-
Notifications
You must be signed in to change notification settings - Fork 49
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
Migration CLI: Add migrate-get
command and --dry-run
/--show-sql
options
#273
Conversation
08f9a00
to
a0f40c8
Compare
}, | ||
} | ||
cmd.Flags().BoolVar(&opts.Down, "down", false, "print down migration") | ||
cmd.Flags().BoolVar(&opts.Up, "up", false, "print up migration") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a little odd that this command takes --down
and --up
options, when the migration commands are migrate-down
and migrate-up
, but I tried to consider all the alternatives, and I think this is the least bad. Having two full commands for migrate-get-down
and migrate-get-up
feels too heavy handed and unwieldy.
b505679
to
dc121f5
Compare
6945ab6
to
8f9bb03
Compare
|
||
require.Equal(t, "-- River migration 001 [down]", migrationComment(1, rivermigrate.DirectionDown)) | ||
require.Equal(t, "-- River migration 002 [up]", migrationComment(2, rivermigrate.DirectionUp)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh, I wish I could write more tests for the CLI, but I'm getting hard blocked by the fact that none of our internal test utilities are available to this module. Something to look into separately, but punting on it for now.
8f9bb03
to
0b5125b
Compare
e5d4268
to
71abf47
Compare
… options This one's in pursuit of resolving #209, which I've decided to tackle now because we're going to have to cut a CLI release across River package versions for #258 anyway, so this'll reuse some work. A new `river migrate-get` command becomes available, whose only job is to dump SQL from River migrations so that it can easily be plugged into other migration frameworks. Its use looks like: river migrate-get --version 3 --down > version3.down.sql river migrate-get --version 3 --up > version3.up.sql It can also take multiple versions: river migrate-get --version 3,2,1 --down > river.down.sql river migrate-get --version 1,2.3 --up > river.up.sql It can also dump _all_ migrations, which will be useful in cases where users want to avoid River's internal migration framework completely, and use their own: river migrate-get --all --exclude-version 1 --up > river_all.up.sql river migrate-get --all --exclude-version 1 --down > river_all.down.sql Along with that, `migrate-down` and `migrate-up` get a few new useful options: * `--dry-run`: Prints information on migrations that would be run, but doesn't modify the database in any way. * `--show-sql`: Prints SQL for each migration step that was applied. This gives users an easy way to, after a River upgrade, run the CLI to see what commands would be run were they to migrate, but without actually performing the migration, likely a step that most production users would perform to be cautious: river migrate-up --dry-run --show-sql I've also done a little cleanup around the River CLI's `main.go`. The `--verbose` and `--debug` commands added in #258 are now promoted to persistent flag configuration so they're available for all commands, and we now have one standardized way of initializing an appropriate logger. Fixes #209.
0b5125b
to
62db5c7
Compare
thx! |
This one's in pursuit of resolving #209, which I've decided to tackle
now because we're going to have to cut a CLI release across River
package versions for #258 anyway, so this'll reuse some work.
A new
river migrate-get
command becomes available, whose only job isto dump SQL from River migrations so that it can easily be plugged into
other migration frameworks. Its use looks like:
It can also take multiple versions:
It can also dump all migrations, which will be useful in cases where
users want to avoid River's internal migration framework completely, and
use their own:
Along with that,
migrate-down
andmigrate-up
get a few new usefuloptions:
--dry-run
: Prints information on migrations that would be run, butdoesn't modify the database in any way.
--show-sql
: Prints SQL for each migration step that was applied.This gives users an easy way to, after a River upgrade, run the CLI to
see what commands would be run were they to migrate, but without
actually performing the migration, likely a step that most production
users would perform to be cautious:
I've also done a little cleanup around the River CLI's
main.go
. The--verbose
and--debug
commands added in #258 are now promoted topersistent flag configuration so they're available for all commands, and
we now have one standardized way of initializing an appropriate logger.
Fixes #209.