From 7b05e700a1880b9b8940ff09e3438782cfc39bff Mon Sep 17 00:00:00 2001 From: AndriiMysko Date: Wed, 6 Dec 2023 11:51:32 +0200 Subject: [PATCH 1/3] Add unique vcs_id and vcs_type indexes for repositories, organizations and users --- ...06113245_add_unique_vcs_id_type_indexes.rb | 9 +++++++ db/main/structure.sql | 24 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 db/main/migrate/20231206113245_add_unique_vcs_id_type_indexes.rb diff --git a/db/main/migrate/20231206113245_add_unique_vcs_id_type_indexes.rb b/db/main/migrate/20231206113245_add_unique_vcs_id_type_indexes.rb new file mode 100644 index 00000000..6fd2bd12 --- /dev/null +++ b/db/main/migrate/20231206113245_add_unique_vcs_id_type_indexes.rb @@ -0,0 +1,9 @@ +class AddUniqueVcsIdTypeIndexes < ActiveRecord::Migration[5.2] + disable_ddl_transaction! + + def change + add_index :repositories, [:vcs_id, :vcs_type], algorithm: :concurrently, unique: true + add_index :organizations, [:vcs_id, :vcs_type], algorithm: :concurrently, unique: true + add_index :users, [:vcs_id, :vcs_type], algorithm: :concurrently, unique: true + end +end diff --git a/db/main/structure.sql b/db/main/structure.sql index 1c3b66cc..08795688 100644 --- a/db/main/structure.sql +++ b/db/main/structure.sql @@ -5171,6 +5171,27 @@ CREATE INDEX index_users_on_vcs_type_and_vcs_id ON public.users USING btree (vcs CREATE INDEX managed_repositories_idx ON public.repositories USING btree (managed_by_installation_at); +-- +-- Name: index_repositories_on_vcs_id_and_vcs_type; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_repositories_on_vcs_id_and_vcs_type ON public.repositories USING btree (vcs_id, vcs_type); + + +-- +-- Name: index_organizations_on_vcs_id_and_vcs_type; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_organizations_on_vcs_id_and_vcs_type ON public.organizations USING btree (vcs_id, vcs_type); + + +-- +-- Name: index_users_on_vcs_id_and_vcs_type; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX index_users_on_vcs_id_and_vcs_type ON public.users USING btree (vcs_id, vcs_type); + + -- -- Name: owner_installations_idx; Type: INDEX; Schema: public; Owner: - -- @@ -5969,6 +5990,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20220825140522'), ('20220905144600'), ('20221214171030'), -('20230208161446'); +('20230208161446'), +('20231206113245'); From f68dcc28208b4c91c16c1374554ffd10ac8da9b3 Mon Sep 17 00:00:00 2001 From: AndriiMysko Date: Wed, 6 Dec 2023 11:58:56 +0200 Subject: [PATCH 2/3] Change --- .../20231206113245_add_unique_vcs_id_type_indexes.rb | 1 + db/main/structure.sql | 7 ------- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/db/main/migrate/20231206113245_add_unique_vcs_id_type_indexes.rb b/db/main/migrate/20231206113245_add_unique_vcs_id_type_indexes.rb index 6fd2bd12..9a9a1d6b 100644 --- a/db/main/migrate/20231206113245_add_unique_vcs_id_type_indexes.rb +++ b/db/main/migrate/20231206113245_add_unique_vcs_id_type_indexes.rb @@ -2,6 +2,7 @@ class AddUniqueVcsIdTypeIndexes < ActiveRecord::Migration[5.2] disable_ddl_transaction! def change + remove_index :repositories, column: [:vcs_id, :vcs_type], algorithm: :concurrently add_index :repositories, [:vcs_id, :vcs_type], algorithm: :concurrently, unique: true add_index :organizations, [:vcs_id, :vcs_type], algorithm: :concurrently, unique: true add_index :users, [:vcs_id, :vcs_type], algorithm: :concurrently, unique: true diff --git a/db/main/structure.sql b/db/main/structure.sql index 08795688..4a496ac9 100644 --- a/db/main/structure.sql +++ b/db/main/structure.sql @@ -4730,13 +4730,6 @@ CREATE INDEX index_repositories_on_slug_or_names ON public.repositories USING bt CREATE INDEX index_repositories_on_updated_at ON public.repositories USING btree (updated_at); --- --- Name: index_repositories_on_vcs_id_and_vcs_type; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_repositories_on_vcs_id_and_vcs_type ON public.repositories USING btree (vcs_id, vcs_type); - - -- -- Name: index_repositories_on_vcs_type_and_vcs_id; Type: INDEX; Schema: public; Owner: - -- From f3ecedee523810d0d0efc9743154ba48e9992eeb Mon Sep 17 00:00:00 2001 From: AndriiMysko Date: Wed, 6 Dec 2023 12:49:20 +0200 Subject: [PATCH 3/3] Change --- ...0231206113245_add_unique_vcs_id_type_indexes.rb | 2 ++ db/main/structure.sql | 14 -------------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/db/main/migrate/20231206113245_add_unique_vcs_id_type_indexes.rb b/db/main/migrate/20231206113245_add_unique_vcs_id_type_indexes.rb index 9a9a1d6b..febb02df 100644 --- a/db/main/migrate/20231206113245_add_unique_vcs_id_type_indexes.rb +++ b/db/main/migrate/20231206113245_add_unique_vcs_id_type_indexes.rb @@ -4,7 +4,9 @@ class AddUniqueVcsIdTypeIndexes < ActiveRecord::Migration[5.2] def change remove_index :repositories, column: [:vcs_id, :vcs_type], algorithm: :concurrently add_index :repositories, [:vcs_id, :vcs_type], algorithm: :concurrently, unique: true + remove_index :organizations, column: [:vcs_id, :vcs_type], algorithm: :concurrently add_index :organizations, [:vcs_id, :vcs_type], algorithm: :concurrently, unique: true + remove_index :users, column: [:vcs_id, :vcs_type], algorithm: :concurrently add_index :users, [:vcs_id, :vcs_type], algorithm: :concurrently, unique: true end end diff --git a/db/main/structure.sql b/db/main/structure.sql index 4a496ac9..c097db6a 100644 --- a/db/main/structure.sql +++ b/db/main/structure.sql @@ -4478,13 +4478,6 @@ CREATE UNIQUE INDEX index_organizations_on_org_id ON public.organizations USING CREATE INDEX index_organizations_on_updated_at ON public.organizations USING btree (updated_at); --- --- Name: index_organizations_on_vcs_id_and_vcs_type; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_organizations_on_vcs_id_and_vcs_type ON public.organizations USING btree (vcs_id, vcs_type); - - -- -- Name: index_owner_groups_on_owner_type_and_owner_id; Type: INDEX; Schema: public; Owner: - -- @@ -5143,13 +5136,6 @@ CREATE UNIQUE INDEX index_users_on_org_id ON public.users USING btree (org_id); CREATE INDEX index_users_on_updated_at ON public.users USING btree (updated_at); --- --- Name: index_users_on_vcs_id_and_vcs_type; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_users_on_vcs_id_and_vcs_type ON public.users USING btree (vcs_id, vcs_type); - - -- -- Name: index_users_on_vcs_type_and_vcs_id; Type: INDEX; Schema: public; Owner: - --