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.
This commit is contained in:
Yorick Peterse 2017-08-14 17:05:32 +02:00
parent 12cdc4616d
commit c8997ae5d2
No known key found for this signature in database
GPG key ID: EDD30D2BEB691AC9

View file

@ -9,9 +9,21 @@ class AddBroadcastMessageNotNullConstraints < ActiveRecord::Migration
COLUMNS = %i[starts_at ends_at created_at updated_at message_html] 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| COLUMNS.each do |column|
BroadcastMessage.where(column => nil).delete_all
change_column_null :broadcast_messages, column, false change_column_null :broadcast_messages, column, false
end end
end end
def down
COLUMNS.each do |column|
change_column_null :broadcast_messages, column, true
end
end
end end