Skip to content

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

Merged
merged 4 commits into from
Jun 2, 2025
Merged

Split pgroll latest #861

merged 4 commits into from
Jun 2, 2025

Conversation

divyenduz
Copy link
Contributor

@divyenduz divyenduz commented May 28, 2025

Split pgroll latest into

  • pgroll latest migration
  • pgroll latest schema

CleanShot 2025-05-28 at 20 11 54@2x

Fix #845

Amp: https://ampcode.com/threads/T-51521447-5949-4653-bc50-d7c846a27757

Split pgroll latest into
- pgroll latest migration
- pgroll latest schema

Fix #845

Amp: https://ampcode.com/threads/T-51521447-5949-4653-bc50-d7c846a27757
@github-actions github-actions bot temporarily deployed to Docs Preview May 28, 2025 18:10 Inactive
@github-actions github-actions bot temporarily deployed to Docs Preview May 28, 2025 18:12 Inactive
@@ -13,26 +13,39 @@ import (
)

func latestCmd() *cobra.Command {
var withSchema bool
Copy link
Contributor

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. :)

Copy link
Contributor Author

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

Copy link
Contributor

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)

Copy link
Contributor Author

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

@github-actions github-actions bot temporarily deployed to Docs Preview May 29, 2025 15:17 Inactive
@andrew-farries andrew-farries self-requested a review June 2, 2025 08:10
Copy link
Collaborator

@andrew-farries andrew-farries left a 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
Comment on lines 77 to 86
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)
}
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done.

@github-actions github-actions bot temporarily deployed to Docs Preview June 2, 2025 12:10 Inactive
@divyenduz divyenduz merged commit 7b932e9 into main Jun 2, 2025
30 checks passed
@divyenduz divyenduz deleted the split_latest_migration branch June 2, 2025 14:36
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.

Split pgroll latest into pgroll latest schema and pgroll latest migration
3 participants