Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prisma Migrate shows warning when editing rolled-back migration #9829

Closed
Valerionn opened this issue Oct 18, 2021 · 2 comments · Fixed by #12381
Closed

Prisma Migrate shows warning when editing rolled-back migration #9829

Valerionn opened this issue Oct 18, 2021 · 2 comments · Fixed by #12381
Assignees
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/schema Issue for team Schema. topic: dx topic: prisma migrate deploy CLI: prisma migrate deploy
Milestone

Comments

@Valerionn
Copy link

Valerionn commented Oct 18, 2021

Bug description

When a migration failed to apply on a production system, the documentation tells you that one solution for this problem is to mark the migration as rolled-back, then change the migration (e.g. by adding IF NOT EXIST) and then call prisma migrate deploy again.

This leads to two entries in the _prisma_migrations table, one for the original, failed migration with the old checksum which has a rolled_back_at date. The other entry is for the same file, but with the new, edited checksum.

However, whenever you run prisma migrate deploy again, the warning

WARNING The following migrations have been modified since they were applied:
20211018125402_test

is always shown. It is not possible to get rid of this warning (unless you manually delete the rolled-back entry from _prisma_migrations which is something we definitely want to avoid in a production db). The solution in the documentation for this warning is to "restore the old file" which obviously doesn't work since it's broken. Just ignoring the warning is also not a solution because it might be a legitimate problem - if it's not a rolled-back migration.

How to reproduce

  1. Create a migration with npx prisma migrate dev --create-only
  2. Edit the migration in a way that it fails
  3. Run npx prisma migrate deploy
  4. Edit the migration so that it now runs again
  5. Follow the instructions in https://www.prisma.io/docs/guides/database/production-troubleshooting to mark the migration as rolled-back
  6. Run npx prisma migrate deploy again
  7. Observe the "migrations have been changed"-warning

Expected behavior

The "The following migrations have been modified since they were applied" warning should only trigger on entires in the _prisma_migrations table that are not marked as rolled-back.

Prisma information

Environment & setup

  • OS: Windows
  • Database: PostgreSQL
  • Node.js version: v14.15.4

Prisma Version

prisma                  : 3.2.1
@prisma/client          : 3.2.1
Current platform        : windows
Query Engine (Node-API) : libquery-engine b71d8cb16c4ddc7e3e9821f42fd09b0f82d7934c (at node_modules\@prisma\engines\query_engine-windows.dll.node)
Migration Engine        : migration-engine-cli b71d8cb16c4ddc7e3e9821f42fd09b0f82d7934c (at node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine    : introspection-core b71d8cb16c4ddc7e3e9821f42fd09b0f82d7934c (at node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary           : prisma-fmt b71d8cb16c4ddc7e3e9821f42fd09b0f82d7934c (at node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash    : b71d8cb16c4ddc7e3e9821f42fd09b0f82d7934c
Studio                  : 0.435.0

@Valerionn Valerionn added the kind/bug A reported bug. label Oct 18, 2021
@tomhoule tomhoule added kind/feedback Issue for gathering feedback. process/candidate team/schema Issue for team Schema. and removed kind/bug A reported bug. labels Oct 18, 2021
@floelhoeffel floelhoeffel pinned this issue Oct 20, 2021
@floelhoeffel floelhoeffel unpinned this issue Oct 20, 2021
@floelhoeffel floelhoeffel self-assigned this Oct 20, 2021
@janpio janpio added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. topic: prisma migrate deploy CLI: prisma migrate deploy and removed kind/feedback Issue for gathering feedback. labels Jan 3, 2022
@floelhoeffel
Copy link

I see two levels to fix this:

  1. remove the warning for roll-backed migrations (100% makes sense as changing a rolled-back migration is a valid strategy)
  2. remove the warning all together for migrate deploy but leave it in for migrate status. I wonder how useful a warning for already applied migrations is? I assume in most cases files could have been changed due to reformatting or adding a comment while the SQL would stay the same.

@floelhoeffel
Copy link

Lets do 1) and make a decision if we want to do 2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/schema Issue for team Schema. topic: dx topic: prisma migrate deploy CLI: prisma migrate deploy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants