-
Notifications
You must be signed in to change notification settings - Fork 105
Split pgroll latest #861
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
Split pgroll latest #861
Conversation
Split pgroll latest into - pgroll latest migration - pgroll latest schema Fix #845 Amp: https://ampcode.com/threads/T-51521447-5949-4653-bc50-d7c846a27757
@@ -13,26 +13,39 @@ import ( | |||
) | |||
|
|||
func latestCmd() *cobra.Command { | |||
var withSchema bool |
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.
Please add withSchema
back to the code. It is indeed not needed for the code to function. But it makes the code more readable for humans. :)
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.
Done, did you mean something like this? 2ced55e
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.
Almost. :D What I meant is that passing true
and false
to functions can impair readablity. You have to look at the function signature to understand what true and false mean. If you "alias" true to "withSchema" and "withoutSchema", it becomes clear to the reader what true/false means.
In the previous version of the code, I would like have a local variable in latestMigrationCmd
named withoutSchema
set to false. In latestSchemaCmd
a local varaible named withSchema set to true. Then pass those variables to
latestVersionLocal` like:
latestVersion, err = latestVersionLocal(ctx, migrationsDir, withSchema)
and
latestVersion, err = latestVersionLocal(ctx, migrationsDir, withoutSchema)
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.
This is done, as discussed in DMs, I ended up using withSchema
and !withSchema
instead of withoutSchema = false
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.
Looks good; made one suggestion
cmd/latest.go
Outdated
if migrationsDir != "" { | ||
latestVersion, err = latestVersionLocal(ctx, migrationsDir, withSchema) | ||
if err != nil { | ||
return fmt.Errorf("failed to get latest version from directory %q: %w", migrationsDir, err) | ||
} | ||
} else { | ||
latestVersion, err = latestVersionRemote(ctx, withSchema) | ||
if err != nil { | ||
return fmt.Errorf("failed to get latest version from database: %w", err) | ||
} |
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.
The duplication between latestMigrationCmd
and latestSchemaCmd
could be removed by adding a function:
// getLatestVersion returns the latest migration version from a local
// migrations directory or remote database, optionally prepending the schema
// name to which the migration is applied.
func getLatestVersion(ctx context.Context, migrationsDir string, withSchema bool) (string, error) {
if migrationsDir != "" {
return latestVersionLocal(ctx, migrationsDir, withSchema)
}
return latestVersionRemote(ctx, withSchema)
}
and using it from both latestMigrationCmd
and latestSchemaCmd
.
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.
This is done.
Split pgroll latest into
Fix #845
Amp: https://ampcode.com/threads/T-51521447-5949-4653-bc50-d7c846a27757