Add organization_id foreign key for ai_settings

What does this MR do and why?

Adds the organization_id sharding key to ai_settings (schema-only, no behavior change): See references for followups; this is a multi step MR set.

  • Adds a nullable organization_id column.
  • Adds a unique index on organization_id.
  • Adds a foreign key to organizations with ON DELETE CASCADE.
  • Backfills the single existing row to the default organization (post-deploy).

The column is left nullable for now. NOT NULL enforcement and per-organization lookup (replacing Ai::Setting.instance / SingletonRecord) are deferred to follow-up iterations, so ai_settings is tracked in allowed_organization_id_violations.

References

Related to #531356

How to set up and validate locally

  1. Run the migrations:
    bundle exec rails db:migrate
  2. Confirm the column, index, and FK exist:
    Ai::Setting.column_names.include?('organization_id') # => true
  3. Confirm the existing row is backfilled to the default organization:
    Ai::Setting.instance.organization_id # => 1

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Alper Akgun

Merge request reports

Loading