cannot set alias for composite primary key, getting (errno 1059) (sqlstate 42000) errors

My table has the following schema ->
export const emergencyContactPhoneNumber = mysqlTable(
"emergency_contact_phone_number",
{
emergencyContactId: ulid("emergency_contact_id").notNull(),
phoneNumberId: ulid("phone_number_id").notNull(),
description: varchar("description", { length: 10 }).notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
},
(table) => ({
primaryKey: primaryKey(table.emergencyContactId, table.phoneNumberId),
}),
);
export const emergencyContactPhoneNumber = mysqlTable(
"emergency_contact_phone_number",
{
emergencyContactId: ulid("emergency_contact_id").notNull(),
phoneNumberId: ulid("phone_number_id").notNull(),
description: varchar("description", { length: 10 }).notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
},
(table) => ({
primaryKey: primaryKey(table.emergencyContactId, table.phoneNumberId),
}),
);
when migrating to planetscale i get the following error ->
DatabaseError: target: mycompany.-.primary: vttablet: rpc error: code = InvalidArgument desc = Identifier name 'emergency_contact_phone_number_emergency_contact_id_phone_number_id' is too long
DatabaseError: target: mycompany.-.primary: vttablet: rpc error: code = InvalidArgument desc = Identifier name 'emergency_contact_phone_number_emergency_contact_id_phone_number_id' is too long
the generated sql produces this monster index for the composite primary key
CREATE TABLE `emergency_contact_phone_number` (
`emergency_contact_id` char(26) NOT NULL,
`phone_number_id` char(26) NOT NULL,
`description` varchar(10) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT (now()),
CONSTRAINT `emergency_contact_phone_number_emergency_contact_id_phone_number_id` PRIMARY KEY(`emergency_contact_id`,`phone_number_id`)
);
CREATE TABLE `emergency_contact_phone_number` (
`emergency_contact_id` char(26) NOT NULL,
`phone_number_id` char(26) NOT NULL,
`description` varchar(10) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT (now()),
CONSTRAINT `emergency_contact_phone_number_emergency_contact_id_phone_number_id` PRIMARY KEY(`emergency_contact_id`,`phone_number_id`)
);
how the heck can i set an alias for a composite primary key?
9 Replies
BinaryArtifex
BinaryArtifex•15mo ago
@Andrew Sherman sorry to buzz ya mate, don't seem to be getting a bite on my question, hopin you could maybe point me in the right direction? i don't particularly want to compress my table or column names as ive got a consistent set of conventions id really prefer to stick to....
Andrii Sherman
Andrii Sherman•15mo ago
Hey, sorry for a late response. This issue will be fixed right after we will introduce custom names for primaryKey and foreignKey constraints are you using push or generate?
BinaryArtifex
BinaryArtifex•15mo ago
@Andrew Sherman been away for a minute sorry for late reply, yeah im pushing incremental migrations to planetscale through the greenfields phase till i settle on a version 1 database schema for production, so before that its the wild west atm cant see a mention of custom names for primary keys in the releases page just yet, will this feature be far away?
Andrii Sherman
Andrii Sherman•15mo ago
no, I will work on it next(I'm finishing some batch api feature for orm) and then will work on drizzle-kit names for pk/fk
Aidan Laycock
Aidan Laycock•14mo ago
Hey @a_sherman - Has this functionality been released? As I'm currently hitting the same issue as above, and I can't find anything in the docs about it 🙂
Andrii Sherman
Andrii Sherman•13mo ago
GitHub
Unsigned Ints; Custom names for PrimaryKeys and ForeignKeys by Andr...
Added unsigned option for all ints in MySQL column: int('column_name', { unsigned: true }) Add custom names for primary keys and foreign keys for all dialects const table = sqliteTable('...
Andrii Sherman
Andrii Sherman•13mo ago
it's waiting it's turn for a next 0.29.0 release working on a kit side for that
Aidan Laycock
Aidan Laycock•13mo ago
That's amazing thank you! Do you roughly when that should be released?
BinaryArtifex
BinaryArtifex•13mo ago
@Andrew Sherman at the risk of stretchin the friendship i don't spose a cheeky little Check constraint feature is gonna creep into 0.29.0? cause that'd just be swell.
Want results from more Discord servers?
Add your server