diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2017-08-14 18:05:32 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2017-08-14 18:05:32 +0300 |
commit | c8997ae5d24653126d8bba8131b070d7fb0eb53d (patch) | |
tree | 3eea9b67d92aa9d14072982d95b87bf82d603b84 /db | |
parent | 12cdc4616df600edef92f417aecce217f2e5326d (diff) |
Remove invalid broadcast messages before migrating
This prevents the migration from failing to set "NOT NULL" constraints
when some rows contain NULL values that are no longer allowed.
Diffstat (limited to 'db')
-rw-r--r-- | db/migrate/20170809134534_add_broadcast_message_not_null_constraints.rb | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/db/migrate/20170809134534_add_broadcast_message_not_null_constraints.rb b/db/migrate/20170809134534_add_broadcast_message_not_null_constraints.rb index 13e8ef52f22..5551fb51a6e 100644 --- a/db/migrate/20170809134534_add_broadcast_message_not_null_constraints.rb +++ b/db/migrate/20170809134534_add_broadcast_message_not_null_constraints.rb @@ -9,9 +9,21 @@ class AddBroadcastMessageNotNullConstraints < ActiveRecord::Migration COLUMNS = %i[starts_at ends_at created_at updated_at message_html] - def change + class BroadcastMessage < ActiveRecord::Base + self.table_name = 'broadcast_messages' + end + + def up COLUMNS.each do |column| + BroadcastMessage.where(column => nil).delete_all + change_column_null :broadcast_messages, column, false end end + + def down + COLUMNS.each do |column| + change_column_null :broadcast_messages, column, true + end + end end |