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_idcolumn. - Adds a unique index on
organization_id. - Adds a foreign key to
organizationswithON 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
- Next !243050 (merged)
- Next !243041 (merged)
How to set up and validate locally
- Run the migrations:
bundle exec rails db:migrate - Confirm the column, index, and FK exist:
Ai::Setting.column_names.include?('organization_id') # => true - 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