-
Notifications
You must be signed in to change notification settings - Fork 525
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
Programmatically support checking if there are any pending migrations #225
Comments
@wendorf Interesting suggestion, I like it. Just thinking out-loud, would something like this work, pseudo based on your suggestion? {
"migrations": [
{
"name": "000001_baseline_schema.sql",
"applied_at": "2020-08-24T19:40:36-04:00",
"is_applied": true,
"version_id": 0
},
{
"name": "000057_drop_a_table.go",
"applied_at": "2020-08-24T19:40:40-04:00",
"is_applied": true,
"version_id": 45
},
{
"name": "20200808122156_backfill_data.go",
"applied_at": "",
"is_applied": false,
"version_id": 20200808122156
}
]
} |
That would work quite well :) To bikeshed, I might omit the |
Would be useful to have this also accessible from the go package's interface. In our case we use goose programmatically to set up the database for integration tests, and it would be good to be able to know is there are pending migrations when a test suite is first run. something like: goose.DetailedStatus(db *sql.DB, dir string, opts ...goose.OptionsFunc) ([]goose.MigrationStatus, error) |
The goose provider now has a func (p *Provider) HasPending(context.Context) (bool, error) {} I'm going to keep this issue open until there is |
In my CI pipeline, I want to fail a code deploy if there are any pending migrations so a human can look at them manually. I currently do that by running
! goose status 2>&1 | grep Pending > /dev/null
. If that returns 0, then I know I have no pending migrations and can continue with my deploy.This works, but it feels a bit brittle to grep for a string. I'd prefer to have explicit support in goose for programmatically knowing if migrations are pending.
Some possible solutions:
goose status --fail-if-pending
goose status --json | jq '.migrations[] | select(.pending)' -e
The text was updated successfully, but these errors were encountered: