mirror of https://github.com/mastodon/mastodon
Add `NOT NULL` requirement to columns on `polls` (#33374)
parent
d2fbf42b0e
commit
b648c64e2e
@ -0,0 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddNotNullToPollAccountColumn < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
add_check_constraint :polls, 'account_id IS NOT NULL', name: 'polls_account_id_null', validate: false
|
||||
end
|
||||
end
|
@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ValidateNotNullToPollAccountColumn < ActiveRecord::Migration[7.2]
|
||||
def up
|
||||
connection.execute(<<~SQL.squish)
|
||||
DELETE FROM polls
|
||||
WHERE account_id IS NULL
|
||||
SQL
|
||||
|
||||
validate_check_constraint :polls, name: 'polls_account_id_null'
|
||||
change_column_null :polls, :account_id, false
|
||||
remove_check_constraint :polls, name: 'polls_account_id_null'
|
||||
end
|
||||
|
||||
def down
|
||||
add_check_constraint :polls, 'account_id IS NOT NULL', name: 'polls_account_id_null', validate: false
|
||||
change_column_null :polls, :account_id, true
|
||||
end
|
||||
end
|
@ -0,0 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddNotNullToPollStatusColumn < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
add_check_constraint :polls, 'status_id IS NOT NULL', name: 'polls_status_id_null', validate: false
|
||||
end
|
||||
end
|
@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ValidateNotNullToPollStatusColumn < ActiveRecord::Migration[7.2]
|
||||
def up
|
||||
connection.execute(<<~SQL.squish)
|
||||
DELETE FROM polls
|
||||
WHERE status_id IS NULL
|
||||
SQL
|
||||
|
||||
validate_check_constraint :polls, name: 'polls_status_id_null'
|
||||
change_column_null :polls, :status_id, false
|
||||
remove_check_constraint :polls, name: 'polls_status_id_null'
|
||||
end
|
||||
|
||||
def down
|
||||
add_check_constraint :polls, 'status_id IS NOT NULL', name: 'polls_status_id_null', validate: false
|
||||
change_column_null :polls, :status_id, true
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue