mirror of https://github.com/pressly/goose.git
rename back to GetDBVersion
parent
67b6f0784a
commit
abcbf8b607
|
@ -342,11 +342,11 @@ func run(command string, p *goose.Provider, dir string, args []string) error {
|
|||
case "status":
|
||||
// TODO(mf): implement
|
||||
case "version":
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Printf("goose: version %v\n", currentVersion)
|
||||
log.Printf("goose: version %v\n", dbVersion)
|
||||
default:
|
||||
return fmt.Errorf("%q: no such command", command)
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@ package goose
|
|||
|
||||
import "context"
|
||||
|
||||
// CurrentVersion prints the current version of the database.
|
||||
func (p *Provider) CurrentVersion(ctx context.Context) (int64, error) {
|
||||
// GetDBVersion returns the current version of the database.
|
||||
func (p *Provider) GetDBVersion(ctx context.Context) (int64, error) {
|
||||
var migrationRow migrationRow
|
||||
err := p.db.QueryRowContext(
|
||||
ctx,
|
||||
|
|
12
down.go
12
down.go
|
@ -12,13 +12,13 @@ func (p *Provider) Down(ctx context.Context) error {
|
|||
// Migrate only the latest migration down.
|
||||
return p.downToNoVersioning(ctx, currentVersion-1)
|
||||
}
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
migration, err := p.migrations.Current(currentVersion)
|
||||
migration, err := p.migrations.Current(dbVersion)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to find migration:%d", currentVersion)
|
||||
return fmt.Errorf("failed to find migration:%d", dbVersion)
|
||||
}
|
||||
return p.startMigration(ctx, false, migration)
|
||||
}
|
||||
|
@ -51,14 +51,14 @@ func (p *Provider) DownTo(ctx context.Context, version int64) error {
|
|||
// 5,4,3,2,1
|
||||
// I think the most accurate way is to migrate down based on the initial order that was applied.
|
||||
for {
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if currentVersion == 0 {
|
||||
if dbVersion == 0 {
|
||||
return nil
|
||||
}
|
||||
current, err := p.migrations.Current(currentVersion)
|
||||
current, err := p.migrations.Current(dbVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -168,16 +168,16 @@ func TestEmbeddedMigrations(t *testing.T) {
|
|||
t.Run("migration_cycle", func(t *testing.T) {
|
||||
err := p.Up(ctx)
|
||||
check.NoError(t, err)
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, 3)
|
||||
check.Number(t, dbVersion, 3)
|
||||
|
||||
err = p.Reset(ctx)
|
||||
check.NoError(t, err)
|
||||
|
||||
currentVersion, err = p.CurrentVersion(ctx)
|
||||
dbVersion, err = p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, 0)
|
||||
check.Number(t, dbVersion, 0)
|
||||
})
|
||||
|
||||
t.Run("create_uses_os_fs", func(t *testing.T) {
|
||||
|
|
4
redo.go
4
redo.go
|
@ -12,11 +12,11 @@ func (p *Provider) Redo(ctx context.Context) error {
|
|||
return err
|
||||
}
|
||||
} else {
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
migration, err = p.migrations.Current(currentVersion)
|
||||
migration, err = p.migrations.Current(dbVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -59,20 +59,20 @@ func TestClickUpDownAll(t *testing.T) {
|
|||
Ref: https://clickhouse.com/blog/how-to-update-data-in-click-house/
|
||||
*/
|
||||
|
||||
// Collect migrations so we don't have to hard-code the currentVersion
|
||||
// Collect migrations so we don't have to hard-code the dbVersion
|
||||
// in an assertion later in the test.
|
||||
migrations := p.ListMigrations()
|
||||
check.NumberNotZero(t, len(migrations))
|
||||
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, 0)
|
||||
check.Number(t, dbVersion, 0)
|
||||
|
||||
err = p.Up(ctx)
|
||||
check.NoError(t, err)
|
||||
currentVersion, err = p.CurrentVersion(ctx)
|
||||
dbVersion, err = p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, len(migrations))
|
||||
check.Number(t, dbVersion, len(migrations))
|
||||
|
||||
err = p.DownTo(ctx, 0)
|
||||
check.NoError(t, err)
|
||||
|
@ -82,9 +82,9 @@ func TestClickUpDownAll(t *testing.T) {
|
|||
)
|
||||
check.NoError(t, err)
|
||||
|
||||
currentVersion, err = p.CurrentVersion(ctx)
|
||||
dbVersion, err = p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, 0)
|
||||
check.Number(t, dbVersion, 0)
|
||||
}
|
||||
|
||||
func TestClickHouseFirstThree(t *testing.T) {
|
||||
|
@ -102,9 +102,9 @@ func TestClickHouseFirstThree(t *testing.T) {
|
|||
err = p.Up(ctx)
|
||||
check.NoError(t, err)
|
||||
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, 3)
|
||||
check.Number(t, dbVersion, 3)
|
||||
|
||||
type result struct {
|
||||
customerID string `db:"customer_id"`
|
||||
|
@ -173,7 +173,7 @@ func TestRemoteImportMigration(t *testing.T) {
|
|||
|
||||
err = p.Up(ctx)
|
||||
check.NoError(t, err)
|
||||
_, err = p.CurrentVersion(ctx)
|
||||
_, err = p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
|
||||
var count int
|
||||
|
|
|
@ -25,9 +25,9 @@ func TestNotAllowMissing(t *testing.T) {
|
|||
// Developer A - migration 7 (mistakenly applied)
|
||||
err = p.Apply(ctx, 7)
|
||||
check.NoError(t, err)
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, 7)
|
||||
check.Number(t, dbVersion, 7)
|
||||
|
||||
// Developer B - migration 6 (missing) and 8 (new)
|
||||
// This should raise an error. By default goose does not allow missing (out-of-order)
|
||||
|
@ -36,9 +36,9 @@ func TestNotAllowMissing(t *testing.T) {
|
|||
check.HasError(t, err)
|
||||
check.Contains(t, err.Error(), "missing migrations")
|
||||
// Confirm db version is unchanged.
|
||||
currentVersion, err = p.CurrentVersion(ctx)
|
||||
dbVersion, err = p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, 7)
|
||||
check.Number(t, dbVersion, 7)
|
||||
}
|
||||
|
||||
func TestAllowMissingUpWithRedo(t *testing.T) {
|
||||
|
@ -58,30 +58,30 @@ func TestAllowMissingUpWithRedo(t *testing.T) {
|
|||
{
|
||||
err := p.Apply(ctx, 7)
|
||||
check.NoError(t, err)
|
||||
current, err := p.CurrentVersion(ctx)
|
||||
current, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, current, 7)
|
||||
|
||||
// Redo the previous Up migration and re-apply it.
|
||||
err = p.Redo(ctx)
|
||||
check.NoError(t, err)
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, 7)
|
||||
check.Number(t, dbVersion, 7)
|
||||
}
|
||||
// Migration 6
|
||||
{
|
||||
err := p.UpByOne(ctx)
|
||||
check.NoError(t, err)
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, 6)
|
||||
check.Number(t, dbVersion, 6)
|
||||
|
||||
err = p.Redo(ctx)
|
||||
check.NoError(t, err)
|
||||
currentVersion, err = p.CurrentVersion(ctx)
|
||||
dbVersion, err = p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, 6)
|
||||
check.Number(t, dbVersion, 6)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,9 +108,9 @@ func TestNotAllowMissingUpByOne(t *testing.T) {
|
|||
{
|
||||
err = p.Apply(ctx, 7)
|
||||
check.NoError(t, err)
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, 7)
|
||||
check.Number(t, dbVersion, 7)
|
||||
}
|
||||
// Developer B - migration 6
|
||||
{
|
||||
|
@ -124,10 +124,10 @@ func TestNotAllowMissingUpByOne(t *testing.T) {
|
|||
check.NoError(t, err)
|
||||
check.Number(t, count, 6)
|
||||
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
// Expecting max(version_id) to be 7
|
||||
check.Number(t, currentVersion, 7)
|
||||
check.Number(t, dbVersion, 7)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,9 +157,9 @@ func TestAllowMissingUpWithReset(t *testing.T) {
|
|||
{
|
||||
err := p.Apply(ctx, 7)
|
||||
check.NoError(t, err)
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, 7)
|
||||
check.Number(t, dbVersion, 7)
|
||||
}
|
||||
// Developer B - migration 6 (missing) and 8 (new)
|
||||
{
|
||||
|
@ -179,7 +179,7 @@ func TestAllowMissingUpWithReset(t *testing.T) {
|
|||
// Count should be all testdata migrations (all applied)
|
||||
check.Number(t, count, len(allMigrations))
|
||||
|
||||
current, err := p.CurrentVersion(ctx)
|
||||
current, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
// Expecting max(version_id) to be highest version in testdata
|
||||
check.Number(t, current, maxVersionID)
|
||||
|
@ -188,9 +188,9 @@ func TestAllowMissingUpWithReset(t *testing.T) {
|
|||
// Migrate everything down using Reset.
|
||||
err = p.Reset(ctx)
|
||||
check.NoError(t, err)
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, 0)
|
||||
check.Number(t, dbVersion, 0)
|
||||
}
|
||||
|
||||
func TestAllowMissingUpByOne(t *testing.T) {
|
||||
|
@ -219,7 +219,7 @@ func TestAllowMissingUpByOne(t *testing.T) {
|
|||
{
|
||||
err = p.Apply(ctx, 7)
|
||||
check.NoError(t, err)
|
||||
current, err := p.CurrentVersion(ctx)
|
||||
current, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, current, 7)
|
||||
}
|
||||
|
@ -233,10 +233,10 @@ func TestAllowMissingUpByOne(t *testing.T) {
|
|||
// Expecting count of migrations to be 7
|
||||
check.Number(t, count, 7)
|
||||
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
// Expecting max(version_id) to be 6
|
||||
check.Number(t, currentVersion, 6)
|
||||
check.Number(t, dbVersion, 6)
|
||||
}
|
||||
// Developer B - migration 8
|
||||
{
|
||||
|
@ -249,10 +249,10 @@ func TestAllowMissingUpByOne(t *testing.T) {
|
|||
// Expecting count of migrations to be 8
|
||||
check.Number(t, count, 8)
|
||||
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
// Expecting max(version_id) to be 8
|
||||
check.Number(t, currentVersion, 8)
|
||||
check.Number(t, dbVersion, 8)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -273,7 +273,7 @@ func TestMigrateAllowMissingDown(t *testing.T) {
|
|||
{
|
||||
err := p.Apply(ctx, 7)
|
||||
check.NoError(t, err)
|
||||
current, err := p.CurrentVersion(ctx)
|
||||
current, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, current, 7)
|
||||
}
|
||||
|
@ -289,7 +289,7 @@ func TestMigrateAllowMissingDown(t *testing.T) {
|
|||
count, err := getGooseVersionCount(db, defaultTableName)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, count, 8)
|
||||
current, err := p.CurrentVersion(ctx)
|
||||
current, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
// Expecting max(version_id) to be 8
|
||||
check.Number(t, current, 8)
|
||||
|
@ -303,7 +303,7 @@ func TestMigrateAllowMissingDown(t *testing.T) {
|
|||
{
|
||||
err := p.Down(ctx)
|
||||
check.NoError(t, err)
|
||||
current, err := p.CurrentVersion(ctx)
|
||||
current, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
// Expecting max(version) to be 6
|
||||
check.Number(t, current, 6)
|
||||
|
@ -312,7 +312,7 @@ func TestMigrateAllowMissingDown(t *testing.T) {
|
|||
{
|
||||
err := p.Down(ctx)
|
||||
check.NoError(t, err)
|
||||
current, err := p.CurrentVersion(ctx)
|
||||
current, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
// Expecting max(version) to be 7
|
||||
check.Number(t, current, 7)
|
||||
|
@ -321,7 +321,7 @@ func TestMigrateAllowMissingDown(t *testing.T) {
|
|||
{
|
||||
err := p.Down(ctx)
|
||||
check.NoError(t, err)
|
||||
current, err := p.CurrentVersion(ctx)
|
||||
current, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
// Expecting max(version) to be 5
|
||||
check.Number(t, current, 5)
|
||||
|
@ -340,8 +340,8 @@ func setupTestDB(t *testing.T, version int64) *sql.DB {
|
|||
check.NoError(t, err)
|
||||
// Verify the currentVersion DB version is the Nth migration. This will only
|
||||
// work for sqeuentially applied migrations.
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, version)
|
||||
check.Number(t, dbVersion, version)
|
||||
return db
|
||||
}
|
||||
|
|
|
@ -28,22 +28,22 @@ func TestMigrateUpWithReset(t *testing.T) {
|
|||
// Migrate all
|
||||
err = p.Up(ctx)
|
||||
check.NoError(t, err)
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, migrations[len(migrations)-1].Version)
|
||||
check.Number(t, dbVersion, migrations[len(migrations)-1].Version)
|
||||
// Validate the db migration version actually matches what goose claims it is
|
||||
// based on the last migration applied.
|
||||
gotVersion, err := getCurrentGooseVersion(db, defaultTableName)
|
||||
check.NoError(t, err)
|
||||
|
||||
check.Number(t, gotVersion, currentVersion)
|
||||
check.Number(t, gotVersion, dbVersion)
|
||||
|
||||
// Migrate everything down using Reset.
|
||||
err = p.Reset(ctx)
|
||||
check.NoError(t, err)
|
||||
currentVersion, err = p.CurrentVersion(ctx)
|
||||
dbVersion, err = p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, 0)
|
||||
check.Number(t, dbVersion, 0)
|
||||
}
|
||||
|
||||
func TestMigrateUpWithRedo(t *testing.T) {
|
||||
|
@ -56,9 +56,9 @@ func TestMigrateUpWithRedo(t *testing.T) {
|
|||
p, err := goose.NewProvider(toDialect(t, *dialect), db, migrationsDir, nil)
|
||||
check.NoError(t, err)
|
||||
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, 0)
|
||||
check.Number(t, dbVersion, 0)
|
||||
|
||||
var count int
|
||||
for {
|
||||
|
@ -71,24 +71,24 @@ func TestMigrateUpWithRedo(t *testing.T) {
|
|||
t.Fatalf("expecting error:%v", goose.ErrNoNextVersion)
|
||||
}
|
||||
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, count)
|
||||
check.Number(t, dbVersion, count)
|
||||
|
||||
// Redo the previous Up migration and re-apply it.
|
||||
err = p.Redo(ctx)
|
||||
check.NoError(t, err)
|
||||
|
||||
currentVersion, err = p.CurrentVersion(ctx)
|
||||
dbVersion, err = p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, count)
|
||||
check.Number(t, dbVersion, count)
|
||||
}
|
||||
migrations := p.ListMigrations()
|
||||
// Once everything is tested the version should match the highest testdata version
|
||||
maxVersion := migrations[len(migrations)-1].Version
|
||||
currentVersion, err = p.CurrentVersion(ctx)
|
||||
dbVersion, err = p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, maxVersion)
|
||||
check.Number(t, dbVersion, maxVersion)
|
||||
}
|
||||
|
||||
func TestMigrateUpTo(t *testing.T) {
|
||||
|
@ -107,9 +107,9 @@ func TestMigrateUpTo(t *testing.T) {
|
|||
err = p.UpTo(ctx, upToVersion)
|
||||
check.NoError(t, err)
|
||||
// Fetch the goose version from DB
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, upToVersion)
|
||||
check.Number(t, dbVersion, upToVersion)
|
||||
// Validate the version actually matches what goose claims it is
|
||||
gotVersion, err := getCurrentGooseVersion(db, defaultTableName)
|
||||
check.NoError(t, err)
|
||||
|
@ -143,13 +143,13 @@ func TestMigrateUpByOne(t *testing.T) {
|
|||
}
|
||||
counter++
|
||||
}
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, migrations[len(migrations)-1].Version)
|
||||
check.Number(t, dbVersion, migrations[len(migrations)-1].Version)
|
||||
// Validate the db migration version actually matches what goose claims it is
|
||||
gotVersion, err := getCurrentGooseVersion(db, defaultTableName)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, gotVersion, currentVersion)
|
||||
check.Number(t, gotVersion, dbVersion)
|
||||
}
|
||||
|
||||
func TestMigrateFull(t *testing.T) {
|
||||
|
@ -193,13 +193,13 @@ func TestMigrateFull(t *testing.T) {
|
|||
// Apply all up migrations
|
||||
err = p.Up(ctx)
|
||||
check.NoError(t, err)
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, currentVersion, migrations[len(migrations)-1].Version)
|
||||
check.Number(t, dbVersion, migrations[len(migrations)-1].Version)
|
||||
// Validate the db migration version actually matches what goose claims it is
|
||||
gotVersion, err := getCurrentGooseVersion(db, defaultTableName)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, gotVersion, currentVersion)
|
||||
check.Number(t, gotVersion, dbVersion)
|
||||
tables, err := getTableNames(db)
|
||||
check.NoError(t, err)
|
||||
if !reflect.DeepEqual(tables, knownTables) {
|
||||
|
|
|
@ -27,7 +27,7 @@ func TestNoVersioning(t *testing.T) {
|
|||
|
||||
err = p.Up(ctx)
|
||||
check.NoError(t, err)
|
||||
baseVersion, err := p.CurrentVersion(ctx)
|
||||
baseVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
|
||||
// Create a separate provider
|
||||
|
@ -43,9 +43,9 @@ func TestNoVersioning(t *testing.T) {
|
|||
err = noVersionProvider.Up(ctx)
|
||||
check.NoError(t, err)
|
||||
// Confirm no changes to the versioned schema in the DB
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, baseVersion, currentVersion)
|
||||
check.Number(t, baseVersion, dbVersion)
|
||||
seedOwnerCount, err := countSeedOwners(db)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, seedOwnerCount, wantSeedOwnerCount)
|
||||
|
@ -56,9 +56,9 @@ func TestNoVersioning(t *testing.T) {
|
|||
err = noVersionProvider.DownTo(ctx, 0)
|
||||
check.NoError(t, err)
|
||||
// Confirm no changes to the versioned schema in the DB
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, baseVersion, currentVersion)
|
||||
check.Number(t, baseVersion, dbVersion)
|
||||
seedOwnerCount, err := countSeedOwners(db)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, seedOwnerCount, 0)
|
||||
|
@ -77,9 +77,9 @@ func TestNoVersioning(t *testing.T) {
|
|||
err = noVersionProvider.Up(ctx)
|
||||
check.NoError(t, err)
|
||||
// Confirm no changes to the versioned schema in the DB
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, baseVersion, currentVersion)
|
||||
check.Number(t, baseVersion, dbVersion)
|
||||
seedOwnerCount, err := countSeedOwners(db)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, seedOwnerCount, wantSeedOwnerCount)
|
||||
|
@ -90,9 +90,9 @@ func TestNoVersioning(t *testing.T) {
|
|||
err = noVersionProvider.Reset(ctx)
|
||||
check.NoError(t, err)
|
||||
// Confirm no changes to the versioned schema in the DB
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, baseVersion, currentVersion)
|
||||
check.Number(t, baseVersion, dbVersion)
|
||||
seedOwnerCount, err := countSeedOwners(db)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, seedOwnerCount, 0)
|
||||
|
@ -111,9 +111,9 @@ func TestNoVersioning(t *testing.T) {
|
|||
err = noVersionProvider.Up(ctx)
|
||||
check.NoError(t, err)
|
||||
// Confirm no changes to the versioned schema in the DB
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, baseVersion, currentVersion)
|
||||
check.Number(t, baseVersion, dbVersion)
|
||||
seedOwnerCount, err := countSeedOwners(db)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, seedOwnerCount, wantSeedOwnerCount)
|
||||
|
@ -124,9 +124,9 @@ func TestNoVersioning(t *testing.T) {
|
|||
err = noVersionProvider.Redo(ctx)
|
||||
check.NoError(t, err)
|
||||
// Confirm no changes to the versioned schema in the DB
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, baseVersion, currentVersion)
|
||||
check.Number(t, baseVersion, dbVersion)
|
||||
seedOwnerCount, err := countSeedOwners(db)
|
||||
check.NoError(t, err)
|
||||
check.Number(t, seedOwnerCount, wantSeedOwnerCount) // owners should be unchanged
|
||||
|
|
8
up.go
8
up.go
|
@ -48,7 +48,7 @@ func (p *Provider) up(ctx context.Context, upByOne bool, version int64) error {
|
|||
var current int64
|
||||
for {
|
||||
var err error
|
||||
current, err = p.CurrentVersion(ctx)
|
||||
current, err = p.GetDBVersion(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -108,13 +108,13 @@ func (p *Provider) upAllowMissing(
|
|||
// want to keep it as a safe-guard. Maybe we should instead have
|
||||
// the underlying query (if possible) return the current version as
|
||||
// part of the same transaction.
|
||||
currentVersion, err := p.CurrentVersion(ctx)
|
||||
dbVersion, err := p.GetDBVersion(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if currentVersion != missing.Version {
|
||||
if dbVersion != missing.Version {
|
||||
return fmt.Errorf("error: missing migration:%d does not match current db version:%d",
|
||||
currentVersion, missing.Version)
|
||||
dbVersion, missing.Version)
|
||||
}
|
||||
|
||||
lookupApplied[missing.Version] = true
|
||||
|
|
Loading…
Reference in New Issue