drizzle-orm
drizzle-orm copied to clipboard
[FEATURE]: Allow specifying constraint names
Describe want to want
Computed constraint names can sometimes get too long for Postgres, resulting in this warning:
psql:migrations/0000_brown_rage.sql:110: NOTICE: identifier "super_duper_duper_long_name" will be truncated to "super_duper_du"
It would be great if one could specify the constraint name in foreignKey
:
foreignKey('table_other_table_fk', {
columns: [table.id],
foreignColumns: [otherTable.id],
})
Or
pgTable('table', {
id: uuid('id').notNull().references('table_other_table_fk', () => otherTable.id),
})
NOTE: This probably applies to constraints in general, not just foreign key constraints.
Make sense. We are working on adding constraints as separate entity, so you can specify any constraint you want. Will think on names for it Thanks!
Sounds good! Thank you!
@AndriiSherman do you have any ETA on this ? PG may generate a warning, but it completely breaks on MySQL.
Just a note that this feature would be good from the perspective of incremental migration.
Currently, drizzle-kit introspect:mysql
get the current constraint names correctly, but the first drizzle-kit generate:mysql
removes and re-adds the FK constraint names as they are incorrectly named.
Any update on this ?
I'm finally got to this feature. Should be shipped soon
@AndriiSherman Hey whats the status on this? Its causing some issues for us migrating to Drizzle.
This is also a blocker for us.
The initial schema migration works despite the truncation warnings for postgres, but because drizzle-kit seems to be unaware of the truncation, subsequent migrations end up failing, rendering drizzle-kit unusable.
Anyone aware of a workaround?
@AndriiSherman I'm not sure about what is more important than support a basic feature for one of the most popular sql engine, but this is clearly overdue. I get your business but understand that because of this issue I cannot recommend drizzle to anyone building something serious. This is not a "nice to have", it's not even an "enhancement" (despite the tag). It's a critical bug fix for MySQL and a major one for Postgres. And it's 6 months old.
EDIT : I understand this is FOSS, but we both know you are building a business behind it ; my tone is more a wake up call than an angry comment ;)
This has been implemented in v0.29
It seems that this has been just partially fixed, as of now drizzle-kit introspect
won't get names for single-column foreign keys translated in code using the references()
method, this causes drizzle-kit generate
defining fancy and sometimes long names for those constraints leading again to this issue. The only workaround I found is to remove foreign key definitions manually on column definitions and add them as composites with the foreignKey
operator which is impractical for large databases. It would be nice if the references()
method also includes a name
param like references(name, ref, action?)
.
It seems like this isn't supported in the references()
method as stated above. Is it possible for it to support this as this is a major blocker for us when migrating to drizzle.