/** * drizzle-kit quotes any type name it does not recognise, so a geography column * is emitted as "geography(Point,4326)" — a quoted identifier, which Postgres * rejects with `type "geography(Point,4326)" does not exist`. * * This unquotes them. It runs automatically as part of `pnpm db:generate`; * if you ever run `drizzle-kit generate` directly, run this afterwards. */ import { readdir, readFile, writeFile } from 'node:fs/promises'; import { join } from 'node:path'; const DIR = 'drizzle'; const QUOTED = /"(geography|geometry)\(([^)"]*)\)"/g; const files = (await readdir(DIR)).filter((f) => f.endsWith('.sql')); let patched = 0; for (const file of files) { const path = join(DIR, file); const before = await readFile(path, 'utf8'); const after = before.replace(QUOTED, '$1($2)'); if (after !== before) { await writeFile(path, after); patched++; console.log(` unquoted PostGIS types in ${file}`); } } console.log(patched ? `PostGIS fixup applied to ${patched} file(s)` : 'PostGIS fixup: nothing to do');