drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.35k stars 634 forks source link

[FEATURE]: Support `CREATE EXTENSION` #2124

Open mauriciabad opened 7 months ago

mauriciabad commented 7 months ago

Describe what you want

Hi, I want to use PostGIS but I cant find any way to add CREATE EXTENSION IF NOT EXISTS postgis; to the migrations files automatically. The ideal solution would be to somehow add support for CREATE EXTENSION, and include the generated tables to the schema.

Related to: https://github.com/drizzle-team/drizzle-orm/issues/671 and https://github.com/drizzle-team/drizzle-orm/issues/1315

Aymericr commented 7 months ago

Suggestions: Add dependencies for extensions, such as declaring schemas, so they would end up in the migrations.

Example:

import { env } from "@/env.mjs"
import { drizzle } from "drizzle-orm/postgres-js"
import { sql } from "drizzle-orm"
import postgres from "postgres"
import * as schema from "./load-schema"

const client = postgres(env.DATABASE_URL)
export const db = drizzle(client, {
    schema,
    extensions: {
      vector: sql`create extension if not exists vector with schema extensions;`,
      pg_trgm: sql`create extension if not exists pg_trgm with schema extensions;`
    }
})
mauriciabad commented 3 months ago

Maybe this issue is already solved.

In this docs they add run npx drizzle-kit generate --custom and add CREATE EXTENSION postgis; to the migration file.

https://orm.drizzle.team/learn/guides/postgis-geometry-point