Some checks failed
Deploy to Cloudflare Workers / deploy (push) Has been cancelled
52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
import { spawnSync } from "child_process";
|
|
import { readFileSync, existsSync } from "fs";
|
|
import { dirname, join } from "path";
|
|
import { fileURLToPath } from "url";
|
|
|
|
const root = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
|
|
function loadEnvLocal() {
|
|
const path = join(root, ".env.local");
|
|
if (!existsSync(path)) return {};
|
|
const env = {};
|
|
for (const line of readFileSync(path, "utf8").split(/\r?\n/)) {
|
|
const trimmed = line.trim();
|
|
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
const eq = trimmed.indexOf("=");
|
|
if (eq === -1) continue;
|
|
const key = trimmed.slice(0, eq).trim();
|
|
let val = trimmed.slice(eq + 1).trim();
|
|
if (
|
|
(val.startsWith('"') && val.endsWith('"')) ||
|
|
(val.startsWith("'") && val.endsWith("'"))
|
|
) {
|
|
val = val.slice(1, -1);
|
|
}
|
|
env[key] = val;
|
|
}
|
|
return env;
|
|
}
|
|
|
|
const env = loadEnvLocal();
|
|
const dbUrl = env.SUPABASE_DB_URL;
|
|
|
|
if (!dbUrl) {
|
|
console.error("ERROR: SUPABASE_DB_URL is not set in .env.local\n");
|
|
console.error("1. Open https://supabase.com/dashboard/project/vcxpcyafnlyiyqmapyyy");
|
|
console.error("2. Connect -> Session mode (port 5432)");
|
|
console.error("3. Add to .env.local:");
|
|
console.error(
|
|
" SUPABASE_DB_URL=postgresql://postgres.vcxpcyafnlyiyqmapyyy:PASSWORD@aws-0-REGION.pooler.supabase.com:5432/postgres"
|
|
);
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log("Pushing migrations via pooler (IPv4)...");
|
|
const result = spawnSync("npx", ["supabase", "db", "push", "--db-url", dbUrl], {
|
|
cwd: root,
|
|
stdio: "inherit",
|
|
shell: true,
|
|
});
|
|
|
|
process.exit(result.status ?? 1);
|