Postgres Schema (namespace)

Does anyone have a minimal example of a Drizzle postgres schema that uses the Postgres "Schema" (namespace) feature? On drizzle kit push I keep getting error: schema "meow" does not exist.
import { sql } from "drizzle-orm"
import {
index,
serial,
timestamp,
pgSchema,
text,
} from "drizzle-orm/pg-core"

const schema = pgSchema("meow")

const time = (name="time") => timestamp(name, { withTimezone: true, mode: "date" }).default(sql`CURRENT_TIMESTAMP`).notNull()
const event = schema.enum("event_type", ["click", "buy", "poll"])

export const User = schema.table("user", {
id: text("id").primaryKey(),
email: text("email").unique().notNull(),
hash: text("hash").notNull(),
username: text("username").unique().notNull(),
})
import { sql } from "drizzle-orm"
import {
index,
serial,
timestamp,
pgSchema,
text,
} from "drizzle-orm/pg-core"

const schema = pgSchema("meow")

const time = (name="time") => timestamp(name, { withTimezone: true, mode: "date" }).default(sql`CURRENT_TIMESTAMP`).notNull()
const event = schema.enum("event_type", ["click", "buy", "poll"])

export const User = schema.table("user", {
id: text("id").primaryKey(),
email: text("email").unique().notNull(),
hash: text("hash").notNull(),
username: text("username").unique().notNull(),
})
4 Replies
Darren
Darren2mo ago
in your drizzle config have you added
import { defineConfig } from 'drizzle-kit'
export default defineConfig({
schemaFilter: ["meow"],
});
import { defineConfig } from 'drizzle-kit'
export default defineConfig({
schemaFilter: ["meow"],
});
ive honestly only used it where the schema was already made, i dont know qhat happens if it doesnt exist
meow
meow2mo ago
I have. I'm a bit confused because when I look at the docs https://orm.drizzle.team/docs/column-types/pg#enum I see that it should've created a corresponding SQL statement to create the schema for me. But then I don't see it when I generate the migration files.
Darren
Darren2mo ago
ah.. try adding export to
const schema = pgSchema("meow")
const schema = pgSchema("meow")
so
export const schema = pgSchema("meow")
export const schema = pgSchema("meow")
then in your config make sure you import * from that file
meow
meow2mo ago
Yo... massive thanks. What an oversight by me.
Want results from more Discord servers?
Add your server