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

Add check for pending migrations #420

Closed
wants to merge 1 commit into from
Closed

Conversation

nkwtnb
Copy link

@nkwtnb nkwtnb commented Dec 1, 2022

First, thank you for creating nice library.

Summary

Compare existing migration files and migration version of DB to check if there is pending migration.

Tests were added as follows

  • The test case of applying all migrations
    • Expect that No pending migrations exist (return false)
  • The test case of rollbacking all migrations
    • Expect that pending migrations exist (return true)

Thank you!

@witsch
Copy link

witsch commented Mar 23, 2024

This, along with perhaps an option to have goose status set its status code to something other than 0 when there are pending migrations would be very helpful.

Our use case is to make some Kubernetes deployments wait for migrations to finish before they are started themselves (using a simple shell loop in most cases). So a straight-forward way to check if the database is "ready" would be great – instead of "grepping" for "pending" that is… 😊

And yes, thanks for all your work on this!

@mfridman
Copy link
Collaborator

Note that goose.NewProvider has a method called .Status(ctx) which returns a slice of []*MigrationStatus,

type MigrationStatus struct {
	Source    *Source
	State     State
	AppliedAt time.Time
}

This allows you to quickly loop over all migrations and check for State, which is one of StatePending and StateApplied.

I presume we could add another method called .Pending() that returns only the migrations that are pending.

In the next few weeks I'll be working on #663 to plug the goose.Provider into the CLI code which enables us to expose much of this functionality, and output it as JSON (#350) so you can programmatically goose status | jq .... Would that help in your case?

@witsch
Copy link

witsch commented Mar 24, 2024

In the next few weeks I'll be working on #663 to plug the goose.Provider into the CLI code which enables us to expose much of this functionality, and output it as JSON (#350) so you can programmatically goose status | jq .... Would that help in your case?

Yes, it surely would. In fact, #225 (which is linked in #350) sounds very close to what we're doing. I just hadn't seen it before, but the JSON output would totally do the trick for us as well! 😊

@mfridman
Copy link
Collaborator

Thank you so much for putting up a PR with tests! I'd prefer to focus our efforts on the goose.Provider which has a bit more knobs and functionality.

At some point we can re-use the .HasPending() method added in #751.

func (p *Provider) HasPending(context.Context) (bool, error) {}

Dropped a #225 (comment) in a related issue.

@mfridman mfridman closed this Apr 21, 2024
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.

3 participants