drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.64k stars 650 forks source link

[BUG]: Foreign key name length #3244

Open L-Mario564 opened 3 weeks ago

L-Mario564 commented 3 weeks ago

What version of drizzle-orm are you using?

?

What version of drizzle-kit are you using?

?

Describe the Bug

From drizzle-kit-mirror repo: https://github.com/drizzle-team/drizzle-kit-mirror/issues/128.

With succinct table and column names, the foreign key constraint names are sometimes too long, more than 64 characters, which is the limit in mysql.

Expected behavior

No response

Environment & setup

No response

dmitrysteblyuk commented 1 day ago

Same with postgres. A workaround would be to use foreignKey() and provide a custom name. But if one uses .references(), then drizzle can generate a name longer than 63 characters and Postgres will truncate it.

On the next migration drizzle will drop this truncated constraint and create a new one. This is not good.

Example of drizzle generate output in my case:

ALTER TABLE "component_dependencies" DROP CONSTRAINT "component_dependencies_component_version_id_component_versions_";

DO $$ BEGIN
 ALTER TABLE "component_dependencies" ADD CONSTRAINT "component_dependencies_component_version_id_component_versions_id_fk" FOREIGN KEY ("component_version_id") REFERENCES "public"."component_versions"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
 WHEN duplicate_object THEN null;
END $$;