rubenv / sql-migrate

SQL schema migration tool for Go.
MIT License
3.24k stars 280 forks source link

Adds "ignoreunknown" flag to "up" cli command #193

Closed jhuliano closed 3 years ago

jhuliano commented 3 years ago

Thought it could be helpful to add the "ignoreunknown" option as a flag on the CLI. I only added it to the up command, but for consistency, we could also add it to other commands like down.

> sql-migrate up --help
Usage: sql-migrate up [options] ...

  Migrates the database to the most recent version available.

Options:

  -config=dbconfig.yml   Configuration file to use.
  -env="development"     Environment.
  -limit=0               Limit the number of migrations (0 = unlimited).
  -dryrun                Don't apply migrations, just print them.
  -ignoreunknown=false   Skips the check to see if there is a migration ran in the database that is not in MigrationSource, this should be used sparingly as it is removing a safety check.

The use case is that when I do a deployment for my service the first thing I do is running the DB migration (sql-migrate up), but, if I want to rollback the deployment (or redeploy the previous version for that matter) the sql-migration up would throw an error in case a new migration existed. The flag would address this case .

rubenv commented 3 years ago

So as you mention yourself: this removes a safety check.

Most people will blindly use the flag and screw things up, rather than figuring out what went wrong.

Not sure this is a good idea.

jhuliano commented 3 years ago

@rubenv I see, but on the other hand there are also valid use-cases for it, otherwise it wouldn't even be part of the codebase, I guess.

Up to you, feel free to close the PR if you don't like the idea.