Migrate: Trying to rename a truncated index name

Created on 7 Aug 2020  ·  6Comments  ·  Source: prisma/migrate

Bug description

Since we have no ability to name the index, it can happen that the name is more than what PostgreSQL accepts (63 bytes). In this case the name is automatically truncated, but on further migrations the engine is trying to rename the index to the full name.

How to reproduce

  1. Create an index that has more than 63 bytes of name length
  2. Apply the migrations
  3. Modify something in the schema
  4. Create a new migrations
  5. You now have a rename step for the index name

Expected behavior

  1. Don't try to rename the index name
  2. Allow us to name the index

Environment & setup

  • Database: PostgreSQL
  • Prisma version: 2.3.0
enginemigration engine tecengines

All 6 comments

Good point! I was going to do a writeup about constraint names and how they should be reflected (or not) in the prisma schema — this is definitely going to be part of it. We should fix this.

The constraint names proposal is still being evaluated, I'll work on a stop-gap fix for this issue.

So I had a look at our test suite, and we already migrate index names if you provide a name for the index in the prisma schema: @@index([field1, field2], name: "myIndexName") should create an index named myIndexName. The other part of the issue is validating index name size limits in the prisma schema. There is the issue to track that work: https://github.com/prisma/prisma-engines/issues/962

To avoid this exact situation, where no index name is provided, I'm going to implement comparison on the first 63 bytes for diffing purposes.

Neat I didn't know you could give it a name already. I don't think it is in the doc?

It's probably not in the docs because it's not relevant outside of migrate, and I don't think introspect populates it, and migrate is still experimental. I'll raise the issue.

Was this page helpful?
0 / 5 - 0 ratings