Skip to content

Commit 62956f2

Browse files
committed
fix: handle NULL columns during CHECK constraint migration
Use COALESCE to fill NULL created_at/updated_at/expires_at values during table rebuild, preventing NOT NULL constraint failures.
1 parent 5583a54 commit 62956f2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/db/sqlite.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ export class TransactionDB {
9999
created_at TEXT NOT NULL DEFAULT (datetime('now')),
100100
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
101101
);
102-
INSERT INTO transactions_new SELECT * FROM transactions;
102+
INSERT INTO transactions_new (id, type, wallet, sol_amount, usdc_amount, mainnet_tx, devnet_tx, mainnet_payout_tx, memo, status, expires_at, created_at, updated_at)
103+
SELECT id, type, wallet, sol_amount, usdc_amount, mainnet_tx, devnet_tx, mainnet_payout_tx, memo, status,
104+
COALESCE(expires_at, datetime(created_at, '+30 minutes')),
105+
COALESCE(created_at, datetime('now')),
106+
COALESCE(updated_at, datetime('now'))
107+
FROM transactions;
103108
DROP TABLE transactions;
104109
ALTER TABLE transactions_new RENAME TO transactions;
105110
CREATE INDEX IF NOT EXISTS idx_transactions_status ON transactions(status);

0 commit comments

Comments
 (0)