Skip to content

Fix teacher_reported_today migration: dynamic db name + idempotent CR… - #119

Merged
buzz-code merged 1 commit into
mainfrom
claude/teacher-phone-call-flow-oan736
Jul 18, 2026
Merged

buzz-code merged 1 commit into
mainfrom
claude/teacher-phone-call-flow-oan736

Conversation

@buzz-code

Copy link
Copy Markdown
Owner

…EATE VIEW

Two real bugs found from a failing production deploy log:

  • The migration hardcoded the literal database name "mysql_database" (leaked from local dev) into the typeorm_metadata bookkeeping statements, instead of using the dynamic ${dbName} pattern this codebase's other view migrations use (queryRunner.connection.options.database). Would break against any database not literally named "mysql_database".
  • CREATE VIEW / DROP VIEW aren't idempotent: MySQL DDL causes an implicit commit independent of the migration's transaction, so if a deploy is retried after a partial failure (view created, tracking row not yet committed), the next attempt fails with "table already exists". Switched to CREATE OR REPLACE VIEW and DROP VIEW IF EXISTS, plus clearing any stale typeorm_metadata row first.

Verified by reproducing the exact reported failure against a MySQL database named differently from my sandbox: ran migrations up to this one, manually created the view outside migration tracking (simulating the partial-failure state), then confirmed the fixed migration completes successfully and the view still returns correct data.

…EATE VIEW

Two real bugs found from a failing production deploy log:
- The migration hardcoded the literal database name "mysql_database" (leaked
  from local dev) into the typeorm_metadata bookkeeping statements, instead
  of using the dynamic ${dbName} pattern this codebase's other view
  migrations use (queryRunner.connection.options.database). Would break
  against any database not literally named "mysql_database".
- CREATE VIEW / DROP VIEW aren't idempotent: MySQL DDL causes an implicit
  commit independent of the migration's transaction, so if a deploy is
  retried after a partial failure (view created, tracking row not yet
  committed), the next attempt fails with "table already exists". Switched
  to CREATE OR REPLACE VIEW and DROP VIEW IF EXISTS, plus clearing any
  stale typeorm_metadata row first.

Verified by reproducing the exact reported failure against a MySQL
database named differently from my sandbox: ran migrations up to this
one, manually created the view outside migration tracking (simulating
the partial-failure state), then confirmed the fixed migration completes
successfully and the view still returns correct data.
@buzz-code
buzz-code merged commit 645df24 into main Jul 18, 2026
1 check passed
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.

2 participants