Skip to content

feat(migration): add organization_id column to audit_log - #2789

Merged
t-kikuc merged 1 commit into
mainfrom
feat/org-audit-log-schema
Aug 26, 2026
Merged

feat(migration): add organization_id column to audit_log#2789
t-kikuc merged 1 commit into
mainfrom
feat/org-audit-log-schema

Conversation

@hvn2k1

@hvn2k1 hvn2k1 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Part of #1982

What this PR does

Adds an organization_id column (default '') and an (organization_id, timestamp DESC) index to the audit_log table, 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 in audit_log with an empty environment_id and a populated organization_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

  • MySQL uses ALGORITHM=INSTANT so the column add doesn't rebuild the table.
  • Postgres uses CREATE INDEX CONCURRENTLY, so the migration file is marked -- atlas:txmode none (CONCURRENTLY cannot run inside a transaction).
  • Index names follow each side's existing convention: idx_organization_id_timestamp_desc (MySQL, matching idx_environment_id_timestamp_desc) and idx_audit_log_organization_timestamp (Postgres, matching idx_audit_log_environment_timestamp).
  • Both statements were verified against MySQL 8.0 and Postgres 18 locally; atlas migrate validate passes for both directories.

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>
Copilot AI balanced review requested due to automatic review settings August 26, 2026 04:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds organization-scoped audit log schema support for MySQL and PostgreSQL.

Changes:

  • Adds organization_id with 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
hvn2k1 marked this pull request as ready for review August 26, 2026 04:39

@t-kikuc t-kikuc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@t-kikuc
t-kikuc merged commit 4a8271b into main Aug 26, 2026
13 checks passed
@t-kikuc
t-kikuc deleted the feat/org-audit-log-schema branch August 26, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants