From 98406fafbe129f60bcb64023ecd0eb3acc36d717 Mon Sep 17 00:00:00 2001 From: Randall Stillwell Date: Mon, 25 May 2026 11:25:43 -0500 Subject: [PATCH] fix(migration): neon() returns rows array directly, not { rows, rowCount } MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The pick-a-name B2 migration script (shipped 2026-05-24 in `9abbab6`) was authored against the @vercel/postgres return shape `{ rows: [...], rowCount: N }` but uses @neondatabase/serverless's `neon()` tagged template, which returns the rows array DIRECTLY. As shipped, the first query at line 37 produced `before === undefined` and crashed at the `before.length` check on line 44 with `TypeError: Cannot read properties of undefined (reading 'length')`. Verified pattern from `lib/database.js` line 33: the wrapper adapter explicitly checks `Array.isArray(result)` because `neon()` returns the array directly. AGENTS.md Gotcha #1 mentions @neondatabase and @vercel/postgres run in parallel; this is exactly the kind of cross- contamination that creates. Fix: drop the `{ rows: x }` destructuring in all 3 sites (lines 37, 61, 73) and assign the result directly. Added a 4-line "why" comment block above the first site so the next person to write a migration script doesn't make the same mistake. Hand-verified post-fix: - node --check: exit 0 - Live run against prod Neon DB: migrated 3 users (admin id=1, alice id=5, bob id=6) from @tcgvault.com → @deckhearth.com. Idempotent re-run prints "Nothing to migrate." - No data loss; the broken first attempt didn't reach the UPDATE statement (crashed before line 54), so prod was unchanged. Operator action satisfied by this fix: - The `pick-a-name` PR #21 / squash `9abbab6` post-merge operator action ("run the migration script before next admin login") is now complete in prod. Admin login uses `admin@deckhearth.com`. Co-authored-by: Cursor --- scripts/migrations/2026-05-24-rename-admin-email.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/migrations/2026-05-24-rename-admin-email.js b/scripts/migrations/2026-05-24-rename-admin-email.js index ac880b0..7be1dfe 100644 --- a/scripts/migrations/2026-05-24-rename-admin-email.js +++ b/scripts/migrations/2026-05-24-rename-admin-email.js @@ -34,7 +34,11 @@ async function main() { const sql = neon(process.env.POSTGRES_URL); - const { rows: before } = await sql` + // NOTE: @neondatabase/serverless's tagged-template returns the rows array + // directly — NOT wrapped in { rows, rowCount } like @vercel/postgres does. + // See lib/database.js line 33 for the same finding. Do NOT destructure + // `{ rows: x }` from a `neon()` result; assign the result directly. + const before = await sql` SELECT id, email, role FROM users WHERE email LIKE '%@tcgvault.com' @@ -58,7 +62,7 @@ async function main() { WHERE email LIKE '%@tcgvault.com' `; - const { rows: after } = await sql` + const after = await sql` SELECT id, email, role FROM users WHERE email LIKE '%@deckhearth.com' @@ -70,7 +74,7 @@ async function main() { console.log(` id=${r.id} role=${r.role} email=${r.email}`); } - const { rows: stragglers } = await sql` + const stragglers = await sql` SELECT COUNT(*)::int AS count FROM users WHERE email LIKE '%@tcgvault.com' `; if (stragglers[0].count !== 0) { -- 2.45.2