Add NOT NULL
requirement to columns on account_conversations
(#33308)
This commit is contained in:
parent
a596f3479b
commit
cf4595967b
6 changed files with 59 additions and 7 deletions
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddNotNullToAccountConversationAccountColumn < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
add_check_constraint :account_conversations, 'account_id IS NOT NULL', name: 'account_conversations_account_id_null', validate: false
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ValidateNotNullToAccountConversationAccountColumn < ActiveRecord::Migration[7.2]
|
||||
def up
|
||||
connection.execute(<<~SQL.squish)
|
||||
DELETE FROM account_conversations
|
||||
WHERE account_id IS NULL
|
||||
SQL
|
||||
|
||||
validate_check_constraint :account_conversations, name: 'account_conversations_account_id_null'
|
||||
change_column_null :account_conversations, :account_id, false
|
||||
remove_check_constraint :account_conversations, name: 'account_conversations_account_id_null'
|
||||
end
|
||||
|
||||
def down
|
||||
add_check_constraint :account_conversations, 'account_id IS NOT NULL', name: 'account_conversations_account_id_null', validate: false
|
||||
change_column_null :account_conversations, :account_id, true
|
||||
end
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddNotNullToAccountConversationConversationColumn < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
add_check_constraint :account_conversations, 'conversation_id IS NOT NULL', name: 'account_conversations_conversation_id_null', validate: false
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ValidateNotNullToAccountConversationConversationColumn < ActiveRecord::Migration[7.2]
|
||||
def up
|
||||
connection.execute(<<~SQL.squish)
|
||||
DELETE FROM account_conversations
|
||||
WHERE conversation_id IS NULL
|
||||
SQL
|
||||
|
||||
validate_check_constraint :account_conversations, name: 'account_conversations_conversation_id_null'
|
||||
change_column_null :account_conversations, :conversation_id, false
|
||||
remove_check_constraint :account_conversations, name: 'account_conversations_conversation_id_null'
|
||||
end
|
||||
|
||||
def down
|
||||
add_check_constraint :account_conversations, 'conversation_id IS NOT NULL', name: 'account_conversations_conversation_id_null', validate: false
|
||||
change_column_null :account_conversations, :conversation_id, true
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue