0
0
Fork 0

Add missing NOT NULL on more columns from "large but valid" tables (#33330)

This commit is contained in:
Matt Jankowski 2024-12-17 08:38:18 -05:00 committed by GitHub
parent f19fd0b889
commit 978142ac9e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 173 additions and 17 deletions

View file

@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddNotNullToAccountNoteAccountColumn < ActiveRecord::Migration[7.2]
def change
add_check_constraint :account_notes, 'account_id IS NOT NULL', name: 'account_notes_account_id_null', validate: false
end
end

View file

@ -0,0 +1,19 @@
# frozen_string_literal: true
class ValidateNotNullToAccountNoteAccountColumn < ActiveRecord::Migration[7.2]
def up
connection.execute(<<~SQL.squish)
DELETE FROM account_notes
WHERE account_id IS NULL
SQL
validate_check_constraint :account_notes, name: 'account_notes_account_id_null'
change_column_null :account_notes, :account_id, false
remove_check_constraint :account_notes, name: 'account_notes_account_id_null'
end
def down
add_check_constraint :account_notes, 'account_id IS NOT NULL', name: 'account_notes_account_id_null', validate: false
change_column_null :account_notes, :account_id, true
end
end

View file

@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddNotNullToAccountNoteTargetAccountColumn < ActiveRecord::Migration[7.2]
def change
add_check_constraint :account_notes, 'target_account_id IS NOT NULL', name: 'account_notes_target_account_id_null', validate: false
end
end

View file

@ -0,0 +1,19 @@
# frozen_string_literal: true
class ValidateNotNullToAccountNoteTargetAccountColumn < ActiveRecord::Migration[7.2]
def up
connection.execute(<<~SQL.squish)
DELETE FROM account_notes
WHERE target_account_id IS NULL
SQL
validate_check_constraint :account_notes, name: 'account_notes_target_account_id_null'
change_column_null :account_notes, :target_account_id, false
remove_check_constraint :account_notes, name: 'account_notes_target_account_id_null'
end
def down
add_check_constraint :account_notes, 'target_account_id IS NOT NULL', name: 'account_notes_target_account_id_null', validate: false
change_column_null :account_notes, :target_account_id, true
end
end

View file

@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddNotNullToMarkerUserColumn < ActiveRecord::Migration[7.2]
def change
add_check_constraint :markers, 'user_id IS NOT NULL', name: 'markers_user_id_null', validate: false
end
end

View file

@ -0,0 +1,19 @@
# frozen_string_literal: true
class ValidateNotNullToMarkerUserColumn < ActiveRecord::Migration[7.2]
def up
connection.execute(<<~SQL.squish)
DELETE FROM markers
WHERE user_id IS NULL
SQL
validate_check_constraint :markers, name: 'markers_user_id_null'
change_column_null :markers, :user_id, false
remove_check_constraint :markers, name: 'markers_user_id_null'
end
def down
add_check_constraint :markers, 'user_id IS NOT NULL', name: 'markers_user_id_null', validate: false
change_column_null :markers, :user_id, true
end
end

View file

@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddNotNullToPollVoteAccountColumn < ActiveRecord::Migration[7.2]
def change
add_check_constraint :poll_votes, 'account_id IS NOT NULL', name: 'poll_votes_account_id_null', validate: false
end
end

View file

@ -0,0 +1,19 @@
# frozen_string_literal: true
class ValidateNotNullToPollVoteAccountColumn < ActiveRecord::Migration[7.2]
def up
connection.execute(<<~SQL.squish)
DELETE FROM poll_votes
WHERE account_id IS NULL
SQL
validate_check_constraint :poll_votes, name: 'poll_votes_account_id_null'
change_column_null :poll_votes, :account_id, false
remove_check_constraint :poll_votes, name: 'poll_votes_account_id_null'
end
def down
add_check_constraint :poll_votes, 'account_id IS NOT NULL', name: 'poll_votes_account_id_null', validate: false
change_column_null :poll_votes, :account_id, true
end
end

View file

@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddNotNullToPollVotePollColumn < ActiveRecord::Migration[7.2]
def change
add_check_constraint :poll_votes, 'poll_id IS NOT NULL', name: 'poll_votes_poll_id_null', validate: false
end
end

View file

@ -0,0 +1,19 @@
# frozen_string_literal: true
class ValidateNotNullToPollVotePollColumn < ActiveRecord::Migration[7.2]
def up
connection.execute(<<~SQL.squish)
DELETE FROM poll_votes
WHERE poll_id IS NULL
SQL
validate_check_constraint :poll_votes, name: 'poll_votes_poll_id_null'
change_column_null :poll_votes, :poll_id, false
remove_check_constraint :poll_votes, name: 'poll_votes_poll_id_null'
end
def down
add_check_constraint :poll_votes, 'poll_id IS NOT NULL', name: 'poll_votes_poll_id_null', validate: false
change_column_null :poll_votes, :poll_id, true
end
end

View file

@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddNotNullToTombstoneAccountColumn < ActiveRecord::Migration[7.2]
def change
add_check_constraint :tombstones, 'account_id IS NOT NULL', name: 'tombstones_account_id_null', validate: false
end
end

View file

@ -0,0 +1,19 @@
# frozen_string_literal: true
class ValidateNotNullToTombstoneAccountColumn < ActiveRecord::Migration[7.2]
def up
connection.execute(<<~SQL.squish)
DELETE FROM tombstones
WHERE account_id IS NULL
SQL
validate_check_constraint :tombstones, name: 'tombstones_account_id_null'
change_column_null :tombstones, :account_id, false
remove_check_constraint :tombstones, name: 'tombstones_account_id_null'
end
def down
add_check_constraint :tombstones, 'account_id IS NOT NULL', name: 'tombstones_account_id_null', validate: false
change_column_null :tombstones, :account_id, true
end
end