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..febb02df --- /dev/null +++ b/db/main/migrate/20231206113245_add_unique_vcs_id_type_indexes.rb @@ -0,0 +1,12 @@ +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 + 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 1c3b66cc..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: - -- @@ -4730,13 +4723,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: - -- @@ -5151,24 +5137,38 @@ 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: - +-- Name: index_users_on_vcs_type_and_vcs_id; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX index_users_on_vcs_id_and_vcs_type ON public.users USING btree (vcs_id, vcs_type); +CREATE INDEX index_users_on_vcs_type_and_vcs_id ON public.users USING btree (vcs_type, vcs_id); -- --- Name: index_users_on_vcs_type_and_vcs_id; Type: INDEX; Schema: public; Owner: - +-- Name: managed_repositories_idx; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX index_users_on_vcs_type_and_vcs_id ON public.users USING btree (vcs_type, vcs_id); +CREATE INDEX managed_repositories_idx ON public.repositories USING btree (managed_by_installation_at); -- --- Name: managed_repositories_idx; Type: INDEX; Schema: public; Owner: - +-- Name: index_repositories_on_vcs_id_and_vcs_type; Type: INDEX; Schema: public; Owner: - -- -CREATE INDEX managed_repositories_idx ON public.repositories USING btree (managed_by_installation_at); +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); -- @@ -5969,6 +5969,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20220825140522'), ('20220905144600'), ('20221214171030'), -('20230208161446'); +('20230208161446'), +('20231206113245');