0
0
Fork 0

Add missing primary keys to accounts_tags and statuses_tags (#25210)

This commit is contained in:
Claire 2023-06-01 09:49:06 +02:00 committed by GitHub
parent f84037ae2b
commit fe84f7e323
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 5 deletions

View file

@ -0,0 +1,24 @@
# frozen_string_literal: true
class AddPrimaryKeyToAccountsTagsJoinTable < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def up
ActiveRecord::Base.transaction do
safety_assured do
execute 'ALTER TABLE accounts_tags ADD PRIMARY KEY USING INDEX index_accounts_tags_on_tag_id_and_account_id'
# Rename for consistency as the primary key's name is not represented in db/schema.rb
execute 'ALTER INDEX index_accounts_tags_on_tag_id_and_account_id RENAME TO accounts_tags_pkey'
end
end
end
def down
safety_assured do
# I have found no way to demote the primary key to an index, instead, re-create the index
execute 'CREATE UNIQUE INDEX CONCURRENTLY index_accounts_tags_on_tag_id_and_account_id ON accounts_tags (tag_id, account_id)'
execute 'ALTER TABLE accounts_tags DROP CONSTRAINT accounts_tags_pkey'
end
end
end

View file

@ -0,0 +1,24 @@
# frozen_string_literal: true
class AddPrimaryKeyToStatusesTagsJoinTable < ActiveRecord::Migration[6.1]
disable_ddl_transaction!
def up
ActiveRecord::Base.transaction do
safety_assured do
execute 'ALTER TABLE statuses_tags ADD PRIMARY KEY USING INDEX index_statuses_tags_on_tag_id_and_status_id'
# Rename for consistency as the primary key's name is not represented in db/schema.rb
execute 'ALTER INDEX index_statuses_tags_on_tag_id_and_status_id RENAME TO statuses_tags_pkey'
end
end
end
def down
safety_assured do
# I have found no way to demote the primary key to an index, instead, re-create the index
execute 'CREATE UNIQUE INDEX CONCURRENTLY index_statuses_tags_on_tag_id_and_status_id ON statuses_tags (tag_id, status_id)'
execute 'ALTER TABLE statuses_tags DROP CONSTRAINT statuses_tags_pkey'
end
end
end