Skip to content

Commit

Permalink
Migration validate version should not create schema_migration table o…
Browse files Browse the repository at this point in the history
…n check (#953)
  • Loading branch information
nopcoder authored Nov 24, 2020
1 parent cbf77cf commit 6f8a0fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 1 addition & 2 deletions cmd/lakefs/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"syscall"
"time"

"github.com/treeverse/lakefs/catalog/mvcc"

"github.com/dlmiddlecote/sqlstats"
"github.com/golang-migrate/migrate/v4"
"github.com/prometheus/client_golang/prometheus"
Expand All @@ -21,6 +19,7 @@ import (
"github.com/treeverse/lakefs/auth"
"github.com/treeverse/lakefs/auth/crypt"
"github.com/treeverse/lakefs/block/factory"
"github.com/treeverse/lakefs/catalog/mvcc"
"github.com/treeverse/lakefs/config"
"github.com/treeverse/lakefs/db"
"github.com/treeverse/lakefs/dedup"
Expand Down
13 changes: 12 additions & 1 deletion db/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"

"github.com/golang-migrate/migrate/v4"
_ "github.com/golang-migrate/migrate/v4/database/postgres"
"github.com/golang-migrate/migrate/v4/database/postgres"
"github.com/golang-migrate/migrate/v4/source"
"github.com/golang-migrate/migrate/v4/source/httpfs"
"github.com/rakyll/statik/fs"
Expand Down Expand Up @@ -176,6 +176,17 @@ func MigrateTo(p params.Database, version uint, force bool) error {
}

func MigrateVersion(params params.Database) (uint, bool, error) {
// validate that default migrations table exists with information - a workaround
// so we will not create the migration table as the package will ensure the table exists
dbPool := BuildDatabaseConnection(params)
defer dbPool.Close()
var rows int
err := dbPool.Get(&rows, `SELECT COUNT(*) FROM `+postgres.DefaultMigrationsTable)
if err != nil || rows == 0 {
return 0, false, migrate.ErrNilVersion
}

// get version from migrate
m, err := getMigrate(params)
if err != nil {
return 0, false, err
Expand Down

0 comments on commit 6f8a0fe

Please sign in to comment.