[migrate] Custom index with pg_trgm gets removed immediately and causes drift
See original GitHub issueProblem
I am creating a migration script with npx prisma migrate dev --create-only
:
My migration.sql
file:
CREATE EXTENSION IF NOT EXISTS pg_trgm;
DROP INDEX IF EXISTS index_on_profile_name_trigram;
CREATE INDEX index_on_profile_name_trigram ON "Profile" using gin (name gin_trgm_ops);
Then I am running npx prisma migrate dev
.
Two outcomes:
- Prisma-migrate detects a drift and empties my database content (
Drift detected: Your database schema is not in sync with your migration history.
) - Prisma-migrate creates a second migration file that removes the index again.
Auto-generated migration.sql
:
-- DropIndex
DROP INDEX "index_on_profile_name_trigram";
Suggested solution
Both “outcomes” described above should not happen. Instead prisma-migrate should only apply my migration script.
Alternatives
- Deleting the automatically generated
migration.sql
file everytime I add a new migration - Also it will detect a drift everytime, and require me to import my database content again This is very inconvenient.
Additional context
I have asked around in the slack channel and got asked to create this PR:
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Migrate renames my indexes & throws Drift detected error ...
So the migration sequence is something like this. Migration 1: Full SQL dump of my existing schema created manually. Migration 2: Auto created ......
Read more >Cannot run migrations when postgres extension added in ...
Since Postgres already don't have pg_trgm I need to execute a command to install it. So my migration to do so is
Read more >Migrations - Drift - Simon Binder
To delete a column referenced by a foreign key, you'd have to migrate the referencing tables first. Renaming columns. If you're renaming a...
Read more >Documentation: 15: F.35. pg_trgm
The pg_trgm module provides functions and operators for determining the similarity of alphanumeric text based on trigram matching, as well as index operator ......
Read more >Manage Red Hat Quay
Editing the config.yaml file directly is possible, but it is only ... You can customize your Red Hat Quay database connection settings within...
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
To anyone who is having same issue, this worked for me
and manually adding
CREATE EXTENSION
statement in the migration file before index creation.Quick question: What happens if you
db pull
when this index is already present, either with the schema you already have or a new, empty one? Would be interesting to know if this index is picked up, and if so how.