drizzle-orm
drizzle-orm copied to clipboard
[BUG]: postgresql migrations generation: the schema is ignored for indexes (indexes applied to "public" schema)
What version of drizzle-orm are you using?
0.23.2
Describe the Bug
Basically indexes are applied to public schema no matter if you use custom postgresql schema or not
Contents of my schema.ts looks like this:
const accountSchema = pgSchema('account');
export const usersTable = accountSchema.table("users", {
id: uuid("id").defaultRandom().primaryKey(),
email: varchar("email", { length: 255 }).notNull(),
// ....
},
(table) => {
return {
emailIdx: index().on(table.email),
emailUnique: uniqueIndex("users_email_unique").on(table.email),
idUnique: uniqueIndex("users_id_unique").on(table.id),
}
})
that generates this sql migration output:
CREATE TABLE IF NOT EXISTS "account"."users" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"email" varchar(255) NOT NULL,
// ...
);
CREATE INDEX IF NOT EXISTS users_email_index ON users ("email");
CREATE UNIQUE INDEX IF NOT EXISTS users_email_unique ON users ("email");
CREATE UNIQUE INDEX IF NOT EXISTS users_id_unique ON users ("id");
the indexes are created on public.user rather than account.users
If there is an API for this let me know, I will submit a docs update PR.
Thanks! Yeah itβs a bug. Will fix it
Related - https://github.com/drizzle-team/drizzle-orm/issues/440
I don't think drizzle-kit handles multiple schemas at all.
@erickreutz it's right. Will be next to get fixed on drizzle-kit side
Fixed in [email protected]