Cells: Add composite index index_ssh_signatures_on_project_id_and_commit_sha for ssh_signatures table
What does this MR do and why?
As part of Cells, we need to ensure that the unique index by commit_sha is still unique for ssh_signatures table.
In this MR, we drop index_ssh_signatures_on_commit_sha and redundant index_ssh_signatures_on_project_id indexes in favor of index_ssh_signatures_on_project_id_and_commit_sha since the same commit SHA cannot exist across different projects in any meaningful way.
Database
Before migration
Table "public.ssh_signatures"
Column | Type | Collation | Nullable | Default
------------------------+--------------------------+-----------+----------+--------------------------------------------
id | bigint | | not null | nextval('ssh_signatures_id_seq'::regclass)
created_at | timestamp with time zone | | not null |
updated_at | timestamp with time zone | | not null |
project_id | bigint | | not null |
key_id | bigint | | |
verification_status | smallint | | not null | 0
commit_sha | bytea | | not null |
user_id | bigint | | |
key_fingerprint_sha256 | bytea | | |
committer_email | text | | |
Indexes:
"ssh_signatures_pkey" PRIMARY KEY, btree (id)
"index_ssh_signatures_on_commit_sha" UNIQUE, btree (commit_sha)
"index_ssh_signatures_on_key_id" btree (key_id)
"index_ssh_signatures_on_project_id" btree (project_id)
"index_ssh_signatures_on_user_id" btree (user_id)
Check constraints:
"check_73776e38f9" CHECK (char_length(committer_email) <= 255)
Foreign-key constraints:
"fk_0c83baaa5f" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
"fk_7d2f93996c" FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE
"fk_aa1efbe865" FOREIGN KEY (key_id) REFERENCES keys(id) ON DELETE SET NULL
After migration
Table "public.ssh_signatures"
Column | Type | Collation | Nullable | Default
------------------------+--------------------------+-----------+----------+--------------------------------------------
id | bigint | | not null | nextval('ssh_signatures_id_seq'::regclass)
created_at | timestamp with time zone | | not null |
updated_at | timestamp with time zone | | not null |
project_id | bigint | | not null |
key_id | bigint | | |
verification_status | smallint | | not null | 0
commit_sha | bytea | | not null |
user_id | bigint | | |
key_fingerprint_sha256 | bytea | | |
committer_email | text | | |
Indexes:
"ssh_signatures_pkey" PRIMARY KEY, btree (id)
"index_ssh_signatures_on_key_id" btree (key_id)
"index_ssh_signatures_on_project_id_and_commit_sha" UNIQUE, btree (project_id, commit_sha)
"index_ssh_signatures_on_user_id" btree (user_id)
Check constraints:
"check_73776e38f9" CHECK (char_length(committer_email) <= 255)
Foreign-key constraints:
"fk_0c83baaa5f" FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL
"fk_7d2f93996c" FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE
"fk_aa1efbe865" FOREIGN KEY (key_id) REFERENCES keys(id) ON DELETE SET NULL
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #562085 (closed)
Edited by Javiera Tapia