From 5d9b2c03fb6bdd28e4c233a35005c709cdd3760c Mon Sep 17 00:00:00 2001 From: Christophe Besson Date: Sun, 13 Sep 2026 21:41:28 +0200 Subject: fix(hub): the migration chain runs, and a test says so MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `add_email_verification` wrote PostgreSQL's `(now() at time zone 'utc')` as a literal server default, where every other migration in the chain uses `sa.func.now()` and lets the dialect render it. On SQLite that is `sqlite3.OperationalError: near "at": syntax error` — so `meshbay-hub migrate` could not reach head on the database the suite and the documented local-hub workflow both use. Which is how it survived: the only test that ran alembic at all stopped at `c3d4e5f6a7b8`, the revision immediately before it. The two newest migrations — email verification, and the mail quota committed two days ago — had been run by exactly one thing, a production deploy, and the newest by nothing at all. `test_migrations_reach_head.py` upgrades to head and compares what that built against `Base.metadata`, both directions: a column in the models and in no migration never reaches production, and one in the migrations and in no model is a rename abandoned halfway. Both tests fail on the unfixed migration with the error above; the drift half was checked by adding a model column on purpose and watching it be named. The schemas agree today. It still does not check PostgreSQL-only behaviour — a default, an index type or a constraint one dialect accepts and the other refuses. Running the chain somewhere beats running it nowhere, and is not the same as running it where it ships. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01UMxEQadpzPkYLFf5CYKhpW --- .../db/migrations/versions/d4e5f6a7b8c9_add_email_verification.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'packages/meshbay-hub/src') diff --git a/packages/meshbay-hub/src/meshbay_hub/db/migrations/versions/d4e5f6a7b8c9_add_email_verification.py b/packages/meshbay-hub/src/meshbay_hub/db/migrations/versions/d4e5f6a7b8c9_add_email_verification.py index 20ba29d..6741eb8 100644 --- a/packages/meshbay-hub/src/meshbay_hub/db/migrations/versions/d4e5f6a7b8c9_add_email_verification.py +++ b/packages/meshbay-hub/src/meshbay_hub/db/migrations/versions/d4e5f6a7b8c9_add_email_verification.py @@ -34,8 +34,14 @@ def upgrade() -> None: sa.Column('purpose', sa.String(16), nullable=False), sa.Column('user_id', sa.String(36), sa.ForeignKey('users.id'), nullable=True), sa.Column('group_id', sa.String(36), sa.ForeignKey('groups.id'), nullable=True), + # `sa.func.now()`, as every other migration in this chain uses: the + # dialect running it renders it. Written out as PostgreSQL's + # `(now() at time zone 'utc')`, this was a syntax error on SQLite — so + # the chain could not reach head on the database the suite and the + # local-hub workflow both use, and the two newest migrations had been + # run by exactly one thing: a production deploy. sa.Column('created_at', sa.DateTime(timezone=True), - server_default=sa.text("(now() at time zone 'utc')")), + server_default=sa.func.now()), sa.Column('expires_at', sa.DateTime(timezone=True), nullable=False), sa.Column('verified_at', sa.DateTime(timezone=True), nullable=True), sa.Column('attempts', sa.Integer, server_default='0'), -- cgit v1.2.3