Make migrations reversible
While I don't use this feature, there are developers who do. It's useful when running migrations and changing branches. I'm raising an `ActiveRecord::IrreversibleMigration` exception in every `drop_table` migration because these migrations were all done before version 1.0.0, and so making all of them reversible would be too much work for little benefit.
This commit is contained in:
@@ -36,9 +36,6 @@ Rails/HasManyOrHasOneDependent:
|
|||||||
Rails/InverseOf:
|
Rails/InverseOf:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
Rails/ReversibleMigration:
|
|
||||||
Enabled: true
|
|
||||||
|
|
||||||
Rails/SkipsModelValidations:
|
Rails/SkipsModelValidations:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
|
|||||||
@@ -220,6 +220,9 @@ Rails/RelativeDateConstant:
|
|||||||
Rails/RequestReferer:
|
Rails/RequestReferer:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
|
Rails/ReversibleMigration:
|
||||||
|
Enabled: true
|
||||||
|
|
||||||
Rails/SafeNavigation:
|
Rails/SafeNavigation:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
ConvertTry: true
|
ConvertTry: true
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class RemoveExternalLinkFromDebates < ActiveRecord::Migration[4.2]
|
class RemoveExternalLinkFromDebates < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def change
|
||||||
remove_column :debates, :external_link
|
remove_column :debates, :external_link, :string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,17 +2,17 @@ class RefactorVerificationColumns < ActiveRecord::Migration[4.2]
|
|||||||
def change
|
def change
|
||||||
rename_column :users, :sms_verification_code, :sms_confirmation_code
|
rename_column :users, :sms_verification_code, :sms_confirmation_code
|
||||||
|
|
||||||
remove_column :users, :sms_verified_at
|
remove_column :users, :sms_verified_at, :datetime
|
||||||
remove_column :users, :email_verified_at
|
remove_column :users, :email_verified_at, :datetime
|
||||||
remove_column :users, :email_for_verification
|
remove_column :users, :email_for_verification, :string
|
||||||
remove_column :users, :verified_user_sms_verified_at
|
remove_column :users, :verified_user_sms_verified_at, :datetime
|
||||||
add_column :users, :verified_at, :datetime
|
add_column :users, :verified_at, :datetime
|
||||||
|
|
||||||
remove_column :users, :phone
|
remove_column :users, :phone, :string
|
||||||
add_column :users, :unconfirmed_phone, :string
|
add_column :users, :unconfirmed_phone, :string
|
||||||
add_column :users, :confirmed_phone, :string
|
add_column :users, :confirmed_phone, :string
|
||||||
|
|
||||||
remove_column :users, :letter_requested
|
remove_column :users, :letter_requested, :boolean, default: false
|
||||||
add_column :users, :letter_requested_at, :datetime
|
add_column :users, :letter_requested_at, :datetime
|
||||||
|
|
||||||
rename_column :users, :sms_tries, :sms_confirmation_tries
|
rename_column :users, :sms_tries, :sms_confirmation_tries
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class RemoveFlaggedAsInappropiateAtFromCommentsAndDebates < ActiveRecord::Migration[4.2]
|
class RemoveFlaggedAsInappropiateAtFromCommentsAndDebates < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def change
|
||||||
remove_column :debates, :flagged_as_inappropiate_at
|
remove_column :debates, :flagged_as_inappropiate_at, :datetime
|
||||||
remove_column :comments, :flagged_as_inappropiate_at
|
remove_column :comments, :flagged_as_inappropiate_at, :datetime
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
class MergeActivitiesAndNotifications < ActiveRecord::Migration[4.2]
|
class MergeActivitiesAndNotifications < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def change
|
||||||
change_table :notifications do |t|
|
remove_column :notifications, :read, :boolean, default: false
|
||||||
t.remove :read
|
remove_index :notifications, column: [:activity_id]
|
||||||
t.remove :activity_id
|
remove_column :notifications, :activity_id, :integer
|
||||||
t.references :notifiable, polymorphic: true
|
|
||||||
end
|
add_reference :notifications, :notifiable, polymorphic: true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class RemovesExternalLinkFromDebates < ActiveRecord::Migration[4.2]
|
class RemovesExternalLinkFromDebates < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def change
|
||||||
remove_column :debates, :external_link
|
remove_column :debates, :external_link, :string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
class DestroyCaptchaTable < ActiveRecord::Migration[4.2]
|
class DestroyCaptchaTable < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def up
|
||||||
drop_table :simple_captcha_data
|
drop_table :simple_captcha_data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
fail ActiveRecord::IrreversibleMigration
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
class ReplaceGeozonesByHeadingsInBudgets < ActiveRecord::Migration[4.2]
|
class ReplaceGeozonesByHeadingsInBudgets < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def change
|
||||||
remove_column :budget_investments, :geozone_id
|
remove_column :budget_investments, :geozone_id, :integer
|
||||||
remove_column :budget_ballots, :geozone_id
|
remove_column :budget_ballots, :geozone_id, :integer
|
||||||
|
|
||||||
add_reference :budget_investments, :heading, index: true
|
add_reference :budget_investments, :heading, index: true
|
||||||
add_reference :budget_ballots, :heading, index: true
|
add_reference :budget_ballots, :heading, index: true
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class DeletesHeadingIdFromBallot < ActiveRecord::Migration[4.2]
|
class DeletesHeadingIdFromBallot < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def change
|
||||||
remove_column :budget_ballots, :heading_id
|
remove_column :budget_ballots, :heading_id, :integer, index: true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class RemoveQuestionFromPollQuestions < ActiveRecord::Migration[4.2]
|
class RemoveQuestionFromPollQuestions < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def change
|
||||||
remove_column :poll_questions, :question
|
remove_column :poll_questions, :question, :string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
class DeleteOfficingBooths < ActiveRecord::Migration[4.2]
|
class DeleteOfficingBooths < ActiveRecord::Migration[4.2]
|
||||||
def self.up
|
def up
|
||||||
drop_table :poll_officing_booths
|
drop_table :poll_officing_booths
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.down
|
def down
|
||||||
|
fail ActiveRecord::IrreversibleMigration
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class RemovePhysicalVotesFromProposals < ActiveRecord::Migration[4.2]
|
class RemovePhysicalVotesFromProposals < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def change
|
||||||
remove_column :proposals, :physical_votes
|
remove_column :proposals, :physical_votes, :integer, default: 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class RemoveGeozoneIdFromBudgetHeadings < ActiveRecord::Migration[4.2]
|
class RemoveGeozoneIdFromBudgetHeadings < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def change
|
||||||
remove_column :budget_headings, :geozone_id
|
remove_column :budget_headings, :geozone_id, :integer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class MoveGeozonesFromPollQuestionsToPolls < ActiveRecord::Migration[4.2]
|
class MoveGeozonesFromPollQuestionsToPolls < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def up
|
||||||
drop_table :geozones_poll_questions
|
drop_table :geozones_poll_questions
|
||||||
|
|
||||||
create_table :geozones_polls do |t|
|
create_table :geozones_polls do |t|
|
||||||
@@ -7,4 +7,9 @@ class MoveGeozonesFromPollQuestionsToPolls < ActiveRecord::Migration[4.2]
|
|||||||
t.references :poll, index: true, foreign_key: true
|
t.references :poll, index: true, foreign_key: true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
drop_table :geozones_polls
|
||||||
|
fail ActiveRecord::IrreversibleMigration
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class RemoveSummaryFromPollQuestion < ActiveRecord::Migration[4.2]
|
class RemoveSummaryFromPollQuestion < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def change
|
||||||
remove_column :poll_questions, :summary
|
remove_column :poll_questions, :summary, :string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class RemoveTolk < ActiveRecord::Migration[4.2]
|
class RemoveTolk < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def up
|
||||||
remove_index :tolk_translations, column: [:phrase_id, :locale_id]
|
remove_index :tolk_translations, column: [:phrase_id, :locale_id]
|
||||||
remove_index :tolk_locales, column: :name
|
remove_index :tolk_locales, column: :name
|
||||||
|
|
||||||
@@ -7,4 +7,8 @@ class RemoveTolk < ActiveRecord::Migration[4.2]
|
|||||||
drop_table :tolk_phrases
|
drop_table :tolk_phrases
|
||||||
drop_table :tolk_locales
|
drop_table :tolk_locales
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
fail ActiveRecord::IrreversibleMigration
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
class RemoveLocalCensusRecordUserId < ActiveRecord::Migration[4.2]
|
class RemoveLocalCensusRecordUserId < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def change
|
||||||
remove_column :local_census_records, :user_id
|
remove_foreign_key :local_census_records, :users
|
||||||
|
remove_column :local_census_records, :user_id, :integer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
class RemovePollRecount < ActiveRecord::Migration[4.2]
|
class RemovePollRecount < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def up
|
||||||
remove_index :poll_recounts, column: [:booth_assignment_id]
|
remove_index :poll_recounts, column: [:booth_assignment_id]
|
||||||
remove_index :poll_recounts, column: [:officer_assignment_id]
|
remove_index :poll_recounts, column: [:officer_assignment_id]
|
||||||
|
|
||||||
drop_table :poll_recounts
|
drop_table :poll_recounts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
fail ActiveRecord::IrreversibleMigration
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class RemovePollFinalRecounts < ActiveRecord::Migration[4.2]
|
class RemovePollFinalRecounts < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def up
|
||||||
remove_index :poll_final_recounts, column: :booth_assignment_id
|
remove_index :poll_final_recounts, column: :booth_assignment_id
|
||||||
remove_index :poll_final_recounts, column: :officer_assignment_id
|
remove_index :poll_final_recounts, column: :officer_assignment_id
|
||||||
|
|
||||||
@@ -8,4 +8,8 @@ class RemovePollFinalRecounts < ActiveRecord::Migration[4.2]
|
|||||||
|
|
||||||
drop_table :poll_final_recounts
|
drop_table :poll_final_recounts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
fail ActiveRecord::IrreversibleMigration
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class RemovePollWhiteNullTotalResults < ActiveRecord::Migration[4.2]
|
class RemovePollWhiteNullTotalResults < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def up
|
||||||
remove_index :poll_null_results, column: [:booth_assignment_id]
|
remove_index :poll_null_results, column: [:booth_assignment_id]
|
||||||
remove_index :poll_null_results, column: [:officer_assignment_id]
|
remove_index :poll_null_results, column: [:officer_assignment_id]
|
||||||
|
|
||||||
@@ -13,4 +13,8 @@ class RemovePollWhiteNullTotalResults < ActiveRecord::Migration[4.2]
|
|||||||
drop_table :poll_total_results
|
drop_table :poll_total_results
|
||||||
drop_table :poll_white_results
|
drop_table :poll_white_results
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
fail ActiveRecord::IrreversibleMigration
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
class AddDefaultToRecountAmounts < ActiveRecord::Migration[4.2]
|
class AddDefaultToRecountAmounts < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def change
|
||||||
change_column_default :poll_recounts, :white_amount, 0
|
change_column_default :poll_recounts, :white_amount, from: nil, to: 0
|
||||||
change_column_default :poll_recounts, :null_amount, 0
|
change_column_default :poll_recounts, :null_amount, from: nil, to: 0
|
||||||
change_column_default :poll_recounts, :total_amount, 0
|
change_column_default :poll_recounts, :total_amount, from: nil, to: 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class RemoveDescriptionFromPollQuestions < ActiveRecord::Migration[4.2]
|
class RemoveDescriptionFromPollQuestions < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def change
|
||||||
remove_column :poll_questions, :description
|
remove_column :poll_questions, :description, :text
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class RemovePollQuestionValidAnswers < ActiveRecord::Migration[4.2]
|
class RemovePollQuestionValidAnswers < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def change
|
||||||
remove_column :poll_questions, :valid_answers
|
remove_column :poll_questions, :valid_answers, :string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
class AddTimeZoneToDefaultDatetimes < ActiveRecord::Migration[4.2]
|
class AddTimeZoneToDefaultDatetimes < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def change
|
||||||
change_column_default :users, :password_changed_at, DateTime.new(2015, 1, 1, 1, 1, 1, "+00:00")
|
change_column_default :users, :password_changed_at,
|
||||||
change_column_default :locks, :locked_until, DateTime.new(2000, 1, 1, 1, 1, 1, "+00:00")
|
from: Time.zone.local(2015, 1, 1, 1, 1, 1),
|
||||||
|
to: DateTime.new(2015, 1, 1, 1, 1, 1, "+00:00")
|
||||||
|
|
||||||
|
change_column_default :locks, :locked_until,
|
||||||
|
from: Time.zone.local(2000, 1, 1, 1, 1, 1),
|
||||||
|
to: DateTime.new(2000, 1, 1, 1, 1, 1, "+00:00")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class RemoveRelatedContentsFlagsCount < ActiveRecord::Migration[4.2]
|
class RemoveRelatedContentsFlagsCount < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def change
|
||||||
remove_column :related_contents, :flags_count
|
remove_column :related_contents, :flags_count, :integer
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class RemoveImageAndStyleFromBanners < ActiveRecord::Migration[4.2]
|
class RemoveImageAndStyleFromBanners < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def change
|
||||||
remove_column :banners, :image
|
remove_column :banners, :image, :string
|
||||||
remove_column :banners, :style
|
remove_column :banners, :style, :string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
class RemoveInternalCommentsFromInvestment < ActiveRecord::Migration[4.2]
|
class RemoveInternalCommentsFromInvestment < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def change
|
||||||
remove_column :budget_investments, :internal_comments
|
remove_column :budget_investments, :internal_comments, :text
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class EnableRecommendationsByDefault < ActiveRecord::Migration[4.2]
|
class EnableRecommendationsByDefault < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def change
|
||||||
change_column_default :users, :recommended_debates, true
|
change_column_default :users, :recommended_debates, from: false, to: true
|
||||||
change_column_default :users, :recommended_proposals, true
|
change_column_default :users, :recommended_proposals, from: false, to: true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
class DropAnnotationsTable < ActiveRecord::Migration[4.2]
|
class DropAnnotationsTable < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def up
|
||||||
drop_table :annotations
|
drop_table :annotations
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
fail ActiveRecord::IrreversibleMigration
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
class DropLegacyLegislationsTable < ActiveRecord::Migration[4.2]
|
class DropLegacyLegislationsTable < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def up
|
||||||
drop_table :legacy_legislations
|
drop_table :legacy_legislations
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
fail ActiveRecord::IrreversibleMigration
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
class DestroySpendingProposals < ActiveRecord::Migration[4.2]
|
class DestroySpendingProposals < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def up
|
||||||
drop_table :spending_proposals
|
drop_table :spending_proposals
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
fail ActiveRecord::IrreversibleMigration
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
class DestroySpendingProposalValuations < ActiveRecord::Migration[4.2]
|
class DestroySpendingProposalValuations < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def up
|
||||||
drop_table :valuation_assignments
|
drop_table :valuation_assignments
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
fail ActiveRecord::IrreversibleMigration
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
class DestroySpendingProposalAssociations < ActiveRecord::Migration[4.2]
|
class DestroySpendingProposalAssociations < ActiveRecord::Migration[4.2]
|
||||||
def change
|
def change
|
||||||
remove_column :tags, :spending_proposals_count
|
remove_index :tags, :spending_proposals_count
|
||||||
remove_column :valuators, :spending_proposals_count
|
remove_column :tags, :spending_proposals_count, :integer, default: 0
|
||||||
|
remove_column :valuators, :spending_proposals_count, :integer, default: 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
class RemoveHtmlFieldsFormLegislationDraftVersion < ActiveRecord::Migration[5.0]
|
class RemoveHtmlFieldsFormLegislationDraftVersion < ActiveRecord::Migration[5.0]
|
||||||
def change
|
def change
|
||||||
remove_column :legislation_draft_versions, :body_html
|
remove_column :legislation_draft_versions, :body_html, :text
|
||||||
remove_column :legislation_draft_version_translations, :body_html
|
remove_column :legislation_draft_version_translations, :body_html, :text
|
||||||
remove_column :legislation_draft_versions, :toc_html
|
remove_column :legislation_draft_versions, :toc_html, :text
|
||||||
remove_column :legislation_draft_version_translations, :toc_html
|
remove_column :legislation_draft_version_translations, :toc_html, :text
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user