Add unique index for organization integration defaults

What does this MR do and why?

Adds a unique index on integrations (type_new, organization_id) WHERE instance = true.

Nothing today stops two instance-level integrations of the same type existing in one organization. The app-level uniqueness validation is scoped only by instance, not by organization_id. This change adds the same guarantee at the database level, ahead of scoping the lookups/validation themselves in a follow-up MR.

References

Resolves #631286 (closed) Part of epic gitlab-org#22859

Screenshots or screen recordings

N/A — schema-only change, no UI.

How to set up and validate locally

  1. Run bundle exec rails db:migrate.
  2. Confirm the index exists: \d integrations in psql, or check db/structure.sql for index_integrations_on_type_new_and_organization_id_unique.

Migration output:

main: == 20260930095000 AddUniqueIndexOnIntegrationsTypeNewOrganizationId: migrating
main: -- add_index(:integrations, [:type_new, :organization_id], {:unique=>true, :where=>"instance = true", :name=>"index_integrations_on_type_new_and_organization_id_unique", :algorithm=>:concurrently})
main:    -> 0.0046s
main: == 20260930095000 AddUniqueIndexOnIntegrationsTypeNewOrganizationId: migrated (0.0481s)

(Same output on the ci and sec connections in this non-decomposed dev setup.)

MR acceptance checklist

Evaluated against the MR acceptance checklist. No app code changes; existing integration specs pass unchanged (spec/models/integration_spec.rb, spec/models/integrations/every_integration_spec.rb, spec/models/concerns/integrations/).

Related to #631286 (closed)

Merge request reports

Loading
Loading