Skip to content

Add NOT NULL constraint for identities -> user_id

What does this MR do and why?

Add NOT NULL constraint for identities -> user_id

Ensures a user_id is always set for the identities table. This is required for upcoming sharding changes. The application already enforces that identities are created and updated with a user_id, but so far we have not enforced that with a database constraint.

Since identities without a user_id cannot be used for any purpose, we add a migration to remove any such corrupted records in case they exist on a self-managed instance.

References

Database Review

I reviewed our guidance on adding a NOT NULL constraint to an existing column. However, all the steps under "current release N.M " are already implemented by the application. Have verified there are no records like this in production ( private link ).

This MR includes a migration to remove any corrupted records, in case self-managed instances have bad data, per this suggestion. We do not expect any instances to have corrupted records.

Screenshots or screen recordings

Before After

How to set up and validate locally

  1. Run migrations
  2. On the Rails console, run: Identity.create!(extern_uid: 'abc123', provider: 'ldapmain') - this should raise an error like ActiveRecord::RecordInvalid: Validation failed: User must exist

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.

Related to #557855 (closed)

Edited by Andrew Evans

Merge request reports

Loading