fix(migration): rename-admin-email crashes — neon() returns array, not { rows }
Hotfix to scripts/migrations/2026-05-24-rename-admin-email.js (shipped 2026-05-24 in pick-a-name PR #21). Script crashed on first invocation with 'TypeError: Cannot read properties of undefined (reading length)' at line 44. Root cause: architect designed against @vercel/postgres return shape { rows, rowCount } but the script uses @neondatabase/serverless's neon() tagged template which returns the rows array directly. AGENTS.md Gotcha #1 (two SQL clients in parallel) is exactly this kind of cross-contamination. Fix: drop the { rows: x } destructuring in all 3 sites + add a 4-line why comment block above the first site so the next migration author doesn't repeat. Verified hand-run against prod Neon DB: migrated 3 users (admin id=1, alice id=5, bob id=6) from @tcgvault.com to @deckhearth.com; idempotent re-run prints 'Nothing to migrate.' No data risk on the original crash — script exited at line 44 before reaching the UPDATE at line 54. PR #21 operator action item now complete in prod. Surfaces a P3 follow-up: add-neon-return-shape-rule (or fold into single-sql-client). All CI green: lint 128 baseline, vitest 21/21, Playwright smoke 3/3 in 1m2s, forbidden-cors-headers pass, forbidden-endpoints pass. PR #24, commit 98406fa.
This commit is contained in:
parent
7e06ab559a
commit
1de0e03522
1 changed files with 7 additions and 3 deletions
|
|
@ -34,7 +34,11 @@ async function main() {
|
||||||
|
|
||||||
const sql = neon(process.env.POSTGRES_URL);
|
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
|
SELECT id, email, role
|
||||||
FROM users
|
FROM users
|
||||||
WHERE email LIKE '%@tcgvault.com'
|
WHERE email LIKE '%@tcgvault.com'
|
||||||
|
|
@ -58,7 +62,7 @@ async function main() {
|
||||||
WHERE email LIKE '%@tcgvault.com'
|
WHERE email LIKE '%@tcgvault.com'
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const { rows: after } = await sql`
|
const after = await sql`
|
||||||
SELECT id, email, role
|
SELECT id, email, role
|
||||||
FROM users
|
FROM users
|
||||||
WHERE email LIKE '%@deckhearth.com'
|
WHERE email LIKE '%@deckhearth.com'
|
||||||
|
|
@ -70,7 +74,7 @@ async function main() {
|
||||||
console.log(` id=${r.id} role=${r.role} email=${r.email}`);
|
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'
|
SELECT COUNT(*)::int AS count FROM users WHERE email LIKE '%@tcgvault.com'
|
||||||
`;
|
`;
|
||||||
if (stragglers[0].count !== 0) {
|
if (stragglers[0].count !== 0) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue