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

CLI: migrate status should return a non-successful exit code (1) when a failed migration is found or an error occurs #14860

Closed
Jolg42 opened this issue Aug 17, 2022 · 4 comments · Fixed by #14866
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: cli topic: exit code topic: prisma migrate status CLI: prisma migrate status
Milestone

Comments

@Jolg42
Copy link
Member

Jolg42 commented Aug 17, 2022

Bug description

From #12349

migrate status returns a successful exit code (0) in unexpected situations like
when a failed migration is found
P1000: Authentication failed against database server at localhost

How to reproduce

  • when a failed migration is found
npx prisma migrate --create-only
# edit the .sql file and add "BROKEN"
npx prisma migrate deploy
npx prisma migrate status
  • P1000: Authentication failed against database server at localhost
# edit .env and change the username or password to an incorrect one
npx prisma migrate status

Expected behavior

It should return a non-successful exit code -> 1

Prisma Version

4.3.0-dev.27
@Jolg42 Jolg42 added bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. topic: cli tech/typescript Issue for tech TypeScript. team/schema Issue for team Schema. topic: prisma migrate status CLI: prisma migrate status topic: exit code labels Aug 17, 2022
Jolg42 added a commit that referenced this issue Aug 17, 2022
@Jolg42 Jolg42 added this to the 4.3.0 milestone Aug 19, 2022
Jolg42 added a commit that referenced this issue Aug 23, 2022
…4866)

* fix(migrate status): return exit code 1 when error or not in sync

It will now exit(1) = error in these cases

    if database connection error
    If databaseIsBehind (= unapplied migrations)
    If historiesDiverge (= migration history diverged)
    If we can't find a migration table (= not managed by Prisma)
    If failed migration(s) are found

Closes #14860

* process.exit(1) for baseline case too

* cleanup

* fix ts error
@Jolg42
Copy link
Member Author

Jolg42 commented Aug 24, 2022

It will now exit(1) = error in these cases

if database connection error
If databaseIsBehind (= unapplied migrations)
If historiesDiverge (= migration history diverged)
If we can't find a migration table (= not managed by Prisma)
If failed migration(s) are found

@Jolg42
Copy link
Member Author

Jolg42 commented Aug 24, 2022

It's now in our internal dev version 4.3.0-dev.56 and up, and will be part of the 4.3.0 release.

@jacobchrismarsh
Copy link

Replying to this comment from the linked PR

If databaseIsBehind = unapplied migrations -> exit(1)

The other instances of errors make sense, but does this one? I'm not sure that unapplied migrations are error-worthy.

I only bring this up because my team used prisma migrate status as a part of our build process to list all unapplied migrations and then apply them. This change broke our pipeline by introducing a new error.

@janpio
Copy link
Member

janpio commented Nov 2, 2022

Turned this comment into a new issue @jacobchrismarsh so we are sure to follow up properly: #16105

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: cli topic: exit code topic: prisma migrate status CLI: prisma migrate status
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants