Skip to content

Add organization_id to authentication_events

What does this MR do and why?

This MR adds organization_id as a sharding key to the authentication_events table as part of GitLab's Cells and Organizations initiative.

Background

The authentication_events table currently lacks a proper sharding key, which is required for GitLab's Cells architecture. Investigation in #553447 (closed) revealed that not all authentication events have an associated user_id, making organization_id a more suitable sharding key for this table.

Implementation Details

This is Step 1 of a 3-step migration process:

  • Step 1 (This MR): Add organization_id column with default value 1
  • Step 2: Update application code to ensure organization is properly set for new records
  • Step 3: Remove default value constraint once all records have proper organization associations

Technical Context

  • Table Size: Medium (as documented in db/docs/authentication_events.yml)
  • Feature Category: System Access
  • Schema: gitlab_main_org (organization-level data)
  • Model: AuthenticationEvent - tracks user authentication attempts across various providers

References

Database Impact

  • Migration Type: Non-blocking (uses concurrent operations)
  • Downtime: None expected
  • Index Addition: Concurrent index on organization_id
  • Foreign Key: Added with cascade delete to maintain referential integrity
  • Default Value: Temporary default of 1 (default organization) for existing records
Edited by Aboobacker MK

Merge request reports

Loading