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

need to run db push twice in order to apply changes #7411

Closed
steebchen opened this issue Jun 2, 2021 · 2 comments · Fixed by #8540
Closed

need to run db push twice in order to apply changes #7411

steebchen opened this issue Jun 2, 2021 · 2 comments · Fixed by #8540
Assignees
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/schema Issue for team Schema. tech/typescript Issue for tech TypeScript. topic: prisma db push CLI: prisma db push
Milestone

Comments

@steebchen
Copy link
Contributor

steebchen commented Jun 2, 2021

Bug description

It happened many times to me already that I run db push, it says “:warning: We found changes that cannot be executed:” and “The PostgreSQL database “db” from “localhost:5340" was successfully reset.“, then I type y, and it says “Your database is now in sync with your schema.“.
However nothing changed. The changes are not applied.
Then I run db push again, it says once again “Your database is now in sync with your schema”, but now it actually is in sync, and some tables are correctly dropped.

How to reproduce

  • set up prisma project
  • run db push
  • introduce breaking change
  • run db push, should migrate successfully judging by the message but no changes applied in db
  • run db push again, shows success again but this time it actually applied the changes in the db

Expected behavior

changes to be applied immediately after running db push

Prisma information

datasource db {
        provider = "postgresql"
        url      = "postgresql://postgres:pw@localhost:5340/db"
}

generator db {
        provider = "prisma-client-js"
}

model User {
        id       String  @id @default(cuid())
        email    String
        name     String?
}

Environment & setup

  • OS:
  • Database: PG
  • Node.js version:

Prisma Version

❯ go run github.com/prisma/prisma-client-go ver
sion 
Environment variables loaded from .env
prisma               : 2.23.0
@prisma/client       : Not found
Current platform     : darwin
Query Engine         : query-engine adf5e8cba3daf12d456d911d72b6e9418681b28b (at ../../../Library/Caches/prisma/binaries/cli/2.23.0/adf5e8cba3daf12d456d911d72b6e9418681b28b/prisma-query-engine-darwin, resolved by PRISMA_QUERY_ENGINE_BINARY)
Migration Engine     : migration-engine-cli adf5e8cba3daf12d456d911d72b6e9418681b28b (at ../../../Library/Caches/prisma/binaries/cli/2.23.0/adf5e8cba3daf12d456d911d72b6e9418681b28b/prisma-migration-engine-darwin, resolved by PRISMA_MIGRATION_ENGINE_BINARY)
Introspection Engine : introspection-core adf5e8cba3daf12d456d911d72b6e9418681b28b (at ../../../Library/Caches/prisma/binaries/cli/2.23.0/adf5e8cba3daf12d456d911d72b6e9418681b28b/prisma-introspection-engine-darwin, resolved by PRISMA_INTROSPECTION_ENGINE_BINARY)
Format Binary        : prisma-fmt adf5e8cba3daf12d456d911d72b6e9418681b28b (at ../../../Library/Caches/prisma/binaries/cli/2.23.0/adf5e8cba3daf12d456d911d72b6e9418681b28b/prisma-prisma-fmt-darwin, resolved by PRISMA_FMT_BINARY)
Default Engines Hash : adf5e8cba3daf12d456d911d72b6e9418681b28b
Studio               : 0.393.0
@steebchen steebchen added the kind/bug A reported bug. label Jun 2, 2021
@Jolg42 Jolg42 added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. process/candidate team/schema Issue for team Schema. topic: prisma db push CLI: prisma db push labels Jun 2, 2021
@pantharshit00
Copy link
Contributor

pantharshit00 commented Jun 15, 2021

I can reproduce this. Looks like it clears the tables but doesn't recreate them in the first run.

Exact reproduction steps.

  1. Start with the following datamodel and create database using db push:
model User {
        id       String  @id @default(cuid())
        email    String
        name     String?
}
  1. Use npx prisma studio to create some records withname as null
  2. Change the datamodel to following:
model User {
        id       String  @id @default(cuid())
        email    String
        name     String
}
  1. Run npx prisma db push. It will say drift detected and ask you to reset the database. Agree to the prompt and proceed with the migration.
  2. Check the database, there should be no tables recreated.

@pantharshit00 pantharshit00 added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Jun 15, 2021
@tomhoule
Copy link
Contributor

Just for context, this happens because the CLI reapplies migrations after you reset, instead of db push-ing.

@tomhoule tomhoule self-assigned this Jun 17, 2021
@tomhoule tomhoule added this to the 2.26.0 milestone Jun 17, 2021
@tomhoule tomhoule added the tech/typescript Issue for tech TypeScript. label Jun 29, 2021
@tomhoule tomhoule modified the milestones: 2.26.0, 2.27.0 Jul 1, 2021
@tomhoule tomhoule removed this from the 2.27.0 milestone Jul 15, 2021
@tomhoule tomhoule removed their assignment Jul 15, 2021
@thebiglabasky thebiglabasky added this to the 2.29.0 milestone Jul 28, 2021
Andrew-Colman pushed a commit to Andrew-Colman/prisma that referenced this issue Aug 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/schema Issue for team Schema. tech/typescript Issue for tech TypeScript. topic: prisma db push CLI: prisma db push
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants