question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prisma Migrate prevents using special index functionality of CockroachDB.

See original GitHub issue

Problem

We’d like to create an index that uses the STORING clause, available in CockroachDB. Something like this:

CREATE INDEX "Reservation_foo_bar_idx" ON "Reservation"("foo", "bar") STORING ("col1", "col2", "col3", "col4");

We can add an index like this in schema.prisma:

@@index([roomId, endDate])

and then edit the generated migration file to add the STORING clause. But the next time the migrate dev is run, the system will delete the old migration and replace it with one where the STORING clause is not there.

Suggested solution

Extend index configuration to allow a storing field for CRDB, or adjust Prisma Migrate to not delete the index when the introspection doesn’t exactly match on clauses that wouldn’t be recognized by Prisma Migrate anyway.

Alternatives

~Right now, what we’re doing is this:~

// @@index([roomId, endDate])

UPDATE this workaround doesn’t work either, Prisma Migrate will delete it.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
AndrewSouthpawcommented, Sep 29, 2022

What happens if you do not include the @@index([roomId, endDate]) in your schema - does Migrate still drop it on the next generated Migration @AndrewSouthpaw?

Migrate still drops it at the next generated migration, yeah.

Is it limited to a simple list of “included” columns

AFAICT from the docs and the railroad diagram, that’s correct.

Cursor_and_CREATE_INDEX___CockroachDB_Docs
0reactions
janpiocommented, Nov 17, 2022

I am closing this here then, as I think #8584 asks for exactly this functionality. What you describe of it dropping it and replacing it with a normal index unless you modify the migration file is expected until that is implemented or we change the behavior otherwise.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Indexes - Prisma
GIN and BTree are the only index types supported by CockroachDB. The operator classes marked to work with CockroachDB are the only ones...
Read more >
Using Prisma with CockroachDB
This guide discusses the concepts behind using Prisma and CockroachDB, explains the commonalities and differences between CockroachDB and other database ...
Read more >
Adding Prisma Migrate to an existing project
Prisma Migrate will create a new migration directory with a SQL migration file in it: ... To include unsupported database features that already...
Read more >
Prisma support for CockroachDB is now in Preview
Prisma Migrate is not supported yet with CockroachDB; if you're starting without an existing database, you will need to define the schema with...
Read more >
Customize a migration file - Prisma
Make a schema change that requires custom SQL (for example, to preserve existing data) · Create a draft migration using: $npx prisma migrate...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found