Identifier is too long (should not exceed 63 characters)

Hello guys. I've got too long constraint id generated by drizzle kit in migration files. Is it safe to apply such migration? Maybe there is a way how I can set custom constraint id for some tables? Here is my schema
export const customerVehicleClaims = pgTable('customer_vehicle_claims', {
claimsid: text('claimsid').primaryKey().notNull(),
customervehicleid: integer('customervehicleid')
.notNull()
.references(() => customervehicle.customervehicleid),
createdAt: timestamp('created_at', { mode: 'string' }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { mode: 'string' }),
customerid: integer('customerid')
.notNull()
.references(() => customer.customerid),
vehicleid: integer('vehicleid')
.notNull()
.references(() => vehicle.vehicleid),
});
export const customerVehicleClaims = pgTable('customer_vehicle_claims', {
claimsid: text('claimsid').primaryKey().notNull(),
customervehicleid: integer('customervehicleid')
.notNull()
.references(() => customervehicle.customervehicleid),
createdAt: timestamp('created_at', { mode: 'string' }).defaultNow().notNull(),
updatedAt: timestamp('updated_at', { mode: 'string' }),
customerid: integer('customerid')
.notNull()
.references(() => customer.customerid),
vehicleid: integer('vehicleid')
.notNull()
.references(() => vehicle.vehicleid),
});
Here is the generated sql
DO
$$
BEGIN
ALTER TABLE "customer_vehicle_claims"
ADD CONSTRAINT "customer_vehicle_claims_customervehicleid_customervehicle_customervehicleid_fk" FOREIGN KEY ("customervehicleid") REFERENCES "customervehicle" ("customervehicleid") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END
$$;
--> statement-breakpoint
DO
$$
BEGIN
ALTER TABLE "customer_vehicle_claims"
ADD CONSTRAINT "customer_vehicle_claims_customervehicleid_customervehicle_customervehicleid_fk" FOREIGN KEY ("customervehicleid") REFERENCES "customervehicle" ("customervehicleid") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END
$$;
--> statement-breakpoint
7 Replies
Alex.dev
Alex.devOP2y ago
Forgot to mention I'm using RDS Aurora for postgres @Dan Kochetov can you help, please?
Dan
Dan2y ago
passing to @Andrew Sherman
Alex.dev
Alex.devOP17mo ago
@Andrew Sherman, please, help)
Andrii Sherman
Andrii Sherman17mo ago
you found me it won't work now if you are using drizzle-kit for migration management. We will add a new API in drizzle-orm to provide custom names for fk and pk. After that evertyhing will work as expected I'll try to make a high priority for this task I know it's blocking some other devs already
Jona Anders
Jona Anders17mo ago
For now, you can just go into a migration file and replace or remove the parts. I know, this isn't pretty, but it does work. Just note that for every migration drizzle kit will try to rename it, so you have to delete the ALTER queries. Maybe just create a file or a note that includes the names of the keys so you can search and replace quickly. Or, if you have to much time to automate a task that you could do in a few seconds manually, write a short script that does it automatically
Alex.dev
Alex.devOP17mo ago
thank you guys so much for help!
Want results from more Discord servers?
Add your server