mirror of
https://github.com/jjbrunton/Sauci.git
synced 2026-10-31 18:19:43 +00:00
Replace the Supabase application data plane with the Node/PostgreSQL API, migrate mobile, admin, web, and MCP callers, add controlled cutover tooling, and define hardened Dokploy infrastructure.
26 lines
941 B
TypeScript
26 lines
941 B
TypeScript
import { resolve } from 'node:path';
|
|
import { drizzle } from 'drizzle-orm/node-postgres';
|
|
import { migrate } from 'drizzle-orm/node-postgres/migrator';
|
|
import { Pool } from 'pg';
|
|
|
|
const databaseUrl = process.env.DATABASE_URL;
|
|
|
|
if (!databaseUrl) {
|
|
throw new Error('DATABASE_URL is required for database migrations');
|
|
}
|
|
|
|
const migrationsFolder = resolve(process.env.MIGRATIONS_DIR ?? 'drizzle');
|
|
const pool = new Pool({ connectionString: databaseUrl, max: 2 });
|
|
const lockClient = await pool.connect();
|
|
|
|
try {
|
|
// Serializes migration containers during rolling/retried deployments.
|
|
await lockClient.query('select pg_advisory_lock($1)', [2_024_082_701]);
|
|
await migrate(drizzle(pool), { migrationsFolder });
|
|
console.log(`Database migrations completed from ${migrationsFolder}`);
|
|
} finally {
|
|
await lockClient.query('select pg_advisory_unlock($1)', [2_024_082_701]).catch(() => undefined);
|
|
lockClient.release();
|
|
await pool.end();
|
|
}
|