From 0db1609c89f6b6f95f5e0a4af7805e8eb20b05c9 Mon Sep 17 00:00:00 2001 From: Tyler Date: Tue, 9 Jun 2026 15:50:53 -0600 Subject: [PATCH] fix(deploy): add explicit pre-flight check for neon_auth schema before running migrations (better error than raw 3F000 from 0001_init.sql) --- .gitea/workflows/deploy.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 781d6d0..1acbd0d 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -25,6 +25,28 @@ jobs: DATABASE_URL: ${{ secrets.DATABASE_URL }} run: | set -e + echo "=== Pre-flight: checking for neon_auth schema (required by 0001_init.sql for FKs to neon_auth.user and related RPCs) ===" + node -e ' + const { Client } = require("pg"); + const url = process.env.DATABASE_URL; + if (!url) { console.error("No DATABASE_URL"); process.exit(1); } + const c = new Client({ connectionString: url }); + c.connect() + .then(() => c.query("SELECT 1 FROM information_schema.schemata WHERE schema_name = \'neon_auth\'")) + .then(res => { + if (res.rows.length === 0) { + console.error("✗ FATAL: neon_auth schema does not exist in the target database."); + console.error("Enable Neon Auth on the Neon project/branch that this DATABASE_URL points to first."); + console.error("Run: neonctl neon-auth (or equivalent) against the correct Neon branch."); + console.error("The neon_auth schema is created by Neon Auth and is a prerequisite for 0001_init.sql."); + process.exit(1); + } + console.log("✓ neon_auth schema exists"); + return c.end(); + }) + .then(() => process.exit(0)) + .catch(e => { console.error("Pre-flight check failed:", e.message); process.exit(1); }); + ' echo "=== Running migrations against DATABASE_URL (masked value for logs) ===" npm run migrate:one echo "=== Post-migration verification: critical table admin_users must exist ==="