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
1 changed files with 13 additions and 1 deletions

View File

@ -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