how to define postgres schema (other than 'public') while setting up with drizzle-orm/node-postgres
I have this code :
import { integer, serial, text, pgTable } from 'drizzle-orm/pg-core';
export const users = pgTable('prod.users', {
id: serial('id').primaryKey(),
email: text('email'),
});
But getting error : relation "prod.users" does not exist
7 Replies
Hello, @ashishansurkar! You can find information related to schemas in docs: https://orm.drizzle.team/docs/schemas
Drizzle ORM - next gen TypeScript ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
That worked. Thank you very much @solo
you are welcome!
In the doc, we have to set the schema and then set the table. Is there a way we can set the schema after setting the table? I want to have the benefit of types from the table but I want to assign Postgres schema dynamically at runtime based on dev/prod environment.
@ashishansurkar probably this will work
@solo , Thanks again. That worked as well. I tried this earlier but forgot to import dotenv and thought it wouldn't work. Much appreciated.
happy to help you