diff --git a/.rubocop.yml b/.rubocop.yml index cc78887e9..911117346 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -36,9 +36,6 @@ Rails/HasManyOrHasOneDependent: Rails/InverseOf: Enabled: true -Rails/ReversibleMigration: - Enabled: true - Rails/SkipsModelValidations: Enabled: true diff --git a/.rubocop_basic.yml b/.rubocop_basic.yml index 8f28a7a2e..de014d83f 100644 --- a/.rubocop_basic.yml +++ b/.rubocop_basic.yml @@ -220,6 +220,9 @@ Rails/RelativeDateConstant: Rails/RequestReferer: Enabled: true +Rails/ReversibleMigration: + Enabled: true + Rails/SafeNavigation: Enabled: true ConvertTry: true diff --git a/db/migrate/20150716154501_remove_external_link_from_debates.rb b/db/migrate/20150716154501_remove_external_link_from_debates.rb index 9b59db739..3e16b6b9f 100644 --- a/db/migrate/20150716154501_remove_external_link_from_debates.rb +++ b/db/migrate/20150716154501_remove_external_link_from_debates.rb @@ -1,5 +1,5 @@ class RemoveExternalLinkFromDebates < ActiveRecord::Migration[4.2] def change - remove_column :debates, :external_link + remove_column :debates, :external_link, :string end end diff --git a/db/migrate/20150826182010_refactor_verification_columns.rb b/db/migrate/20150826182010_refactor_verification_columns.rb index 02d7de5e5..db2581d33 100644 --- a/db/migrate/20150826182010_refactor_verification_columns.rb +++ b/db/migrate/20150826182010_refactor_verification_columns.rb @@ -2,17 +2,17 @@ class RefactorVerificationColumns < ActiveRecord::Migration[4.2] def change rename_column :users, :sms_verification_code, :sms_confirmation_code - remove_column :users, :sms_verified_at - remove_column :users, :email_verified_at - remove_column :users, :email_for_verification - remove_column :users, :verified_user_sms_verified_at + remove_column :users, :sms_verified_at, :datetime + remove_column :users, :email_verified_at, :datetime + remove_column :users, :email_for_verification, :string + remove_column :users, :verified_user_sms_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, :confirmed_phone, :string - remove_column :users, :letter_requested + remove_column :users, :letter_requested, :boolean, default: false add_column :users, :letter_requested_at, :datetime rename_column :users, :sms_tries, :sms_confirmation_tries diff --git a/db/migrate/20150827083232_remove_flagged_as_inappropiate_at_from_comments_and_debates.rb b/db/migrate/20150827083232_remove_flagged_as_inappropiate_at_from_comments_and_debates.rb index e68af1d6c..8afe37f4b 100644 --- a/db/migrate/20150827083232_remove_flagged_as_inappropiate_at_from_comments_and_debates.rb +++ b/db/migrate/20150827083232_remove_flagged_as_inappropiate_at_from_comments_and_debates.rb @@ -1,6 +1,6 @@ class RemoveFlaggedAsInappropiateAtFromCommentsAndDebates < ActiveRecord::Migration[4.2] def change - remove_column :debates, :flagged_as_inappropiate_at - remove_column :comments, :flagged_as_inappropiate_at + remove_column :debates, :flagged_as_inappropiate_at, :datetime + remove_column :comments, :flagged_as_inappropiate_at, :datetime end end diff --git a/db/migrate/20160105170113_merge_activities_and_notifications.rb b/db/migrate/20160105170113_merge_activities_and_notifications.rb index d4aa5b522..761d530f9 100644 --- a/db/migrate/20160105170113_merge_activities_and_notifications.rb +++ b/db/migrate/20160105170113_merge_activities_and_notifications.rb @@ -1,9 +1,9 @@ class MergeActivitiesAndNotifications < ActiveRecord::Migration[4.2] def change - change_table :notifications do |t| - t.remove :read - t.remove :activity_id - t.references :notifiable, polymorphic: true - end + remove_column :notifications, :read, :boolean, default: false + remove_index :notifications, column: [:activity_id] + remove_column :notifications, :activity_id, :integer + + add_reference :notifications, :notifiable, polymorphic: true end end diff --git a/db/migrate/20160219172824_removes_external_link_from_debates.rb b/db/migrate/20160219172824_removes_external_link_from_debates.rb index b4b87b03a..246586aa8 100644 --- a/db/migrate/20160219172824_removes_external_link_from_debates.rb +++ b/db/migrate/20160219172824_removes_external_link_from_debates.rb @@ -1,5 +1,5 @@ class RemovesExternalLinkFromDebates < ActiveRecord::Migration[4.2] def change - remove_column :debates, :external_link + remove_column :debates, :external_link, :string end end diff --git a/db/migrate/20160421090733_destroy_captcha_table.rb b/db/migrate/20160421090733_destroy_captcha_table.rb index 4a214f428..f4e80f71b 100644 --- a/db/migrate/20160421090733_destroy_captcha_table.rb +++ b/db/migrate/20160421090733_destroy_captcha_table.rb @@ -1,5 +1,9 @@ class DestroyCaptchaTable < ActiveRecord::Migration[4.2] - def change + def up drop_table :simple_captcha_data end + + def down + fail ActiveRecord::IrreversibleMigration + end end diff --git a/db/migrate/20160520114820_replace_geozones_by_headings_in_budgets.rb b/db/migrate/20160520114820_replace_geozones_by_headings_in_budgets.rb index dbc660450..49bacb3fe 100644 --- a/db/migrate/20160520114820_replace_geozones_by_headings_in_budgets.rb +++ b/db/migrate/20160520114820_replace_geozones_by_headings_in_budgets.rb @@ -1,7 +1,7 @@ class ReplaceGeozonesByHeadingsInBudgets < ActiveRecord::Migration[4.2] def change - remove_column :budget_investments, :geozone_id - remove_column :budget_ballots, :geozone_id + remove_column :budget_investments, :geozone_id, :integer + remove_column :budget_ballots, :geozone_id, :integer add_reference :budget_investments, :heading, index: true add_reference :budget_ballots, :heading, index: true diff --git a/db/migrate/20160523143320_deletes_heading_id_from_ballot.rb b/db/migrate/20160523143320_deletes_heading_id_from_ballot.rb index 83cb9963d..e60d57bdf 100644 --- a/db/migrate/20160523143320_deletes_heading_id_from_ballot.rb +++ b/db/migrate/20160523143320_deletes_heading_id_from_ballot.rb @@ -1,5 +1,5 @@ class DeletesHeadingIdFromBallot < ActiveRecord::Migration[4.2] def change - remove_column :budget_ballots, :heading_id + remove_column :budget_ballots, :heading_id, :integer, index: true end end diff --git a/db/migrate/20161122101702_remove_question_from_poll_questions.rb b/db/migrate/20161122101702_remove_question_from_poll_questions.rb index 00411ac26..c60943f75 100644 --- a/db/migrate/20161122101702_remove_question_from_poll_questions.rb +++ b/db/migrate/20161122101702_remove_question_from_poll_questions.rb @@ -1,5 +1,5 @@ class RemoveQuestionFromPollQuestions < ActiveRecord::Migration[4.2] def change - remove_column :poll_questions, :question + remove_column :poll_questions, :question, :string end end diff --git a/db/migrate/20161206130836_delete_officing_booths.rb b/db/migrate/20161206130836_delete_officing_booths.rb index 86bc9c166..db53834f2 100644 --- a/db/migrate/20161206130836_delete_officing_booths.rb +++ b/db/migrate/20161206130836_delete_officing_booths.rb @@ -1,8 +1,9 @@ class DeleteOfficingBooths < ActiveRecord::Migration[4.2] - def self.up + def up drop_table :poll_officing_booths end - def self.down + def down + fail ActiveRecord::IrreversibleMigration end end diff --git a/db/migrate/20161229110336_remove_physical_votes_from_proposals.rb b/db/migrate/20161229110336_remove_physical_votes_from_proposals.rb index 603f1d095..c18ad7a98 100644 --- a/db/migrate/20161229110336_remove_physical_votes_from_proposals.rb +++ b/db/migrate/20161229110336_remove_physical_votes_from_proposals.rb @@ -1,5 +1,5 @@ class RemovePhysicalVotesFromProposals < ActiveRecord::Migration[4.2] def change - remove_column :proposals, :physical_votes + remove_column :proposals, :physical_votes, :integer, default: 0 end end diff --git a/db/migrate/20170103170147_remove_geozone_id_from_budget_headings.rb b/db/migrate/20170103170147_remove_geozone_id_from_budget_headings.rb index 7965c1e83..3335ec6d3 100644 --- a/db/migrate/20170103170147_remove_geozone_id_from_budget_headings.rb +++ b/db/migrate/20170103170147_remove_geozone_id_from_budget_headings.rb @@ -1,5 +1,5 @@ class RemoveGeozoneIdFromBudgetHeadings < ActiveRecord::Migration[4.2] def change - remove_column :budget_headings, :geozone_id + remove_column :budget_headings, :geozone_id, :integer end end diff --git a/db/migrate/20170120153244_move_geozones_from_poll_questions_to_polls.rb b/db/migrate/20170120153244_move_geozones_from_poll_questions_to_polls.rb index a94cde61c..2c1c55ec6 100644 --- a/db/migrate/20170120153244_move_geozones_from_poll_questions_to_polls.rb +++ b/db/migrate/20170120153244_move_geozones_from_poll_questions_to_polls.rb @@ -1,5 +1,5 @@ class MoveGeozonesFromPollQuestionsToPolls < ActiveRecord::Migration[4.2] - def change + def up drop_table :geozones_poll_questions create_table :geozones_polls do |t| @@ -7,4 +7,9 @@ class MoveGeozonesFromPollQuestionsToPolls < ActiveRecord::Migration[4.2] t.references :poll, index: true, foreign_key: true end end + + def down + drop_table :geozones_polls + fail ActiveRecord::IrreversibleMigration + end end diff --git a/db/migrate/20170130171322_remove_summary_from_poll_question.rb b/db/migrate/20170130171322_remove_summary_from_poll_question.rb index 8c72b356d..68fecebd3 100644 --- a/db/migrate/20170130171322_remove_summary_from_poll_question.rb +++ b/db/migrate/20170130171322_remove_summary_from_poll_question.rb @@ -1,5 +1,5 @@ class RemoveSummaryFromPollQuestion < ActiveRecord::Migration[4.2] def change - remove_column :poll_questions, :summary + remove_column :poll_questions, :summary, :string end end diff --git a/db/migrate/20170708225159_remove_tolk.rb b/db/migrate/20170708225159_remove_tolk.rb index 8f9e08820..9ef495511 100644 --- a/db/migrate/20170708225159_remove_tolk.rb +++ b/db/migrate/20170708225159_remove_tolk.rb @@ -1,5 +1,5 @@ class RemoveTolk < ActiveRecord::Migration[4.2] - def change + def up remove_index :tolk_translations, column: [:phrase_id, :locale_id] remove_index :tolk_locales, column: :name @@ -7,4 +7,8 @@ class RemoveTolk < ActiveRecord::Migration[4.2] drop_table :tolk_phrases drop_table :tolk_locales end + + def down + fail ActiveRecord::IrreversibleMigration + end end diff --git a/db/migrate/20170713110317_remove_local_census_record_user_id.rb b/db/migrate/20170713110317_remove_local_census_record_user_id.rb index 7833a806f..08ebc7ae6 100644 --- a/db/migrate/20170713110317_remove_local_census_record_user_id.rb +++ b/db/migrate/20170713110317_remove_local_census_record_user_id.rb @@ -1,5 +1,6 @@ class RemoveLocalCensusRecordUserId < ActiveRecord::Migration[4.2] 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 diff --git a/db/migrate/20170719174326_remove_poll_recount.rb b/db/migrate/20170719174326_remove_poll_recount.rb index 2378f16c3..edfa606ec 100644 --- a/db/migrate/20170719174326_remove_poll_recount.rb +++ b/db/migrate/20170719174326_remove_poll_recount.rb @@ -1,8 +1,12 @@ class RemovePollRecount < ActiveRecord::Migration[4.2] - def change + def up remove_index :poll_recounts, column: [:booth_assignment_id] remove_index :poll_recounts, column: [:officer_assignment_id] drop_table :poll_recounts end + + def down + fail ActiveRecord::IrreversibleMigration + end end diff --git a/db/migrate/20170918231410_remove_poll_final_recounts.rb b/db/migrate/20170918231410_remove_poll_final_recounts.rb index 31fc72e90..fde5220bd 100644 --- a/db/migrate/20170918231410_remove_poll_final_recounts.rb +++ b/db/migrate/20170918231410_remove_poll_final_recounts.rb @@ -1,5 +1,5 @@ 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: :officer_assignment_id @@ -8,4 +8,8 @@ class RemovePollFinalRecounts < ActiveRecord::Migration[4.2] drop_table :poll_final_recounts end + + def down + fail ActiveRecord::IrreversibleMigration + end end diff --git a/db/migrate/20171002133547_remove_poll_white_null_total_results.rb b/db/migrate/20171002133547_remove_poll_white_null_total_results.rb index 9d3aa7b14..cc6e7e13b 100644 --- a/db/migrate/20171002133547_remove_poll_white_null_total_results.rb +++ b/db/migrate/20171002133547_remove_poll_white_null_total_results.rb @@ -1,5 +1,5 @@ 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: [:officer_assignment_id] @@ -13,4 +13,8 @@ class RemovePollWhiteNullTotalResults < ActiveRecord::Migration[4.2] drop_table :poll_total_results drop_table :poll_white_results end + + def down + fail ActiveRecord::IrreversibleMigration + end end diff --git a/db/migrate/20171002191347_add_default_to_recount_amounts.rb b/db/migrate/20171002191347_add_default_to_recount_amounts.rb index 32f0ef6b7..c33fa5d12 100644 --- a/db/migrate/20171002191347_add_default_to_recount_amounts.rb +++ b/db/migrate/20171002191347_add_default_to_recount_amounts.rb @@ -1,7 +1,7 @@ class AddDefaultToRecountAmounts < ActiveRecord::Migration[4.2] def change - change_column_default :poll_recounts, :white_amount, 0 - change_column_default :poll_recounts, :null_amount, 0 - change_column_default :poll_recounts, :total_amount, 0 + change_column_default :poll_recounts, :white_amount, from: nil, to: 0 + change_column_default :poll_recounts, :null_amount, from: nil, to: 0 + change_column_default :poll_recounts, :total_amount, from: nil, to: 0 end end diff --git a/db/migrate/20171003170029_remove_description_from_poll_questions.rb b/db/migrate/20171003170029_remove_description_from_poll_questions.rb index 36f3483aa..558f509fe 100644 --- a/db/migrate/20171003170029_remove_description_from_poll_questions.rb +++ b/db/migrate/20171003170029_remove_description_from_poll_questions.rb @@ -1,5 +1,5 @@ class RemoveDescriptionFromPollQuestions < ActiveRecord::Migration[4.2] def change - remove_column :poll_questions, :description + remove_column :poll_questions, :description, :text end end diff --git a/db/migrate/20171017221546_remove_poll_question_valid_answers.rb b/db/migrate/20171017221546_remove_poll_question_valid_answers.rb index 5a803fff6..b0256db53 100644 --- a/db/migrate/20171017221546_remove_poll_question_valid_answers.rb +++ b/db/migrate/20171017221546_remove_poll_question_valid_answers.rb @@ -1,5 +1,5 @@ class RemovePollQuestionValidAnswers < ActiveRecord::Migration[4.2] def change - remove_column :poll_questions, :valid_answers + remove_column :poll_questions, :valid_answers, :string end end diff --git a/db/migrate/20171115164152_add_time_zone_to_default_datetimes.rb b/db/migrate/20171115164152_add_time_zone_to_default_datetimes.rb index 0b658ee7a..ca407158a 100644 --- a/db/migrate/20171115164152_add_time_zone_to_default_datetimes.rb +++ b/db/migrate/20171115164152_add_time_zone_to_default_datetimes.rb @@ -1,6 +1,11 @@ class AddTimeZoneToDefaultDatetimes < ActiveRecord::Migration[4.2] def change - change_column_default :users, :password_changed_at, DateTime.new(2015, 1, 1, 1, 1, 1, "+00:00") - change_column_default :locks, :locked_until, DateTime.new(2000, 1, 1, 1, 1, 1, "+00:00") + change_column_default :users, :password_changed_at, + 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 diff --git a/db/migrate/20171219111046_remove_related_contents_flags_count.rb b/db/migrate/20171219111046_remove_related_contents_flags_count.rb index a7eb00fc4..205e0d241 100644 --- a/db/migrate/20171219111046_remove_related_contents_flags_count.rb +++ b/db/migrate/20171219111046_remove_related_contents_flags_count.rb @@ -1,5 +1,5 @@ class RemoveRelatedContentsFlagsCount < ActiveRecord::Migration[4.2] def change - remove_column :related_contents, :flags_count + remove_column :related_contents, :flags_count, :integer end end diff --git a/db/migrate/20180124143013_remove_image_and_style_from_banners.rb b/db/migrate/20180124143013_remove_image_and_style_from_banners.rb index dbf72c489..3f8bf5051 100644 --- a/db/migrate/20180124143013_remove_image_and_style_from_banners.rb +++ b/db/migrate/20180124143013_remove_image_and_style_from_banners.rb @@ -1,6 +1,6 @@ class RemoveImageAndStyleFromBanners < ActiveRecord::Migration[4.2] def change - remove_column :banners, :image - remove_column :banners, :style + remove_column :banners, :image, :string + remove_column :banners, :style, :string end end diff --git a/db/migrate/20180131011426_remove_internal_comments_from_investment.rb b/db/migrate/20180131011426_remove_internal_comments_from_investment.rb index f37c1b1d1..4909cc872 100644 --- a/db/migrate/20180131011426_remove_internal_comments_from_investment.rb +++ b/db/migrate/20180131011426_remove_internal_comments_from_investment.rb @@ -1,5 +1,5 @@ class RemoveInternalCommentsFromInvestment < ActiveRecord::Migration[4.2] def change - remove_column :budget_investments, :internal_comments + remove_column :budget_investments, :internal_comments, :text end end diff --git a/db/migrate/20180711224810_enable_recommendations_by_default.rb b/db/migrate/20180711224810_enable_recommendations_by_default.rb index 9acafcf98..2ab93c153 100644 --- a/db/migrate/20180711224810_enable_recommendations_by_default.rb +++ b/db/migrate/20180711224810_enable_recommendations_by_default.rb @@ -1,6 +1,6 @@ class EnableRecommendationsByDefault < ActiveRecord::Migration[4.2] def change - change_column_default :users, :recommended_debates, true - change_column_default :users, :recommended_proposals, true + change_column_default :users, :recommended_debates, from: false, to: true + change_column_default :users, :recommended_proposals, from: false, to: true end end diff --git a/db/migrate/20190124084612_drop_annotations_table.rb b/db/migrate/20190124084612_drop_annotations_table.rb index 3e836df80..d7974f5f3 100644 --- a/db/migrate/20190124084612_drop_annotations_table.rb +++ b/db/migrate/20190124084612_drop_annotations_table.rb @@ -1,5 +1,9 @@ class DropAnnotationsTable < ActiveRecord::Migration[4.2] - def change + def up drop_table :annotations end + + def down + fail ActiveRecord::IrreversibleMigration + end end diff --git a/db/migrate/20190124085815_drop_legacy_legislations_table.rb b/db/migrate/20190124085815_drop_legacy_legislations_table.rb index a246a34ba..792dd73fa 100644 --- a/db/migrate/20190124085815_drop_legacy_legislations_table.rb +++ b/db/migrate/20190124085815_drop_legacy_legislations_table.rb @@ -1,5 +1,9 @@ class DropLegacyLegislationsTable < ActiveRecord::Migration[4.2] - def change + def up drop_table :legacy_legislations end + + def down + fail ActiveRecord::IrreversibleMigration + end end diff --git a/db/migrate/20190311215516_destroy_spending_proposals.rb b/db/migrate/20190311215516_destroy_spending_proposals.rb index 96079e25f..9f36dd476 100644 --- a/db/migrate/20190311215516_destroy_spending_proposals.rb +++ b/db/migrate/20190311215516_destroy_spending_proposals.rb @@ -1,5 +1,9 @@ class DestroySpendingProposals < ActiveRecord::Migration[4.2] - def change + def up drop_table :spending_proposals end + + def down + fail ActiveRecord::IrreversibleMigration + end end diff --git a/db/migrate/20190311220711_destroy_spending_proposal_valuations.rb b/db/migrate/20190311220711_destroy_spending_proposal_valuations.rb index bf52deaaa..7c2a8f79e 100644 --- a/db/migrate/20190311220711_destroy_spending_proposal_valuations.rb +++ b/db/migrate/20190311220711_destroy_spending_proposal_valuations.rb @@ -1,5 +1,9 @@ class DestroySpendingProposalValuations < ActiveRecord::Migration[4.2] - def change + def up drop_table :valuation_assignments end + + def down + fail ActiveRecord::IrreversibleMigration + end end diff --git a/db/migrate/20190326211832_destroy_spending_proposal_associations.rb b/db/migrate/20190326211832_destroy_spending_proposal_associations.rb index 57249b9c8..414bee86a 100644 --- a/db/migrate/20190326211832_destroy_spending_proposal_associations.rb +++ b/db/migrate/20190326211832_destroy_spending_proposal_associations.rb @@ -1,6 +1,7 @@ class DestroySpendingProposalAssociations < ActiveRecord::Migration[4.2] def change - remove_column :tags, :spending_proposals_count - remove_column :valuators, :spending_proposals_count + remove_index :tags, :spending_proposals_count + remove_column :tags, :spending_proposals_count, :integer, default: 0 + remove_column :valuators, :spending_proposals_count, :integer, default: 0 end end diff --git a/db/migrate/20191006114603_remove_html_fields_form_legislation_draft_version.rb b/db/migrate/20191006114603_remove_html_fields_form_legislation_draft_version.rb index 4beaf22b9..da2f2e1a2 100644 --- a/db/migrate/20191006114603_remove_html_fields_form_legislation_draft_version.rb +++ b/db/migrate/20191006114603_remove_html_fields_form_legislation_draft_version.rb @@ -1,8 +1,8 @@ class RemoveHtmlFieldsFormLegislationDraftVersion < ActiveRecord::Migration[5.0] def change - remove_column :legislation_draft_versions, :body_html - remove_column :legislation_draft_version_translations, :body_html - remove_column :legislation_draft_versions, :toc_html - remove_column :legislation_draft_version_translations, :toc_html + remove_column :legislation_draft_versions, :body_html, :text + remove_column :legislation_draft_version_translations, :body_html, :text + remove_column :legislation_draft_versions, :toc_html, :text + remove_column :legislation_draft_version_translations, :toc_html, :text end end