Skip to content

[legacy-framework] Prevent blitz db migrate from attempting to create new migration files in production#683

Merged
flybayer merged 3 commits intoblitz-js:canaryfrom
toshi1127:prevent-to-create-new-migration-files
Jun 16, 2020
Merged

[legacy-framework] Prevent blitz db migrate from attempting to create new migration files in production#683
flybayer merged 3 commits intoblitz-js:canaryfrom
toshi1127:prevent-to-create-new-migration-files

Conversation

@toshi1127
Copy link
Collaborator

@toshi1127 toshi1127 commented Jun 14, 2020

This PR closes the issue of Prevent blitz db migrate from attempting to create new migration files in production. #670

What are the changes and their implications?

  • Prevent blitz db migrate from attempting to create new migration files in production.
  • Added test code for Db command.

Checklist

  • Tests added for changes
  • PR submitted to blitzjs.com for any user facing changes

@toshi1127 toshi1127 requested a review from aem as a code owner June 14, 2020 18:13
Copy link
Member

@flybayer flybayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@toshi1127 thank you so much for this!!

Looks good except for the flipped if/else :)

Comment on lines +56 to +69
if (process.env.NODE_ENV === 'production') {
const cp = spawn(prismaBin, ['migrate', 'save', schemaArg, '--create-db', '--experimental'], {
stdio: 'inherit',
})
cp.on('exit', (code) => {
if (code === 0) {
runMigrateUp(prismaBin, resolve)
} else {
process.exit(1)
}
})
} else {
runMigrateUp(prismaBin, resolve)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is backward. In production only up should run. Otherwise both save and up should run.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@toshi1127 toshi1127 changed the title Fixed to create new migration files only in the production environment Prevent blitz db migrate from attempting to create new migration files in production Jun 15, 2020
@toshi1127
Copy link
Collaborator Author

@flybayer
Thanks for the review !!

I thought it might be a good idea to edit the issue to avoid confusion later on.

For safety, migrate save should only run if NODE_ENV === 'production'. 
migrate up will create new migration files

@flybayer
Copy link
Member

Woohoo! Thanks :)

@all-contributors add @toshi1127 for code

@allcontributors
Copy link

@flybayer

I've put up a pull request to add @toshi1127! 🎉

@flybayer flybayer merged commit f82e905 into blitz-js:canary Jun 16, 2020
@itsdillon itsdillon changed the title Prevent blitz db migrate from attempting to create new migration files in production [legacy-framework] Prevent blitz db migrate from attempting to create new migration files in production Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants