feat(migration): add organization_id column to audit_log - #2789
Merged
Conversation
Adds an organization_id column and (organization_id, timestamp DESC) index to the audit_log table on both MySQL and Postgres, so organization-level events can be stored there with an empty environment_id and read by organization admins. Step 1 of #1982. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds organization-scoped audit log schema support for MySQL and PostgreSQL.
Changes:
- Adds
organization_idwith an empty-string default. - Adds organization/timestamp indexes for efficient queries.
- Updates Atlas migration checksums.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
migration/mysql/20260826000000_add_audit_log_organization_id.sql |
Adds the MySQL column and index. |
migration/mysql/atlas.sum |
Registers the MySQL migration. |
migration/postgres/20260826000000_add_audit_log_organization_id.sql |
Adds the PostgreSQL column and concurrent index. |
migration/postgres/atlas.sum |
Registers the PostgreSQL migration. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
hvn2k1
marked this pull request as ready for review
August 26, 2026 04:39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #1982
What this PR does
Adds an
organization_idcolumn (default'') and an(organization_id, timestamp DESC)index to theaudit_logtable, for both MySQL and Postgres.Background / Why this PR is needed
Organization-level events (account changes, environment/project creation, organization updates) currently go to
admin_audit_log, which only system admins can read, so organization admins cannot see their own organization's activity. The plan is to store these events inaudit_logwith an emptyenvironment_idand a populatedorganization_id, and serve them from the existing audit log console with role-scoped filters. This PR is step 1 (schema only); the write path, history migration, and read path follow in separate PRs.Points
ALGORITHM=INSTANTso the column add doesn't rebuild the table.CREATE INDEX CONCURRENTLY, so the migration file is marked-- atlas:txmode none(CONCURRENTLYcannot run inside a transaction).idx_organization_id_timestamp_desc(MySQL, matchingidx_environment_id_timestamp_desc) andidx_audit_log_organization_timestamp(Postgres, matchingidx_audit_log_environment_timestamp).atlas migrate validatepasses for both directories.