Skip to content

Upgrade pre-migration v1 databases in place instead of failing deploy - #3

Merged
het2576 merged 1 commit into
mainfrom
fix/migrate-legacy-db
Nov 16, 2026
Merged

het2576 merged 1 commit into
mainfrom
fix/migrate-legacy-db

Conversation

@het2576

@het2576 het2576 commented Nov 16, 2026

Copy link
Copy Markdown
Owner

The first deploy with Alembic failed with 'relation "users" already exists': production was created by v1's create_all(), so it had tables but no alembic_version, and the v2 migration tried to create everything.

The v2 migration now detects that case and upgrades the v1 tables in place, keeping all data:

  • adds the new columns, recall tables and ON DELETE rules, each only if missing
  • backfills canonical_url; later duplicates of a link are kept but suffixed so the new per-user unique constraint holds
  • recomputes read time from word count (YouTube keeps v1's value)
  • removes v1 "opened" and "skipped" events, which v2 treats as noise, and collapses duplicate clicks so (item_id, event_type) can be unique

Fresh databases and databases already at this revision are unaffected, and both paths produce an identical schema (pg_dump diff, alembic check). New tests run both paths against real throwaway databases, using the exact v1 DDL; the v1 test fails on the old migration with the production error.

Also: a failed profile-embedding call no longer aborts the dispatch build. Migrated users have profile text but no embedding, so their first v2 dispatch computes one; on failure it now ranks without it and retries later.

The first deploy with Alembic failed with 'relation "users" already exists':
production was created by v1's create_all(), so it had tables but no
alembic_version, and the v2 migration tried to create everything.

The v2 migration now detects that case and upgrades the v1 tables in place,
keeping all data:
- adds the new columns, recall tables and ON DELETE rules, each only if missing
- backfills canonical_url; later duplicates of a link are kept but suffixed
  so the new per-user unique constraint holds
- recomputes read time from word count (YouTube keeps v1's value)
- removes v1 "opened" and "skipped" events, which v2 treats as noise, and
  collapses duplicate clicks so (item_id, event_type) can be unique

Fresh databases and databases already at this revision are unaffected, and
both paths produce an identical schema (pg_dump diff, alembic check).
New tests run both paths against real throwaway databases, using the exact
v1 DDL; the v1 test fails on the old migration with the production error.

Also: a failed profile-embedding call no longer aborts the dispatch build.
Migrated users have profile text but no embedding, so their first v2
dispatch computes one; on failure it now ranks without it and retries later.
@vercel

vercel Bot commented Nov 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loop-wire Ready Ready Preview Nov 16, 2026 7:16pm UTC

@het2576
het2576 merged commit c444184 into main Nov 16, 2026
4 checks passed

This branch was successfully deployed

1 active deployment
Preview — e9a45017 Deployed Nov 16, 2026 by vercel[bot]
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.

1 participant