import postgres from 'postgres'; import fs from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const schemaPath = path.join(__dirname, 'postgres_schema.sql'); const connectionString = process.env.DATABASE_URL; if (!connectionString) { console.error("DATABASE_URL is not set"); process.exit(1); } const sql = postgres(connectionString); async function applySchema() { try { console.log("Reading schema file..."); const schemaSql = fs.readFileSync(schemaPath, 'utf8'); console.log("Applying schema to Supabase..."); // Split the SQL by semicolon to execute commands (basic splitting, might be issues with quotes but schema is simple) // Actually, postgres-js can execute multiple statements in one query if it's just a string. await sql.unsafe(schemaSql); console.log("Schema applied successfully!"); } catch (err) { console.error("Error applying schema:", err); process.exit(1); } finally { await sql.end(); } } applySchema();