Database schema missing many primary keys - breaks replication
On both modern MySQL and PostgreSQL systems, replication requires tables have primary keys in order to function properly. There are numerous tables in the Gitlab schema that do not have them and issues arise if you try to enable replication on the database. In PostgreSQL, for example, you get this when attempting to delete from a table without a PK:
ERROR: cannot delete from table "table_name" because it does not have a replica identity and publishes deletes
There is usually a comparable unique key serving the same purpose as a PK but these need to be converted before the DBMS will use them. The following is my running list as of 11.3.0-ce0 although I may have missed a few:
- issue_assignees
- merge_request_diff_files
- merge_request_diff_commits
- project_authorizations
- push_event_payloads
- repository_languages
- schema_migrations
- user_interacted_projects
Please convert the unique keys on these tables to proper primary keys. Here's some SQL that will do it - I have no idea how to translate this into whatever Ruby library you're using:
ALTER TABLE project_authorizations ADD PRIMARY KEY USING INDEX index_project_authorizations_on_user_id_project_id_access_level;
ALTER TABLE issue_assignees ADD PRIMARY KEY USING INDEX index_issue_assignees_on_issue_id_and_user_id;
ALTER TABLE user_interacted_projects ADD PRIMARY KEY USING INDEX index_user_interacted_projects_on_project_id_and_user_id;
ALTER TABLE repository_languages ADD PRIMARY KEY USING INDEX index_repository_languages_on_project_and_languages_id;
ALTER TABLE push_event_payloads ADD PRIMARY KEY USING INDEX index_push_event_payloads_on_event_id;
ALTER TABLE schema_migrations ADD PRIMARY KEY USING INDEX unique_schema_migrations;
ALTER TABLE merge_request_diff_files ADD PRIMARY KEY USING INDEX index_merge_request_diff_files_on_mr_diff_id_and_order;
ALTER TABLE merge_request_diff_commits ADD PRIMARY KEY USING INDEX index_merge_request_diff_commits_on_mr_diff_id_and_order;
Thanks