Commit bcbd581e authored by Andreas Brandl's avatar Andreas Brandl

Merge branch '270090-add-pk-to-elasticsearch-indexed-namespaces' into 'master'

Primary key for elasticsearch_indexed_namespaces

See merge request gitlab-org/gitlab!48944
parents 44d1e10f 40fe4a08
---
title: Add primary key to elasticsearch_indexed_namespaces
merge_request: 48944
author:
type: changed
# frozen_string_literal: true
class AddPrimaryKeyToElasticSearchIndexedNamespaces < ActiveRecord::Migration[6.0]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
UNIQUE_INDEX_NAME = 'index_elasticsearch_indexed_namespaces_on_namespace_id'
PRIMARY_KEY_NAME = 'elasticsearch_indexed_namespaces_pkey'
disable_ddl_transaction!
def up
with_lock_retries do
execute(<<~SQL)
LOCK TABLE elasticsearch_indexed_namespaces IN ACCESS EXCLUSIVE MODE;
DELETE FROM elasticsearch_indexed_namespaces
WHERE namespace_id IS NULL;
ALTER TABLE elasticsearch_indexed_namespaces
ADD CONSTRAINT #{PRIMARY_KEY_NAME} PRIMARY KEY USING INDEX #{UNIQUE_INDEX_NAME};
SQL
end
end
def down
add_concurrent_index :elasticsearch_indexed_namespaces, :namespace_id, unique: true, name: UNIQUE_INDEX_NAME
with_lock_retries do
execute(<<~SQL)
ALTER TABLE elasticsearch_indexed_namespaces
DROP CONSTRAINT #{PRIMARY_KEY_NAME},
ALTER COLUMN namespace_id DROP NOT NULL
SQL
end
end
end
bd10ddc5e78ff2d878f3ce6a45a3e808b89e0885dcc710b87f44ede15ace372b
\ No newline at end of file
......@@ -11950,7 +11950,7 @@ ALTER SEQUENCE elastic_reindexing_tasks_id_seq OWNED BY elastic_reindexing_tasks
CREATE TABLE elasticsearch_indexed_namespaces (
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
namespace_id integer
namespace_id integer NOT NULL
);
CREATE TABLE elasticsearch_indexed_projects (
......@@ -19462,6 +19462,9 @@ ALTER TABLE ONLY draft_notes
ALTER TABLE ONLY elastic_reindexing_tasks
ADD CONSTRAINT elastic_reindexing_tasks_pkey PRIMARY KEY (id);
ALTER TABLE ONLY elasticsearch_indexed_namespaces
ADD CONSTRAINT elasticsearch_indexed_namespaces_pkey PRIMARY KEY (namespace_id);
ALTER TABLE ONLY elasticsearch_indexed_projects
ADD CONSTRAINT elasticsearch_indexed_projects_pkey PRIMARY KEY (project_id);
......@@ -21286,8 +21289,6 @@ CREATE INDEX index_elastic_reindexing_tasks_on_state ON elastic_reindexing_tasks
CREATE INDEX index_elasticsearch_indexed_namespaces_on_created_at ON elasticsearch_indexed_namespaces USING btree (created_at);
CREATE UNIQUE INDEX index_elasticsearch_indexed_namespaces_on_namespace_id ON elasticsearch_indexed_namespaces USING btree (namespace_id);
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);
......
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