-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check before removing old notes column
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
Showing
1 changed file
with
18 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |