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
@@ -0,0 +1,38 @@
"""Create scheduled_messages, which no committed migration ever created.
Migrations 6–10 were generated outside the repository and never committed, and
one of them created this table. Deployments that ran them already have it, so
this is IF NOT EXISTS and a no-op there; fresh databases need it before
migration 20 alters the table. Aerich cannot generate this file because its
saved model state already includes the table: the DDL below is Tortoise's
schema output for the model as of migration 19.
"""
from tortoise import BaseDBAsyncClient
RUN_IN_TRANSACTION = True
async def upgrade(db: BaseDBAsyncClient) -> str:
return """
CREATE TABLE IF NOT EXISTS "scheduled_messages" (
"id" UUID NOT NULL PRIMARY KEY,
"recipient" VARCHAR(255) NOT NULL,
"channel" VARCHAR(20) NOT NULL,
"content" TEXT NOT NULL,
"subject" VARCHAR(255),
"scheduled_at" TIMESTAMPTZ NOT NULL,
"status" VARCHAR(20) NOT NULL DEFAULT 'pending',
"recurrence" VARCHAR(20) NOT NULL DEFAULT 'none',
"use_agent" BOOL NOT NULL DEFAULT False,
"error_message" TEXT,
"created_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
"created_by_id" UUID NOT NULL REFERENCES "users" ("id") ON DELETE CASCADE
);"""
async def downgrade(db: BaseDBAsyncClient) -> str:
# Existing deployments created this table in an uncommitted migration;
# never drop it from under them.
return ""