Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: postgresql migrations generation: the schema is ignored for indexes (indexes applied to "public" schema) #413

Closed
mppub opened this issue Apr 8, 2023 · 4 comments
Assignees
Labels
bug Something isn't working drizzle-kit

Comments

@mppub
Copy link

mppub commented Apr 8, 2023

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.

@mppub mppub added the bug Something isn't working label Apr 8, 2023
@AndriiSherman
Copy link
Member

AndriiSherman commented Apr 8, 2023

Thanks! Yeah it’s a bug. Will fix it

@erickreutz
Copy link

Related - #440

I don't think drizzle-kit handles multiple schemas at all.

@AndriiSherman
Copy link
Member

@erickreutz it's right. Will be next to get fixed on drizzle-kit side

@AndriiSherman
Copy link
Member

Fixed in drizzle-kit@0.18.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working drizzle-kit
Projects
None yet
Development

No branches or pull requests

4 participants