Support indexing a column partially, i.e. indexing a subset of a text field in MySQL
See original GitHub issueProblem
I’m trying out Prisma new native types feature.
generator client {
provider = "prisma-client-js"
previewFeatures = ["nativeTypes"]
}
After I introspect the db, I get the following error.
But actually mediumtext can be used as unique if you specify a length to it.
Suggested solution
Maybe Prisma could support something like the following:
model StatusUpdate {
id String @id @db.Char(30)
uid String @unique(191) @db.MediumText
}
Additional context
Prisma 1 @unique
uses mediumtext unique with 191 length.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top Results From Across the Web
8.3.1 How MySQL Uses Indexes
Indexes are used to find rows with specific column values quickly. Without an index, MySQL must begin with the first row and then...
Read more >Chapter 4. Query Performance Optimization - O'Reilly
MySQL can sometimes use an index to avoid reading row data, when the index contains all the columns the query needs. We discussed...
Read more >Efficient Use of PostgreSQL Indexes | Heroku Dev Center
A partial index covers just a subset of a table's data. It is an index with a WHERE clause. The idea is to...
Read more >mysql - Indexing on a fixed-length string (10 characters
In a table with thousands of phone numbers and the associated user_id, I wish to be able to rapidly query the database and...
Read more >Hibernate Search 6.1.7.Final: Reference Documentation
3, @FullTextField maps a property to a full-text index field with ... i.e. property types that are supported out of the box when ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I ran into this also. Our DB started life with Prisma 1, and so we’ve got several places where P1 created tables with mediumtext columns marked as
@unique
that have an index defined that selects a sub part of that field, so that it can be unique. SeeshortName
column in the sql below, which was exported from our P1 DB:We’ve since switched over to P2, and now we’re trying to start using the native DB types via
introspect
, and then switch over to prisma migrate. But, when I introspect it strips the@unique
from the schema and won’t let me re-add it. I see the same error @chanlito posted above. This is blocking us from being able to upgrade to the latest Prisma version, and from using Prisma Migrate. Any idea if/when the suggested approach might be implemented?We released support for this in https://github.com/prisma/prisma/releases/tag/3.5.0 - please test it out @kgoggin @chanlito and let us know if this works for you - or not. Thanks!