Commit 8cfae5ee authored by pbair's avatar pbair

Add primary key to elasticsearch_indexed_projects

Add a new migration that promotes the unique index on
`elasticsearch_indexed_projects.project_id` to be the primary key of the
table.
parent 2f6b9388
---
title: Add primary key to elasticsearch_indexed_projects
merge_request: 48919
author:
type: changed
# frozen_string_literal: true
class AddPrimaryKeyToElasticSearchIndexedProjects < ActiveRecord::Migration[6.0]
DOWNTIME = false
UNIQUE_INDEX_NAME = 'index_elasticsearch_indexed_projects_on_project_id'
PRIMARY_KEY_NAME = 'elasticsearch_indexed_projects_pkey'
def up
execute(<<~SQL)
DELETE FROM elasticsearch_indexed_projects
WHERE project_id IS NULL
SQL
execute(<<~SQL)
ALTER TABLE elasticsearch_indexed_projects
ALTER COLUMN project_id SET NOT NULL,
ADD CONSTRAINT #{PRIMARY_KEY_NAME} PRIMARY KEY USING INDEX #{UNIQUE_INDEX_NAME}
SQL
end
def down
add_index :elasticsearch_indexed_projects, :project_id, unique: true, name: UNIQUE_INDEX_NAME # rubocop:disable Migration/AddIndex
execute(<<~SQL)
ALTER TABLE elasticsearch_indexed_projects
DROP CONSTRAINT #{PRIMARY_KEY_NAME},
ALTER COLUMN project_id DROP NOT NULL
SQL
end
end
d9ad12dce02d6823536f3206e9c90a0da82c08089c3ce252e8ef28a59589e747
\ No newline at end of file
...@@ -11935,7 +11935,7 @@ CREATE TABLE elasticsearch_indexed_namespaces ( ...@@ -11935,7 +11935,7 @@ CREATE TABLE elasticsearch_indexed_namespaces (
CREATE TABLE elasticsearch_indexed_projects ( CREATE TABLE elasticsearch_indexed_projects (
created_at timestamp with time zone NOT NULL, created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL, updated_at timestamp with time zone NOT NULL,
project_id integer project_id integer NOT NULL
); );
CREATE TABLE emails ( CREATE TABLE emails (
...@@ -19253,6 +19253,9 @@ ALTER TABLE ONLY draft_notes ...@@ -19253,6 +19253,9 @@ ALTER TABLE ONLY draft_notes
ALTER TABLE ONLY elastic_reindexing_tasks ALTER TABLE ONLY elastic_reindexing_tasks
ADD CONSTRAINT elastic_reindexing_tasks_pkey PRIMARY KEY (id); ADD CONSTRAINT elastic_reindexing_tasks_pkey PRIMARY KEY (id);
ALTER TABLE ONLY elasticsearch_indexed_projects
ADD CONSTRAINT elasticsearch_indexed_projects_pkey PRIMARY KEY (project_id);
ALTER TABLE ONLY emails ALTER TABLE ONLY emails
ADD CONSTRAINT emails_pkey PRIMARY KEY (id); ADD CONSTRAINT emails_pkey PRIMARY KEY (id);
...@@ -21054,8 +21057,6 @@ CREATE INDEX index_elasticsearch_indexed_namespaces_on_created_at ON elasticsear ...@@ -21054,8 +21057,6 @@ CREATE INDEX index_elasticsearch_indexed_namespaces_on_created_at ON elasticsear
CREATE UNIQUE INDEX index_elasticsearch_indexed_namespaces_on_namespace_id ON elasticsearch_indexed_namespaces USING btree (namespace_id); CREATE UNIQUE INDEX index_elasticsearch_indexed_namespaces_on_namespace_id ON elasticsearch_indexed_namespaces USING btree (namespace_id);
CREATE UNIQUE INDEX index_elasticsearch_indexed_projects_on_project_id ON elasticsearch_indexed_projects USING btree (project_id);
CREATE UNIQUE INDEX index_emails_on_confirmation_token ON emails USING btree (confirmation_token); CREATE UNIQUE INDEX index_emails_on_confirmation_token ON emails USING btree (confirmation_token);
CREATE UNIQUE INDEX index_emails_on_email ON emails USING btree (email); CREATE UNIQUE INDEX index_emails_on_email ON emails USING btree (email);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment