Skip to content

Add foreign key constraint between user_audit_events and users table for protocells sharding

Problem

The user_audit_events table does not have a foreign key constraint on the users table, as noted in !202547 (diffs).

This will cause issues with the sharding effort for protocells because:

  • When organizations are moved to different cells, we will end up with copies of audit events in different cells
  • These rows will become orphaned, meaning we lose track of where data for an organization could be
  • This impacts data integrity and the ability to properly manage organizational data across cells

Proposal

Add a foreign key constraint between user_audit_events and users table to ensure proper referential integrity and support the protocells sharding effort.

Considerations

  • The *_audit_event tables are partitioned monthly but will be retained indefinitely
  • This is a medium-term effort that needs to be co-designed with the Org Data migration team
  • Need to consider the impact on existing data and migration strategy

Related Issues

Action Items

  • Design foreign key constraint implementation
  • Coordinate with Org Data migration team (@luciezhao @mkozono)
  • Plan migration strategy for existing data
  • Consider impact on partitioned table structure