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

migrate dev can not be used to fix "invalid" migrations over time #8064

Open
janpio opened this issue Jul 4, 2021 · 2 comments
Open

migrate dev can not be used to fix "invalid" migrations over time #8064

janpio opened this issue Jul 4, 2021 · 2 comments
Labels
kind/improvement An improvement to existing feature and code. team/schema Issue for team Schema. topic: prisma migrate dev --create-only CLI: prisma migrate dev --create-only topic: prisma migrate dev CLI: prisma migrate dev

Comments

@janpio
Copy link
Member

janpio commented Jul 4, 2021

#5782 means that in 2.26.0 with referentialActions enable we still by default create invalid migrations for SQL Server. When applying it, you get an error message that let's you (potentially) understand what you need to do - add a onUpdate: Cascade to a @relation in your schema.

Unfortunately you can not use migrate dev to iterate on that, as when you do the change and run migrate dev --create-only again, it fails with a shadow database error as the first migration can not be applied to the shadow database :(

C:\Users\Jan\Documents\throwaway\sqlServerCycles>npx prisma migrate deploy
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db" - SQL Server

1 migration found in prisma/migrations
Error: P3018

A migration failed to apply. New migrations can not be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve

Migration name: 20210704123327_init

Database error code: 1785

Database error:
Introducing FOREIGN KEY constraint 'FK__Comment__postId' on table 'Comment' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.


### edit the schema here


C:\Users\Jan\Documents\throwaway\sqlServerCycles>npx prisma migrate dev --create-only
Environment variables loaded from .env
Prisma schema loaded from prisma\schema.prisma
Datasource "db" - SQL Server

Error: P3006

Migration `20210704123327_init` failed to apply cleanly to the shadow database. 
Error:
Database error
Error querying the database: 'Introducing FOREIGN KEY constraint 'FK__Comment__postId' on table 'Comment' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.' on server EC2AMAZ-HEFESC9 executing  
on line 57 (code: 1785, state: 0, class: 16)
   0: sql_migration_connector::validate_migrations
             at migration-engine\connectors\sql-migration-connector\src\lib.rs:322
   1: migration_core::api::DevDiagnostic
             at migration-engine\core\src\api.rs:89

Instead I have to delete the old migration, and create a new one that does everything in 1 step.

@janpio janpio added topic: prisma migrate dev CLI: prisma migrate dev topic: prisma migrate dev --create-only CLI: prisma migrate dev --create-only labels Jul 4, 2021
@tomhoule
Copy link
Contributor

tomhoule commented Jul 5, 2021

Instead I have to delete the old migration, and create a new one that does everything in 1 step.

I think that's pretty much the intended workflow — that or edit the existing migration.

@tomhoule tomhoule added kind/feedback Issue for gathering feedback. team/schema Issue for team Schema. labels Jul 5, 2021
@janpio
Copy link
Member Author

janpio commented Jul 11, 2021

Might this be a "hole" in the feature set to make handling errors, which can just happen, easier?

In the example above, the next step would be to change the schema and then create another migration. In other cases, it might be setting a datasource property (plantScaleMode/noForeignKeys) or something similar to that. The current instructions are not super helpful in this case and basically are "deal with it manually, good luck".

@janpio janpio added kind/improvement An improvement to existing feature and code. and removed kind/feedback Issue for gathering feedback. labels May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/improvement An improvement to existing feature and code. team/schema Issue for team Schema. topic: prisma migrate dev --create-only CLI: prisma migrate dev --create-only topic: prisma migrate dev CLI: prisma migrate dev
Projects
None yet
Development

No branches or pull requests

2 participants