drizzle-orm icon indicating copy to clipboard operation
drizzle-orm copied to clipboard

[FEATURE]: Allow specifying constraint names

Open migueloller opened this issue 1 year ago • 5 comments

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.

migueloller avatar Apr 16 '23 16:04 migueloller

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!

AndriiSherman avatar Apr 16 '23 17:04 AndriiSherman

Sounds good! Thank you!

migueloller avatar Apr 16 '23 17:04 migueloller

@AndriiSherman do you have any ETA on this ? PG may generate a warning, but it completely breaks on MySQL.

JesusTheHun avatar May 04 '23 17:05 JesusTheHun

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.

danielsharvey avatar May 28 '23 07:05 danielsharvey

Any update on this ?

JesusTheHun avatar Jun 15 '23 12:06 JesusTheHun

I'm finally got to this feature. Should be shipped soon

AndriiSherman avatar Jul 23 '23 19:07 AndriiSherman

@AndriiSherman Hey whats the status on this? Its causing some issues for us migrating to Drizzle.

anotherliam avatar Sep 14 '23 04:09 anotherliam

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?

lewisl9029 avatar Oct 16 '23 05:10 lewisl9029

@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 ;)

JesusTheHun avatar Oct 17 '23 14:10 JesusTheHun

This has been implemented in v0.29

Angelelz avatar Nov 14 '23 04:11 Angelelz

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?).

arcadio-nseng avatar Feb 14 '24 14:02 arcadio-nseng

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.

SamKingDev avatar Apr 10 '24 13:04 SamKingDev