Migrating from Prisma gradually

We're in the middle of migrating away from Prisma to Drizzle which we just found out that Drizzle has its own naming convention for FOREIGN KEY CONSTRAINT. To avoid surprises for this migration, we'd like to keep Prisma constraint names, I looked into the reference() type definitions, it seems that we don't have a way to customise the FOREIGN KEY CONSTRAINT name, is that correct? At the same time, the current generated constraint name is longer than Postgres's allowed length. How can we workaround this?
11 Replies
Andrii Sherman
Yeah, known problem We will definitely add custom names for any constraint we have Will try to prioritize it I’ll think on the best workaround for now and will ping you here We will discuss it internally today and maybe I’ll include this fix in next release
Cayter
CayterOP2y ago
thx!
rphlmr ⚡
rphlmr ⚡2y ago
If the constraint name is too long (the one auto-generated), it will be reduced but I don't know how, Postgres is still capable to find it with the full name.
Cayter
CayterOP2y ago
@_@
rphlmr ⚡
rphlmr ⚡2y ago
this week i was updating some schema constraints and i discovered that the name I had in my sql migration didn't match what i had in db. But no issue on droping it by its full name 🤷‍♂️
Cayter
CayterOP2y ago
we just bumped into that on local @_@
rphlmr ⚡
rphlmr ⚡2y ago
ALTER TABLE "pub_private_discussion_message" DROP CONSTRAINT "pub_private_discussion_message_discussion_id_pub_private_discussion_id_fk";
DO $$ BEGIN
ALTER TABLE "pub_private_discussion_message" ADD CONSTRAINT "pub_private_discussion_message_discussion_id_pub_private_discussion_id_fk" FOREIGN KEY ("discussion_id") REFERENCES "pub_private_discussion"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
ALTER TABLE "pub_private_discussion_message" DROP CONSTRAINT "pub_private_discussion_message_discussion_id_pub_private_discussion_id_fk";
DO $$ BEGIN
ALTER TABLE "pub_private_discussion_message" ADD CONSTRAINT "pub_private_discussion_message_discussion_id_pub_private_discussion_id_fk" FOREIGN KEY ("discussion_id") REFERENCES "pub_private_discussion"("id") ON DELETE cascade ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
this worked 😂 me and my far-too-long table names 😅 i guess you can manually edit your sql migration before deploying but you’ll have to remember that if you edit a constraint later 🥶
Cayter
CayterOP2y ago
i guess you can manually edit your sql migration before deploying but you’ll have to remember that if you edit a constraint later
this is what we wanna avoid, luckily andrew said it's something they can squeeze in
rphlmr ⚡
rphlmr ⚡2y ago
yeah he rocks 😎
Andrii Sherman
@Cayter small update. Preparing kit release with ~15 github issues fixed After that will work on custom names for constraints
Cayter
CayterOP2y ago
Thx man!!!
Want results from more Discord servers?
Add your server