Skip to content

Commit

Permalink
Add check before removing old params_yaml column
Browse files Browse the repository at this point in the history
Check for content in InfoRequestEvent#params_yaml 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 2c0ad31 commit 644d347
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions db/migrate/20230127132719_remove_info_request_event_params_yaml.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
class RemoveInfoRequestEventParamsYaml < ActiveRecord::Migration[7.0]
def change
remove_column :info_request_events, :params_yaml, :text
def up
if InfoRequestEvent.where(params: nil).any?
raise <<~TXT
We can't run the RemoveInfoRequestEventParamsYaml database migrations.
We have dectected InfoRequestEvent objects which haven't been migrated
to the JSONB params column.
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 :info_request_events, :params_yaml
end

def down
add_column :info_request_events, :params_yaml, :text
end
end

0 comments on commit 644d347

Please sign in to comment.