cli icon indicating copy to clipboard operation
cli copied to clipboard

Pending migration alert during app startup

Open svkrclg opened this issue 2 years ago • 6 comments

Issue Creation Checklist

  • [x] I understand that my issue will be automatically closed if I don't fill in the requested information
  • [x] I have read the contribution guidelines

Feature Description

Pending migration (if any) alert during app startup.

Describe the feature you'd like to see implemented

I checked sequelize docs but didn't find any way of getting notified if there is pending migration left. This could be useful in many ways when there are multiple devs working on the project. During app startup, upon initialization of sequelize we should check for current migrations in DB and existing migrations in the migrations folder, and upon any mismatch we throw a non-zero exit and stop the application with a message. All this can be configurable IMO.

Describe why you would like this feature to be added to Sequelize

We can have an external npm package for this, but make sense to have it here. Also, this feature is available in Ruby on Rails ActiveRecord gem.

Is this feature dialect-specific?

  • [x] No. This feature is relevant to Sequelize as a whole.
  • [ ] Yes. This feature only applies to the following dialect(s):

Would you be willing to resolve this issue by submitting a Pull Request?

  • [ ] Yes, I have the time and I know how to start.
  • [x] Yes, I have the time but I will need guidance.
  • [ ] No, I don't have the time, but my company or I are supporting Sequelize through donations on OpenCollective.
  • [ ] No, I don't have the time, and I understand that I will need to wait until someone from the community or maintainers is interested in implementing my feature.

Indicate your interest in the addition of this feature by adding the 👍 reaction. Comments such as "+1" will be removed.

svkrclg avatar Jun 27 '23 10:06 svkrclg

Moved to the CLI repo because the core library is not aware of the migrations (it is entirely a cli concern). We could definitely add a cli subcommand that checks this, that you could use in your start command

ephys avatar Jun 27 '23 10:06 ephys

This is strongly related to the --dry-run flag: https://github.com/sequelize/cli/issues/219

ephys avatar Jun 27 '23 17:06 ephys

No, IMO. I'm talking about a logic that will terminate the app during bootup when there is a pending migration.

svkrclg avatar Jun 29 '23 06:06 svkrclg

This is something you'll need to run before you boot your app and decide whether the app may boot based on the exit status of the cli. The core library, which you use in your app, has no knowledge of migrations. This is because you can use any migration tool, you're not limited to the sequelize cli.

Alternatively you can use child_process.exec to run the relevant cli command from inside your app.

Depending on how --dry-run is designed, it could cover both use cases. I did say "strongly related", not "the same as", we could also decide to go for a --check-no-pending-migrations flag or similar.

ephys avatar Jun 29 '23 06:06 ephys

Thanks for explanation and it make sense now. Should I start working on this feature?

svkrclg avatar Jul 08 '23 05:07 svkrclg

We're actually planning on rewriting the CLI from scratch, so it's unlikely that we'll do much on this repository anymore

ephys avatar Jul 21 '23 13:07 ephys