import postgres from "postgres"; export const sql = postgres({ host: Deno.env.get("POSTGRES_HOST") || "db", port: parseInt(Deno.env.get("POSTGRES_PORT") || "5432"), database: Deno.env.get("POSTGRES_DB") || "nas_builder", username: Deno.env.get("POSTGRES_USER") || "nasadmin", password: Deno.env.get("POSTGRES_PASSWORD") || "your_secure_database_password_here", }); export async function initDb() { await sql` CREATE TABLE IF NOT EXISTS qa_checklists ( id VARCHAR(50) PRIMARY KEY, label TEXT NOT NULL, is_completed BOOLEAN DEFAULT false, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); `; // Seed some initial data if empty const count = await sql`SELECT count(*) FROM qa_checklists`; if (count[0].count === "0") { await sql` INSERT INTO qa_checklists (id, label, is_completed) VALUES ('qa-cap', 'Supercap mounted & isolated', false), ('qa-sas', 'Broadcom SAS seated in PCIe', false), ('qa-cool', 'Waterblock pressure tested', false), ('qa-zfs', 'ZFS pool scrub baseline passed', false) `; } console.log("✅ Database schema initialized"); }