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.

[migrate] Custom index with pg_trgm gets removed immediately and causes drift

See original GitHub issue

Problem

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:

  1. Prisma-migrate detects a drift and empties my database content (Drift detected: Your database schema is not in sync with your migration history.)
  2. 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:

Screenshot 2021-06-07 at 16 47 09

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
manVcommented, Jul 5, 2022

To anyone who is having same issue, this worked for me

@@index([columnName(ops: raw("gin_trgm_ops"))], type: Gin)

and manually adding CREATE EXTENSION statement in the migration file before index creation.

0reactions
janpiocommented, Nov 17, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

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