Skip to content
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

[/v4] - Add CLI and cleanup #497

Merged
merged 10 commits into from
Apr 8, 2023
Merged

[/v4] - Add CLI and cleanup #497

merged 10 commits into from
Apr 8, 2023

Conversation

mfridman
Copy link
Collaborator

@mfridman mfridman commented Apr 8, 2023

This PR adds the CLI component back to the goose command. We're using the https://github.com/peterbourgon/ff (and ffcli) to compose the CLI.

There are also a few improvements, refactors and cleanups to the library itself because now we're starting to use it as if the consumer would.

There are a few breaking changes here, and will need to revisit those before merging:

  • Remove the reset command and method. This was an alias to down-to 0 or .DownTo(ctx, 0), and no point having 2 ways to do the same thing
  • Remove GOOSE_DRIVER evn variable, we can instead derive the intended dialect from the GOOSE_DBSTRING or --dbstring. E.g.,
GOOSE_DBSTRING="postgresql://dbuser:password1@localhost:5433/testdb?sslmode=disable"

With the help of https://github.com/xo/dburl we can parse the database connection string. This should greatly simplify CLI usage.

  • Rename GOOSE_MIGRATION_DIR to just GOOSE_DIR
  • The MigrationResult likely needs to surface error(s) per migration

This one is especially important because when running goose up we may apply N migrations but fail for any number of reasons, this should be available when printing out or outputting JSON. Remember, we don't print within the goose package anymore, so this needs to be surfaced back to the user.

@mfridman
Copy link
Collaborator Author

mfridman commented Apr 8, 2023

Cleaned up the CLI a bit,

A database migration tool that simplifies the process of versioning, applying, and rolling back
schema changes in a controlled and organized way.

USAGE
  goose [flags] <command>

COMMANDS
  create          Create a new .go or .sql migration file
  down            Migrate database down to the previous version
  down-to         Migrate database down to, but not including, a specific version
  env             Print environment variables
  fix             Apply sequential numbering to existing timestamped migrations
  redo            Roll back the last appied migration and re-apply it
  status          List applied and pending migrations
  up              Migrate database to the most recent version
  up-by-one       Migrate database up by one version
  up-to           Migrate database up to, and including, a specific version
  version         Print the current version of the database

SUPPORTED DATABASES
  postgres        mysql        sqlite3
  redshift        tidb         mssql
  clickhouse      vertica      

FLAGS
  --allow-missing         Allow missing (out-of-order) migrations
  --dbstring              Database connection string
  --dir                   Directory with migration files (default: "./migrations")
  --exclude               Exclude migrations by filename, comma separated
  --help                  Display help
  --json                  Format output as JSON
  --lock-mode             Set a lock mode [none, advisory-session] (default: "none")
  --no-versioning         Do not store version info in the database, just run the migrations
  --table                 Table name to store version info (default: "goose_db_version")
  --v                     Turn on verbose mode
  --version               Display the version of goose currently installed

ENVIRONMENT VARIABLES
  GOOSE_DBSTRING          Database connection string, lower priority than --dbstring
  GOOSE_DIR               Directory with migration files, lower priority than --dir

EXAMPLES
  goose --dbstring="postgres://user:password@localhost:5432/dbname?sslmode=disable" status
  goose --dbstring="mysql://user:password@/dbname?parseTime=true" status

  GOOSE_DIR=./examples/sql-migrations GOOSE_DBSTRING="sqlite:./test.db" goose status
  GOOSE_DBSTRING="clickhouse://user:password@localhost:9000/clickdb" goose status

LEARN MORE
  Use 'goose <command> --help' for more information about a command.
  Read the manual at https://pressly.github.io/goose/

@mfridman mfridman merged commit a325e95 into v4 Apr 8, 2023
@mfridman mfridman deleted the v4-goose-cmd branch September 17, 2024 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant