Skip to content

Commit 3c54a96

Browse files
committed
fix(db): Remove backfill migration to fix PostgreSQL enum transaction issue
drizzle-kit migrate runs all pending migrations in a single transaction, so the new enum value is not committed when the UPDATE tries to use it. Moved backfill to standalone script: scripts/backfill-referral-legacy.sql Run this manually after migration 0039 is deployed.
1 parent 9c027aa commit 3c54a96

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

packages/internal/src/db/migrations/0040_referral_legacy_backfill.sql

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/internal/src/db/migrations/meta/_journal.json

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,5 @@
282282
"tag": "0039_quiet_franklin_storm",
283283
"breakpoints": true
284284
},
285-
{
286-
"idx": 40,
287-
"version": "7",
288-
"when": 1769650000000,
289-
"tag": "0040_referral_legacy_backfill",
290-
"breakpoints": true
291-
}
292285
]
293286
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-- Backfill script for referral_legacy grants
2+
-- Run this AFTER migration 0039_quiet_franklin_storm.sql has been deployed and committed
3+
--
4+
-- This script cannot be part of Drizzle migrations because PostgreSQL requires
5+
-- new enum values to be committed before they can be used in subsequent statements.
6+
--
7+
-- Usage: Connect to your database and run this script manually after deployment
8+
-- psql $DATABASE_URL -f scripts/backfill-referral-legacy.sql
9+
10+
-- Migrate existing referral grants that have an expiry date to referral_legacy type
11+
-- (These are the recurring grants from the old referral program)
12+
UPDATE "credit_ledger"
13+
SET "type" = 'referral_legacy',
14+
"priority" = 30
15+
WHERE "type" = 'referral'
16+
AND "expires_at" IS NOT NULL;
17+
18+
-- Update priority for remaining referral grants (one-time grants) to new priority
19+
UPDATE "credit_ledger"
20+
SET "priority" = 50
21+
WHERE "type" = 'referral'
22+
AND "expires_at" IS NULL;
23+
24+
-- Verify the changes
25+
SELECT "type", COUNT(*), MIN("priority"), MAX("priority")
26+
FROM "credit_ledger"
27+
WHERE "type" IN ('referral', 'referral_legacy')
28+
GROUP BY "type";

0 commit comments

Comments
 (0)