SPB Git
720 B · 9 lines typescript
1import { migrate } from "drizzle-orm/postgres-js/migrator";2import { drizzle } from "drizzle-orm/postgres-js";3import postgres from "postgres";4const url = process.env.DATABASE_URL; if (!url) throw new Error("DATABASE_URL missing");5const sql = postgres(url, { max: 1 });6for (const ext of ["vector", "pg_trgm", "unaccent"]) { try { await sql.unsafe(`CREATE EXTENSION IF NOT EXISTS ${ext}`); } catch (e: any) { const ok = (await sql`select 1 from pg_extension where extname = ${ext}`).length > 0; if (!ok) throw new Error(`extension ${ext} missing and cannot be created by this role: ${e.message}`); } }7await migrate(drizzle(sql), { migrationsFolder: "./drizzle" });8console.log("migrations applied"); await sql.end();9
Files · main
Menu

Theme