Create scheduled_messages for databases that never had it #80

Merged
ryan merged 1 commits from fix/scheduled-messages-migration into main 2026-10-13 07:52:55 -04:00
Owner

No committed migration creates scheduled_messages. Migrations 6–10 were generated outside the repo and never committed (the first state that knows ScheduledMessage is migration 11's snapshot). Production has the table; fresh databases, including the local dev DB, don't. On top of #79 a fresh database fails at migration 20's ALTER TABLE scheduled_messages.

Fix: 6_20260603000000_add_scheduled_messages.py, a CREATE TABLE IF NOT EXISTS. Aerich applies any file missing from its version table in numeric order, so:

  • Production: it runs once as a no-op, before migration 20.
  • Fresh databases: it creates the table before anything alters it.
  • Downgrade: intentionally empty, so it never drops a table that existing deployments created elsewhere.

⚠️ Not generated by aerich migrate, against the usual rule. Aerich can't generate this file because its saved state already includes the table. The DDL is Tortoise's own schema output (get_schema_sql) for the model as of migration 19, not hand-typed.

Verified on scratch Postgres:

  • Fresh DB: aerich upgrade succeeds through 19. Before this change it couldn't create the table at all.
  • Prod-like DB (table present, migration 6 unapplied): upgrade succeeds and existing rows are kept.

440 unit tests pass.

🤖 Generated with Claude Code

No committed migration creates `scheduled_messages`. Migrations 6–10 were generated outside the repo and never committed (the first state that knows `ScheduledMessage` is migration 11's snapshot). Production has the table; fresh databases, including the local dev DB, don't. On top of #79 a fresh database fails at migration 20's `ALTER TABLE scheduled_messages`. **Fix:** `6_20260603000000_add_scheduled_messages.py`, a `CREATE TABLE IF NOT EXISTS`. Aerich applies any file missing from its version table in numeric order, so: - **Production:** it runs once as a no-op, before migration 20. - **Fresh databases:** it creates the table before anything alters it. - **Downgrade:** intentionally empty, so it never drops a table that existing deployments created elsewhere. ⚠️ **Not generated by `aerich migrate`,** against the usual rule. Aerich can't generate this file because its saved state already includes the table. The DDL is Tortoise's own schema output (`get_schema_sql`) for the model as of migration 19, not hand-typed. **Verified on scratch Postgres:** - Fresh DB: `aerich upgrade` succeeds through 19. Before this change it couldn't create the table at all. - Prod-like DB (table present, migration 6 unapplied): upgrade succeeds and existing rows are kept. 440 unit tests pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
ryan added 1 commit 2026-10-12 23:17:07 -04:00
No committed migration creates the table: migrations 6-10 were generated
outside the repository, so fresh databases fail once anything alters it.
The new migration is CREATE TABLE IF NOT EXISTS, a no-op where the table
already exists. Aerich cannot generate it because its saved state already
includes the table; the DDL is Tortoise's schema output for the model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner

Correction to the description: this branch is based on main, which has 371 unit tests (all passing), not 440. 440 included #78's configuration tests.

Correction to the description: this branch is based on main, which has 371 unit tests (all passing), not 440. 440 included #78's configuration tests.
ryan merged commit 9034a5bcec into main 2026-10-13 07:52:55 -04:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ryan/simbarag#80