pushSchema from drizzle-kit/api is not working if pgSchema specified in the schema.ts file

Hey, I'm trying to apply migration file to a custom schema using this approach (https://orm.drizzle.team/docs/schemas). If I'll specify pgSchema in schema.ts file the pushSchema still tries to apply to the default public schema ignoring the pgSchema declaration: my schema.ts:
export const schema = pgSchema('custom_schema_name');

export const users = schema.table('users', {
id: serial('id').primaryKey(),
email: varchar('email', { length: 255 }).notNull().unique(),
password: varchar('password', { length: 255 }),
});
export const schema = pgSchema('custom_schema_name');

export const users = schema.table('users', {
id: serial('id').primaryKey(),
email: varchar('email', { length: 255 }).notNull().unique(),
password: varchar('password', { length: 255 }),
});
my db.service.ts:
import { pushSchema } from "drizzle-kit/api";
import * as schema from '../schemas/schema';
...

const db = drizzle(this.configService.get<string>('DATABASE_URL')!)
const result = await pushSchema(schema, db as unknown as PgDatabase<never>);
await result.apply();
import { pushSchema } from "drizzle-kit/api";
import * as schema from '../schemas/schema';
...

const db = drizzle(this.configService.get<string>('DATABASE_URL')!)
const result = await pushSchema(schema, db as unknown as PgDatabase<never>);
await result.apply();
This resulst in a conflict because pushSchema tries to apply the schema.ts file to the public schema instead of pgSchema specified in the file. Am I doing something wrong?
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?