Skip to content

fix(db): renumber audit_actor_stamps migration to clear 000074 collision - #1261

Merged
cristim merged 1 commit into
mainfrom
fix/migration-74-collision
Jun 19, 2026
Merged

fix(db): renumber audit_actor_stamps migration to clear 000074 collision#1261
cristim merged 1 commit into
mainfrom
fix/migration-74-collision

Conversation

@cristim

@cristim cristim commented Jun 19, 2026

Copy link
Copy Markdown
Member

Root cause

PR #1011 added 000074_audit_actor_stamps while prod already has 000074_repair_partial_migration_058_067 applied and recorded in schema_migrations. The duplicate migration number caused the "CI - Build & Test / Integration Tests" job to fail at "Run database migrations" with:

duplicate migration file: 000074_repair_partial_migration_058_067.down.sql

Fix

  • Keep 000074_repair_partial_migration_058_067 at its existing number (prod-applied; recorded in schema_migrations as version 74).
  • Renumber 000074_audit_actor_stamps -> 000077_audit_actor_stamps (next free slot after 000076).
  • Update SQL comment headers in both .up.sql and .down.sql to reflect 000077.
  • No SQL DDL changes.

Verification

  • dups=$(ls internal/database/postgres/migrations/*.up.sql | cut -c-6 | sort | uniq -d) returns empty (pre-commit collision check passes).
  • go build ./... succeeds.
  • Exactly one 000074 entry (the repair) and one 000077 entry (audit stamps) in the migrations directory.
  • No other references to 000074_audit_actor_stamps anywhere in the codebase (grep clean).

Safety check

000074_audit_actor_stamps was merged today via PR #1011 and is NOT yet applied to any environment. Safe to renumber.

Summary by CodeRabbit

  • New Features
    • Enhanced audit trail support with user and timestamp tracking for transaction state changes.

…ision

PR #1011 added 000074_audit_actor_stamps while prod already has
000074_repair_partial_migration_058_067 applied and recorded in
schema_migrations. The duplicate caused "CI - Build & Test /
Integration Tests" to fail at "Run database migrations" with
duplicate migration file error. Keep the repair at 074 (prod-applied)
and move the new audit stamp migration to 077 (next free slot).
@cristim cristim added triaged Item has been triaged priority/p1 Next up; this sprint type/bug Defect labels Jun 19, 2026
@cristim

cristim commented Jun 19, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 835a8be1-7600-42f0-a2b3-c5439242bec5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Migration 000077 adds two nullable audit columns, transitioned_by (UUID FK referencing users(id) with ON DELETE SET NULL) and transitioned_at (TIMESTAMPTZ), to purchase_executions, ri_exchange_history, and account_registrations using idempotent ADD COLUMN IF NOT EXISTS. The down migration drops those same columns conditionally. Both files have their header comments corrected from 000074 to 000077.

Changes

Audit Actor Stamp Migration (000077)

Layer / File(s) Summary
Up and down migration SQL
internal/database/postgres/migrations/000077_audit_actor_stamps.up.sql, internal/database/postgres/migrations/000077_audit_actor_stamps.down.sql
Up script adds transitioned_by (nullable UUID FK to users) and transitioned_at (nullable TIMESTAMPTZ) to purchase_executions, ri_exchange_history, and account_registrations via ADD COLUMN IF NOT EXISTS. Down script drops those columns conditionally. Header comments in both files are corrected from 000074 to 000077.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • LeanerCloud/CUDly#1011: Introduced the original actor-stamping schema and plumbing for the same transitioned_by/transitioned_at columns on the same three tables that this migration targets.
  • LeanerCloud/CUDly#1127: Contains a migration that also asserts audit-related columns (executed_by_user_id/executed_at) on purchase_executions, overlapping with the same schema area modified here.

Suggested labels

severity/high, impact/few, effort/m

Poem

🐇 Hoppy little stamps appear,
transitioned_by and transitioned_at are here!
Three tables gain their audit trail,
IF NOT EXISTS — it cannot fail.
Down the migration, columns fall away,
The rabbit tracks each state-machine's day! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: renumbering the audit_actor_stamps migration from 000074 to 000077 to resolve a collision.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/migration-74-collision

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/p1 Next up; this sprint triaged Item has been triaged type/bug Defect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant