How can I properly configure Drizzle?

I'm following the Prisma migration guide and I have a few problems: My database is in my own schema, but I can't find the option to specify the schema. Drizzle defaults to public which is an antipattern (and also empty in my case). Apart from this even though I configure Drizzle to put the schema file in a specific folder:
export default defineConfig({
dialect: "postgresql",
out: "./src/drizzle",
schema: "./src/repository/schema.ts",
dbCredentials: {
url: process.env.DATABASE_URL ?? fail("DATABASE_URL is not defined"),
},
verbose: true,
strict: true,
});
export default defineConfig({
dialect: "postgresql",
out: "./src/drizzle",
schema: "./src/repository/schema.ts",
dbCredentials: {
url: process.env.DATABASE_URL ?? fail("DATABASE_URL is not defined"),
},
verbose: true,
strict: true,
});
it puts the resulting schema.ts in ./src/drizzle/schema.ts Is this something I can configure?
8 Replies
addamsson
addamssonOP•6mo ago
I've opened a bug ticket as I've exhausted all options and this seems to be a bug in Drizzle itself: https://github.com/drizzle-team/drizzle-orm/issues/2449
GitHub
[BUG]: Drizzle doesn't use the schema part of a database connection...
What version of drizzle-orm are you using? 0.31.0 What version of drizzle-kit are you using? 0.22.1 Describe the Bug I have the following DATABASE_URL in my .env file: DATABASE_URL=postgresql://x:x...
A Dapper Raccoon
A Dapper Raccoon•6mo ago
I'm not very familiar with Postgres, but IIRC you just append a search_path=mySchema parameter to the connection string. From a little searching, it also sounds like your user might be configured to use or prioritize public by default. It looks like you can change that from the shell via
alter user myUser set search_path to '"$user"';
alter user myUser set search_path to '"$user"';
(such that the search_path parameter in the connection string should not be necessary) https://www.postgresql.org/docs/16/ddl-schemas.html#DDL-SCHEMAS-PATH
addamsson
addamssonOP•6mo ago
I have that in my connection string and it doesn't work partly because the migrations are wrong all enums are generated into the public schema and there is no way to change that
DO $$ BEGIN
CREATE TYPE "public"."AccountProvider" AS ENUM('LOCAL', 'DISCORD');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
CREATE TYPE "public"."ConfigLevel" AS ENUM('USER', 'ORG', 'TEAM', 'MODULE');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
CREATE TYPE "public"."JobState" AS ENUM('SCHEDULED', 'RUNNING', 'COMPLETED', 'FAILED', 'UNKNOWN', 'CANCELED');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
DO $$ BEGIN
CREATE TYPE "public"."AccountProvider" AS ENUM('LOCAL', 'DISCORD');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
CREATE TYPE "public"."ConfigLevel" AS ENUM('USER', 'ORG', 'TEAM', 'MODULE');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
CREATE TYPE "public"."JobState" AS ENUM('SCHEDULED', 'RUNNING', 'COMPLETED', 'FAILED', 'UNKNOWN', 'CANCELED');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
A Dapper Raccoon
A Dapper Raccoon•6mo ago
Oh okay yeah - that's a problem 😬
addamsson
addamssonOP•6mo ago
😅 there are other problems too https://discord.com/channels/1043890932593987624/1247567682539098234 the main problem is that i'm migrating from prisma and all of this was working before. I'm using the official docker image for postgresql and this worked with every tool I've used before (prisma / kysely / typeorm) so I think it should work with Drizzle out of the box....but even then it should be an option to explicitly specify a schema and it should be consistent with how the migrator works
A Dapper Raccoon
A Dapper Raccoon•6mo ago
Oh I totally agree. It definitely seems like a bug or oversight in the migrator implementation, and I would think fairly high priority for impairing users trying to transition to the Drizzle suite. If the Kit source was presently available, I'm curious enough about all of this that I'd love to try and track down the responsible code - not that this is really in my general wheelhouse What is the Prisma Migration guide that you're following, out of curiosity?
addamsson
addamssonOP•6mo ago
for me this is a blocker right now 😅
addamsson
addamssonOP•6mo ago
Drizzle ORM - Migrate from Prisma to Drizzle
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Want results from more Discord servers?
Add your server