drizzle-kit: generated constraint names exceed NAMEDATLEN (63 characters) in PostgreSQL

Hi Drizzle Team! We're running into an issue where the generated constraint names exceed postgres' constraint name max length defined by NAMEDATLEN. This is defined at compile time and thus cannot be changed in many instances since 63 is the default value. I've gotten around the issue for now by manually defining foreign keys instead of using the .references property, but I was wondering if there are any methods or plans to address this. Here's an example of some table and column names that cause long foreign keys:
export const membershipSubscriptions = pgTable(
"membership_subscriptions",
withTimestamps({
id: uuid("id").primaryKey(),
// ...
}),
);

export const membershipSubscriptionMembers = pgTable(
"membership_subscription_members",
{
membershipSubscriptionId: uuid("membership_subscription_id")
.references(() => membershipSubscriptions.id)
.notNull(),
memberId: uuid("customer_id")
.references(() => customers.id)
.notNull(),
},
(table) => [
primaryKey({
columns: [table.membershipSubscriptionId, table.memberId],
}),
],
);

export const membershipSubscriptionActivityTypes = pgTable(
"membership_subscription_activity_types",
withTimestamps({
membershipSubscriptionId: uuid("membership_subscription_id")
.references(() => membershipSubscriptions.id)
.notNull(),
activityTypeId: uuid("activity_type_id")
.references(() => activityTypes.id)
.notNull(),
}),
(table) => [
primaryKey({
columns: [table.membershipSubscriptionId, table.activityTypeId],
}),
],
);
export const membershipSubscriptions = pgTable(
"membership_subscriptions",
withTimestamps({
id: uuid("id").primaryKey(),
// ...
}),
);

export const membershipSubscriptionMembers = pgTable(
"membership_subscription_members",
{
membershipSubscriptionId: uuid("membership_subscription_id")
.references(() => membershipSubscriptions.id)
.notNull(),
memberId: uuid("customer_id")
.references(() => customers.id)
.notNull(),
},
(table) => [
primaryKey({
columns: [table.membershipSubscriptionId, table.memberId],
}),
],
);

export const membershipSubscriptionActivityTypes = pgTable(
"membership_subscription_activity_types",
withTimestamps({
membershipSubscriptionId: uuid("membership_subscription_id")
.references(() => membershipSubscriptions.id)
.notNull(),
activityTypeId: uuid("activity_type_id")
.references(() => activityTypes.id)
.notNull(),
}),
(table) => [
primaryKey({
columns: [table.membershipSubscriptionId, table.activityTypeId],
}),
],
);
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?