Migration CLI: Add migrate-get command and --dry-run/--show-sql options#273
Merged
Migration CLI: Add migrate-get command and --dry-run/--show-sql options#273
migrate-get command and --dry-run/--show-sql options#273Conversation
08f9a00 to
a0f40c8
Compare
brandur
commented
Mar 16, 2024
| }, | ||
| } | ||
| cmd.Flags().BoolVar(&opts.Down, "down", false, "print down migration") | ||
| cmd.Flags().BoolVar(&opts.Up, "up", false, "print up migration") |
Contributor
Author
There was a problem hiding this comment.
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
brandur
commented
Mar 17, 2024
|
|
||
| require.Equal(t, "-- River migration 001 [down]", migrationComment(1, rivermigrate.DirectionDown)) | ||
| require.Equal(t, "-- River migration 002 [up]", migrationComment(2, rivermigrate.DirectionUp)) | ||
| } |
Contributor
Author
There was a problem hiding this comment.
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
bgentry
approved these changes
Mar 17, 2024
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
Contributor
Author
|
thx! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-getcommand 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-downandmigrate-upget 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--verboseand--debugcommands 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.