Skip to content

Improve error messages when pgroll init has not been run #745

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 11 commits into from
Mar 25, 2025

Conversation

andrew-farries
Copy link
Collaborator

Improve the error messages displayed by the CLI when attempting to run commands that require pgroll init to have been run.

Old example of pgroll start before pgroll init:

ERROR   Failed to start migration: pq: schema "pgroll" does not exist

New error message:

Error: pgroll is not initialized, run 'pgroll init' to initialize

The same change is applied to all other commands that need to run against an initialized database.

Closes #723

@github-actions github-actions bot temporarily deployed to Docs Preview March 25, 2025 09:01 Inactive
@andrew-farries andrew-farries requested a review from Copilot March 25, 2025 09:01
@andrew-farries andrew-farries force-pushed the better-error-on-no-init branch from 4875f20 to 9ee630f Compare March 25, 2025 09:02
@github-actions github-actions bot temporarily deployed to Docs Preview March 25, 2025 09:02 Inactive
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves the error messaging for commands that require pgroll initialization by verifying whether pgroll is initialized before performing operations.

  • Introduces a new error variable (errPGRollNotInitialized) with a clear error message in cmd/errors.go.
  • Adds initialization checks using IsInitialized in multiple CLI command implementations.
  • Implements a new test in pkg/state/state_test.go to verify the behavior of IsInitialized.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cmd/errors.go Adds a new error variable with a clear error message.
pkg/state/state.go Introduces/duplicates the IsInitialized method for checking.
pkg/state/state_test.go Adds test to verify initialization behavior.
cmd/status.go Adds initialization check before showing status.
cmd/start.go Adds initialization check before starting migrations.
cmd/complete.go Adds initialization check before completing migrations.
cmd/rollback.go Adds initialization check before rolling back migrations.
cmd/migrate.go Adds initialization check before migrating.
cmd/analyze.go Adds initialization check before analyzing schema.
cmd/pull.go Adds initialization check before pulling schema history.
cmd/latest.go Adds initialization check before fetching the latest migration.

@andrew-farries andrew-farries force-pushed the better-error-on-no-init branch from 9ee630f to fc09a60 Compare March 25, 2025 09:07
@github-actions github-actions bot temporarily deployed to Docs Preview March 25, 2025 09:07 Inactive
@andrew-farries andrew-farries requested a review from Copilot March 25, 2025 09:08
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves the CLI error messages for commands that require a prior initialization via pgroll init. The changes add a new error variable for uninitialized state, enhance multiple command flows to check initialization before proceeding, and include a test to verify the behavior of the initialization check.

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cmd/errors.go Introduces a new error variable for uninitialized state with an error message.
pkg/state/state_test.go Adds a test validating that IsInitialized returns the expected values before and after Init.
pkg/state/state.go Adds the IsInitialized method to check whether the state has been initialized.
cmd/complete.go Implements an initialization check before completing a migration.
cmd/start.go Implements an initialization check before starting a migration.
cmd/status.go Implements an initialization check before returning the status.
cmd/rollback.go Implements an initialization check before rolling back a migration.
cmd/analyze.go Implements an initialization check before analyzing the schema.
cmd/migrate.go Implements an initialization check before running migrations.
cmd/pull.go Implements an initialization check before pulling the migration history.
cmd/latest.go Implements an initialization check before obtaining the latest version.

@andrew-farries andrew-farries marked this pull request as ready for review March 25, 2025 09:10
@andrew-farries andrew-farries requested a review from kvch March 25, 2025 09:10
@andrew-farries andrew-farries merged commit 6b013fa into main Mar 25, 2025
30 checks passed
@andrew-farries andrew-farries deleted the better-error-on-no-init branch March 25, 2025 15:37
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.

Running migrations when no init should prompt user to init
2 participants