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

feat: Add a ListDBMigrations function in provider #905

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ func (p *Provider) ListSources() []*Source {
return sources
}

// ListDBMigrations return a list of all migrations listed in the provider database.
func (p *Provider) ListDBMigrations(ctx context.Context) (_ []*database.ListMigrationsResult, retErr error) {
return p.listDBMigrations(ctx, nil)
}

// Ping attempts to ping the database to verify a connection is available.
func (p *Provider) Ping(ctx context.Context) error {
return p.db.PingContext(ctx)
Expand Down Expand Up @@ -648,3 +653,25 @@ func (p *Provider) getDBMaxVersion(ctx context.Context, conn *sql.Conn) (_ int64
}
return latest, nil
}

func (p *Provider) listDBMigrations(ctx context.Context, conn *sql.Conn) (_ []*database.ListMigrationsResult, retErr error) {

if conn == nil {
var cleanup func() error
var err error
conn, cleanup, err = p.initialize(ctx, true)
if err != nil {
return []*database.ListMigrationsResult{}, err
}
defer func() {
retErr = multierr.Append(retErr, cleanup())
}()
}

dbMigrations, err := p.store.ListMigrations(ctx, conn)
if err != nil {
return []*database.ListMigrationsResult{}, err
}

return dbMigrations, nil
}