Skip to content

Commit

Permalink
mark methods as safe for concurrent use
Browse files Browse the repository at this point in the history
  • Loading branch information
mfridman committed May 19, 2023
1 parent 6e2416e commit 5db7047
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apply_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
//
// If the direction is true, the migration will be applied. If the direction is false, the migration
// will be rolled back.
//
// It is safe for concurrent use.
func (p *Provider) ApplyVersion(ctx context.Context, version int64, direction bool) (_ *MigrationResult, retErr error) {
if version < 1 {
return nil, fmt.Errorf("invalid version: %d", version)
Expand Down
2 changes: 2 additions & 0 deletions down.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func (p *Provider) Down(ctx context.Context) (*MigrationResult, error) {
//
// For example, suppose we are currently at migrations 11 and the requested version is 9. In this
// scenario only migrations 11 and 10 will be rolled back.
//
// It is safe for concurrent use.
func (p *Provider) DownTo(ctx context.Context, version int64) ([]*MigrationResult, error) {
return p.down(ctx, false, version)
}
Expand Down
2 changes: 2 additions & 0 deletions status.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type StatusOptions struct {
// Status returns the status of all migrations. The returned slice is ordered by ascending version.
//
// The provided StatusOptions is optional and may be nil if defaults should be used.
//
// It is safe for concurrent use.
func (p *Provider) Status(ctx context.Context, opts *StatusOptions) (_ []*MigrationStatus, retErr error) {
conn, cleanup, err := p.initialize(ctx)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions up.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ import (

// Up applies all available migrations. If there are no migrations to apply, this method returns
// empty list and nil error.
//
// It is safe for concurrent use.
func (p *Provider) Up(ctx context.Context) ([]*MigrationResult, error) {
return p.up(ctx, false, math.MaxInt64)
}

// UpByOne applies the next available migration. If there are no migrations to apply, this method
// returns ErrNoNextVersion.
//
// It is safe for concurrent use.
func (p *Provider) UpByOne(ctx context.Context) (*MigrationResult, error) {
res, err := p.up(ctx, true, math.MaxInt64)
if err != nil {
Expand All @@ -38,6 +42,8 @@ func (p *Provider) UpByOne(ctx context.Context) (*MigrationResult, error) {
//
// For example, suppose there are 3 new migrations available 9, 10, 11. The current database version
// is 8 and the requested version is 10. In this scenario only versions 9 and 10 will be applied.
//
// It is safe for concurrent use.
func (p *Provider) UpTo(ctx context.Context, version int64) ([]*MigrationResult, error) {
return p.up(ctx, false, version)
}
Expand Down
2 changes: 2 additions & 0 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
)

// GetDBVersion retrieves the current database version.
//
// It is safe for concurrent use.
func (p *Provider) GetDBVersion(ctx context.Context) (_ int64, retErr error) {
conn, cleanup, err := p.initialize(ctx)
if err != nil {
Expand Down

0 comments on commit 5db7047

Please sign in to comment.