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:
parent
12cdc4616d
commit
c8997ae5d2
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue