Skip to content

Commit

Permalink
Add check before removing old notes column
Browse files Browse the repository at this point in the history
Check for content in PublicBody::Translation#notes column.

If a re-user skips 0.42.0.0 upgrade notes then they could lose data. Add
a check to ensure we prevent this.
  • Loading branch information
gbp committed Mar 17, 2023
1 parent 644d347 commit fe27d2f
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions db/migrate/20220902112339_remove_public_body_notes.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
class RemovePublicBodyNotes < ActiveRecord::Migration[6.1]
def change
reversible do |dir|
dir.up do
remove_column :public_body_translations, :notes
end

dir.down do
PublicBody.add_translation_fields! notes: :text
end
def up
if PublicBody::Translation.where.not(notes: nil).any?
raise <<~TXT
We can't run the RemovePublicBodyNotes database migrations.
We have dectected PublicBody::Translation objects which haven't been
migrated to the new Note model.
Please deploy Alaveteli 0.42.0.0 and run the upgrade tasks:
https://github.com/mysociety/alaveteli/blob/0.42.0.0/doc/CHANGES.md#upgrade-notes
TXT
end

remove_column :public_body_translations, :notes
end

def down
PublicBody.add_translation_fields! notes: :text
end
end

0 comments on commit fe27d2f

Please sign in to comment.