-
Notifications
You must be signed in to change notification settings - Fork 515
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
143 changed files
with
5,137 additions
and
3,350 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ | |
# Local testing | ||
.envrc | ||
*.FAIL | ||
/scripts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,4 +48,3 @@ changelog: | |
exclude: | ||
- "^docs:" | ||
- "^test:" | ||
# TODO(mf): add docker support? |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package goose | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/pressly/goose/v4/internal/sqlparser" | ||
"go.uber.org/multierr" | ||
) | ||
|
||
// ApplyVersion applies exactly one migration at the specified version. If a migration cannot be | ||
// found for the specified version, this method returns ErrNoCurrentVersion. If the migration has | ||
// been applied already, this method returns ErrAlreadyApplied. | ||
// | ||
// If the direction is true, the migration will be applied. If the direction is false, the migration | ||
// will be rolled back. | ||
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) | ||
} | ||
|
||
m, err := p.getMigration(version) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
conn, cleanup, err := p.initialize(ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer func() { | ||
retErr = multierr.Append(retErr, cleanup()) | ||
}() | ||
// Ensure version table exists. | ||
if err := p.ensureVersionTable(ctx, conn); err != nil { | ||
return nil, err | ||
} | ||
|
||
result, err := p.store.GetMigration(ctx, conn, version) | ||
if err != nil && !errors.Is(err, sql.ErrNoRows) { | ||
return nil, err | ||
} | ||
if result != nil { | ||
return nil, ErrAlreadyApplied | ||
} | ||
|
||
d := sqlparser.DirectionDown | ||
if direction { | ||
d = sqlparser.DirectionUp | ||
} | ||
results, err := p.runMigrations(ctx, conn, []*migration{m}, d, true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if len(results) == 0 { | ||
return nil, ErrAlreadyApplied | ||
} | ||
return results[0], nil | ||
} |
Oops, something went wrong.