Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: simplify migrator (#15496)

Danny Xucf8bc1165018
diff --git a/backend/migrator/migrator.go b/backend/migrator/migrator.go
index 38cba11121..561cd59ec4 100644
--- a/backend/migrator/migrator.go
+++ b/backend/migrator/migrator.go
@@ -8,7 +8,6 @@ import (
"fmt"
"io/fs"
"log/slog"
- "path/filepath"
"sort"
"strconv"
"strings"
@@ -17,124 +16,31 @@ import (
"github.com/pkg/errors"
)
+const latestSchemaFileName = "migration/LATEST.sql"
+
//go:embed migration
var migrationFS embed.FS
// MigrateSchema migrates the schema for metadata database.
-func MigrateSchema(ctx context.Context, db *sql.DB) (*semver.Version, error) {
- conn, err := db.Conn(ctx)
- if err != nil {
- return nil, err
- }
- defer conn.Close()
-
- // Calculate prod cutoffSchemaVersion.
- cutoffSchemaVersion, err := getProdCutoffVersion()
+func MigrateSchema(ctx context.Context, db *sql.DB) error {
+ files, err := getSortedVersionedFiles()
if err != nil {
- return nil, errors.Wrapf(err, "failed to get cutoff version")
- }
- slog.Info(fmt.Sprintf("The prod cutoff schema version: %s", cutoffSchemaVersion))
- if err := initializeSchema(ctx, conn, cutoffSchemaVersion); err != nil {
- return nil, err
- }
-
- if err := backfillSchemaObjectOwner(ctx, conn); err != nil {
- return nil, err
- }
- var c int
- err = conn.QueryRowContext(ctx, "SELECT count(1) FROM instance_change_history WHERE database_id IS NOT NULL").Scan(&c)
- if err == nil && c > 0 {
- return nil, errors.Errorf("Must upgrade to Bytebase 3.3.1 first")
- }
- if _, err := conn.ExecContext(ctx, `
- ALTER TABLE instance_change_history
- DROP COLUMN IF EXISTS row_status,
- DROP COLUMN IF EXISTS creator_id,
- DROP COLUMN IF EXISTS updater_id,
- DROP COLUMN IF EXISTS created_ts,
- DROP COLUMN IF EXISTS updated_ts,
- DROP COLUMN IF EXISTS instance_id,
- DROP COLUMN IF EXISTS database_id,
- DROP COLUMN IF EXISTS project_id,
- DROP COLUMN IF EXISTS issue_id,
- DROP COLUMN IF EXISTS release_version,
- DROP COLUMN IF EXISTS sequence,
- DROP COLUMN IF EXISTS source,
- DROP COLUMN IF EXISTS type,
- DROP COLUMN IF EXISTS description,
- DROP COLUMN IF EXISTS sheet_id,
- DROP COLUMN IF EXISTS statement,
- DROP COLUMN IF EXISTS schema,
- DROP COLUMN IF EXISTS schema_prev,
- DROP COLUMN IF EXISTS payload;
- CREATE UNIQUE INDEX IF NOT EXISTS idx_instance_change_history_unique_version ON instance_change_history (version);`); err != nil {
- return nil, err
- }
- var hasStatus bool
- if err := conn.QueryRowContext(ctx, "SELECT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'instance_change_history' AND column_name = 'status')").Scan(&hasStatus); err != nil {
- return nil, err
- }
- if hasStatus {
- if _, err := conn.ExecContext(ctx, `
- DELETE FROM instance_change_history WHERE status = 'FAILED';
- UPDATE instance_change_history
- SET
- version = ARRAY_TO_STRING(
- (STRING_TO_ARRAY(
- SUBSTRING(version, 0, 15),
- '.'
- )::integer[])::text[],
- '.'
- )
- WHERE version LIKE '%-%';`); err != nil {
- return nil, err
- }
- }
- if _, err := conn.ExecContext(ctx, `
- ALTER TABLE instance_change_history
- DROP COLUMN IF EXISTS status,
- DROP COLUMN IF EXISTS execution_duration_ns;`); err != nil {
- return nil, err
- }
-
- verBefore, err := getLatestMigrationVersion(ctx, conn)
- if err != nil {
- return nil, errors.Wrap(err, "failed to get current schema version")
- }
-
- if _, err := migrate(ctx, conn, *verBefore); err != nil {
- return nil, errors.Wrap(err, "failed to migrate")
+ return err
}
- verAfter, err := getLatestMigrationVersion(ctx, conn)
+ conn, err := db.Conn(ctx)
if err != nil {
- return nil, errors.Wrap(err, "failed to get current schema version")
+ return err
}
- slog.Info(fmt.Sprintf("Current schema version after migration: %s", verAfter))
-
- return verAfter, nil
-}
+ defer conn.Close()
-func initializeSchema(ctx context.Context, conn *sql.Conn, cutoffSchemaVersion semver.Version) error {
- // We use environment table to determine whether we've initialized the schema.
- var exists bool
+ var ok bool
if err := conn.QueryRowContext(ctx,
`SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'environment')`,
- ).Scan(&exists); err != nil {
+ ).Scan(&ok); err != nil {
return err
}
- if exists {
- return nil
- }
- slog.Info("The database schema has not been setup.")
-
- latestSchemaPath := fmt.Sprintf("migration/%s", latestSchemaFile)
- buf, err := migrationFS.ReadFile(latestSchemaPath)
- if err != nil {
- return errors.Wrapf(err, "failed to read latest schema %q", latestSchemaPath)
- }
- version := cutoffSchemaVersion.String()
// Set role to database owner so that the schema owner and database owner are consistent.
owner, err := getCurrentDatabaseOwner(ctx, conn)
if err != nil {
@@ -144,226 +50,110 @@ func initializeSchema(ctx context.Context, conn *sql.Conn, cutoffSchemaVersion s
return err
}
- if err := executeMigration(ctx, conn, string(buf), version); err != nil {
- return err
- }
- slog.Info(fmt.Sprintf("Completed database initial migration with version %s.", cutoffSchemaVersion))
- return nil
-}
-
-// getCurrentDatabaseOwner gets the role of the current database.
-func getCurrentDatabaseOwner(ctx context.Context, conn *sql.Conn) (string, error) {
- const query = `
- SELECT
- u.rolname
- FROM
- pg_roles AS u JOIN pg_database AS d ON (d.datdba = u.oid)
- WHERE
- d.datname = current_database();
- `
- var owner string
- if err := conn.QueryRowContext(ctx, query).Scan(&owner); err != nil {
- return "", err
- }
- return owner, nil
-}
-
-func getCurrentUser(ctx context.Context, conn *sql.Conn) (string, error) {
- row := conn.QueryRowContext(ctx, "SELECT current_user;")
- var user string
- if err := row.Scan(&user); err != nil {
- return "", err
- }
- return user, nil
-}
-
-func backfillSchemaObjectOwner(ctx context.Context, conn *sql.Conn) error {
- currentUser, err := getCurrentUser(ctx, conn)
- if err != nil {
- return err
- }
- databaseOwner, err := getCurrentDatabaseOwner(ctx, conn)
- if err != nil {
- return err
- }
- if currentUser == databaseOwner {
+ latestVersion := files[len(files)-1].version.String()
+ // Initialize the latest schema.
+ if !ok {
+ buf, err := migrationFS.ReadFile(latestSchemaFileName)
+ if err != nil {
+ return errors.Wrapf(err, "failed to read latest schema %q", latestSchemaFileName)
+ }
+ if err := executeMigration(ctx, conn, string(buf), latestVersion); err != nil {
+ return err
+ }
+ slog.Info(fmt.Sprintf("Initialized database schema with version %s.", latestVersion))
return nil
}
- if _, err := conn.ExecContext(ctx, fmt.Sprintf("reassign owned by %s to %s;", currentUser, databaseOwner)); err != nil {
+
+ if err := backfill(ctx, conn); err != nil {
return err
}
- return nil
-}
-
-const (
- latestSchemaFile = "LATEST.sql"
-)
-
-func migrate(ctx context.Context, conn *sql.Conn, curVer semver.Version) (bool, error) {
- slog.Info("Apply database migration if needed...")
- slog.Info(fmt.Sprintf("Current schema version before migration: %s", curVer))
- // Apply migrations if needed.
- retVersion := curVer
- names, err := fs.Glob(migrationFS, "migration/*")
+ latestDatabaseVersion, err := getLatestDatabaseVersion(ctx, conn)
if err != nil {
- return false, err
+ return err
}
-
- minorVersions, err := getMinorMigrationVersions(names, curVer)
- if err != nil {
- return false, err
+ if latestDatabaseVersion == nil {
+ return errors.New("the latest database version is not found")
}
- for _, minorVersion := range minorVersions {
- slog.Info(fmt.Sprintf("Starting minor version migration cycle from %s ...", minorVersion))
- names, err := fs.Glob(migrationFS, fmt.Sprintf("migration/%d.%d/*.sql", minorVersion.Major, minorVersion.Minor))
- if err != nil {
- return false, err
- }
- patchVersions, err := getPatchVersions(minorVersion, curVer, names)
- if err != nil {
- return false, err
+ for _, f := range files {
+ if f.version.LE(*latestDatabaseVersion) {
+ continue
}
- for _, pv := range patchVersions {
- buf, err := fs.ReadFile(migrationFS, pv.filename)
- if err != nil {
- return false, errors.Wrapf(err, "failed to read migration file %q", pv.filename)
- }
- slog.Info(fmt.Sprintf("Migrating %s...", pv.version))
- version := pv.version.String()
- if err := executeMigration(ctx, conn, string(buf), version); err != nil {
- return false, err
- }
- retVersion = pv.version
+ buf, err := fs.ReadFile(migrationFS, f.path)
+ if err != nil {
+ return errors.Wrapf(err, "failed to read file %q", f.path)
}
- if retVersion.EQ(curVer) {
- slog.Info(fmt.Sprintf("Database schema is at version %s; nothing to migrate.", curVer))
- } else {
- slog.Info(fmt.Sprintf("Completed database migration from version %s to %s.", curVer, retVersion))
+ version := f.version.String()
+ slog.Info(fmt.Sprintf("Migrating %s.", version))
+ if err := executeMigration(ctx, conn, string(buf), version); err != nil {
+ return err
}
}
- return len(minorVersions) > 0, nil
-}
-
-func getProdCutoffVersion() (semver.Version, error) {
- minorPathPrefix := "migration/*"
- names, err := fs.Glob(migrationFS, minorPathPrefix)
- if err != nil {
- return semver.Version{}, err
- }
-
- versions, err := getMinorVersions(names)
- if err != nil {
- return semver.Version{}, err
- }
- if len(versions) == 0 {
- return semver.Version{}, errors.Errorf("migration path %s has no minor version", minorPathPrefix)
- }
- minorVersion := versions[len(versions)-1]
-
- patchPathPrefix := fmt.Sprintf("migration/%d.%d", minorVersion.Major, minorVersion.Minor)
- names, err = fs.Glob(migrationFS, fmt.Sprintf("%s/*.sql", patchPathPrefix))
- if err != nil {
- return semver.Version{}, err
- }
- patchVersions, err := getPatchVersions(minorVersion, semver.Version{} /* currentVersion */, names)
- if err != nil {
- return semver.Version{}, err
- }
- if len(patchVersions) == 0 {
- return semver.Version{}, errors.Errorf("migration path %s has no patch version", patchPathPrefix)
- }
- return patchVersions[len(patchVersions)-1].version, nil
+ slog.Info(fmt.Sprintf("Current schema version: %s", latestVersion))
+ return nil
}
-type patchVersion struct {
- version semver.Version
- filename string
+type versionedFile struct {
+ version *semver.Version
+ path string
}
-// getPatchVersions gets the patch versions above the current version in a minor version directory.
-func getPatchVersions(minorVersion semver.Version, currentVersion semver.Version, names []string) ([]patchVersion, error) {
- var patchVersions []patchVersion
- for _, name := range names {
- baseName := filepath.Base(name)
- parts := strings.Split(baseName, "##")
- if len(parts) != 2 {
- return nil, errors.Errorf("migration filename %q should include '##'", name)
- }
- patch, err := strconv.ParseInt(parts[0], 10, 64)
+func getSortedVersionedFiles() ([]versionedFile, error) {
+ var files []versionedFile
+ if err := fs.WalkDir(migrationFS, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
- return nil, errors.Wrapf(err, "migration filename prefix %q should be four digits integer such as '0000'", parts[0])
+ return err
}
- version := minorVersion
- version.Patch = uint64(patch)
- if version.LE(currentVersion) {
- continue
+ if d.IsDir() {
+ return nil
+ }
+ if path == latestSchemaFileName {
+ return nil
}
- patchVersions = append(patchVersions,
- patchVersion{
- version: version,
- filename: name,
- },
- )
- }
- if len(patchVersions) == 0 {
- return nil, nil
+ v, err := getVersionFromPath(path)
+ if err != nil {
+ return err
+ }
+ files = append(files, versionedFile{
+ version: v,
+ path: path,
+ })
+ return nil
+ }); err != nil {
+ return nil, err
}
- // Sort patch version in ascending order.
- sort.Slice(patchVersions, func(i, j int) bool {
- return patchVersions[i].version.LT(patchVersions[j].version)
+ sort.Slice(files, func(i, j int) bool {
+ return files[i].version.LT(*files[j].version)
})
- return patchVersions, nil
+ return files, nil
}
-// getMinorMigrationVersions gets all the prod minor versions since currentVersion (included).
-func getMinorMigrationVersions(names []string, currentVersion semver.Version) ([]semver.Version, error) {
- versions, err := getMinorVersions(names)
- if err != nil {
- return nil, err
+func getVersionFromPath(path string) (*semver.Version, error) {
+ // migration/3.5/0000##vcs.sql
+ s := strings.TrimPrefix(path, "migration/")
+ splits := strings.Split(s, "/")
+ if len(splits) != 2 {
+ return nil, errors.Errorf("invalid migration path %q", path)
}
-
- // We should still include the version with the same minor version with currentVersion in case we have missed some patches.
- currentVersion.Patch = 0
-
- var migrateVersions []semver.Version
- for _, version := range versions {
- // If the migration version is less than to the current version, we will skip the migration since it's already applied.
- // We should still double check the current version in case there's any patch needed.
- if version.LT(currentVersion) {
- slog.Debug(fmt.Sprintf("Skip migration %s; the current schema version %s is higher.", version, currentVersion))
- continue
- }
- migrateVersions = append(migrateVersions, version)
+ splits2 := strings.Split(splits[1], "##")
+ if len(splits2) != 2 {
+ return nil, errors.Errorf("invalid migration path %q", path)
+ }
+ patch, err := strconv.ParseInt(splits2[0], 10, 64)
+ if err != nil {
+ return nil, errors.Wrapf(err, "migration filename prefix %q should be four digits integer such as '0000'", splits2[0])
}
- return migrateVersions, nil
-}
-// getMinorVersions returns the minor versions based on file names in the prod directory.
-func getMinorVersions(names []string) ([]semver.Version, error) {
- var versions []semver.Version
- for _, name := range names {
- baseName := filepath.Base(name)
- if baseName == latestSchemaFile {
- continue
- }
- // Convert minor version to semantic version format, e.g. "1.12" will be "1.12.0".
- s := fmt.Sprintf("%s.0", baseName)
- v, err := semver.Make(s)
- if err != nil {
- return nil, errors.Wrapf(err, "invalid migration file path %q", name)
- }
- versions = append(versions, v)
+ v := fmt.Sprintf("%s.%d", splits[0], patch)
+ version, err := semver.Parse(v)
+ if err != nil {
+ return nil, errors.Wrapf(err, "invalid version %q", v)
}
- // Sort the migration semantic version in ascending order.
- sort.Slice(versions, func(i, j int) bool {
- return versions[i].LT(versions[j])
- })
- return versions, nil
+ return &version, nil
}
func executeMigration(ctx context.Context, conn *sql.Conn, statement string, version string) error {
@@ -386,7 +176,7 @@ func executeMigration(ctx context.Context, conn *sql.Conn, statement string, ver
return txn.Commit()
}
-func getLatestMigrationVersion(ctx context.Context, conn *sql.Conn) (*semver.Version, error) {
+func getLatestDatabaseVersion(ctx context.Context, conn *sql.Conn) (*semver.Version, error) {
query := `SELECT version FROM instance_change_history ORDER BY id DESC`
var v string
@@ -403,3 +193,79 @@ func getLatestMigrationVersion(ctx context.Context, conn *sql.Conn) (*semver.Ver
}
return &version, nil
}
+
+// getCurrentDatabaseOwner gets the role of the current database.
+func getCurrentDatabaseOwner(ctx context.Context, conn *sql.Conn) (string, error) {
+ const query = `
+ SELECT
+ u.rolname
+ FROM
+ pg_roles AS u JOIN pg_database AS d ON (d.datdba = u.oid)
+ WHERE
+ d.datname = current_database();
+ `
+ var owner string
+ if err := conn.QueryRowContext(ctx, query).Scan(&owner); err != nil {
+ return "", err
+ }
+ return owner, nil
+}
+
+func backfill(ctx context.Context, conn *sql.Conn) error {
+ var c int
+ err := conn.QueryRowContext(ctx, "SELECT count(1) FROM instance_change_history WHERE database_id IS NOT NULL").Scan(&c)
+ if err == nil && c > 0 {
+ return errors.Errorf("Must upgrade to Bytebase 3.3.1 first")
+ }
+ if _, err := conn.ExecContext(ctx, `
+ ALTER TABLE instance_change_history
+ DROP COLUMN IF EXISTS row_status,
+ DROP COLUMN IF EXISTS creator_id,
+ DROP COLUMN IF EXISTS updater_id,
+ DROP COLUMN IF EXISTS created_ts,
+ DROP COLUMN IF EXISTS updated_ts,
+ DROP COLUMN IF EXISTS instance_id,
+ DROP COLUMN IF EXISTS database_id,
+ DROP COLUMN IF EXISTS project_id,
+ DROP COLUMN IF EXISTS issue_id,
+ DROP COLUMN IF EXISTS release_version,
+ DROP COLUMN IF EXISTS sequence,
+ DROP COLUMN IF EXISTS source,
+ DROP COLUMN IF EXISTS type,
+ DROP COLUMN IF EXISTS description,
+ DROP COLUMN IF EXISTS sheet_id,
+ DROP COLUMN IF EXISTS statement,
+ DROP COLUMN IF EXISTS schema,
+ DROP COLUMN IF EXISTS schema_prev,
+ DROP COLUMN IF EXISTS payload;
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_instance_change_history_unique_version ON instance_change_history (version);`); err != nil {
+ return err
+ }
+ var hasStatus bool
+ if err := conn.QueryRowContext(ctx, "SELECT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name = 'instance_change_history' AND column_name = 'status')").Scan(&hasStatus); err != nil {
+ return err
+ }
+ if hasStatus {
+ if _, err := conn.ExecContext(ctx, `
+ DELETE FROM instance_change_history WHERE status = 'FAILED';
+ UPDATE instance_change_history
+ SET
+ version = ARRAY_TO_STRING(
+ (STRING_TO_ARRAY(
+ SUBSTRING(version, 0, 15),
+ '.'
+ )::integer[])::text[],
+ '.'
+ )
+ WHERE version LIKE '%-%';`); err != nil {
+ return err
+ }
+ }
+ if _, err := conn.ExecContext(ctx, `
+ ALTER TABLE instance_change_history
+ DROP COLUMN IF EXISTS status,
+ DROP COLUMN IF EXISTS execution_duration_ns;`); err != nil {
+ return err
+ }
+ return nil
+}
diff --git a/backend/migrator/migrator_test.go b/backend/migrator/migrator_test.go
index 042059a397..4187220ef4 100644
--- a/backend/migrator/migrator_test.go
+++ b/backend/migrator/migrator_test.go
@@ -1,7 +1,6 @@
package migrator
import (
- "fmt"
"testing"
"github.com/blang/semver/v4"
@@ -10,128 +9,14 @@ import (
_ "github.com/bytebase/bytebase/backend/plugin/db/pg"
)
-func TestGetMinorMigrationVersions(t *testing.T) {
- names := []string{latestSchemaFile, "1.0", "1.1", "1.2", "1.3", "1.4"}
-
- tests := []struct {
- names []string
- currentVersion semver.Version
- want []semver.Version
- }{
- {
- names: names,
- currentVersion: semver.MustParse("1.0.0"),
- want: []semver.Version{semver.MustParse("1.0.0"), semver.MustParse("1.1.0"), semver.MustParse("1.2.0"), semver.MustParse("1.3.0"), semver.MustParse("1.4.0")},
- },
- {
- names: names,
- currentVersion: semver.MustParse("1.3.0"),
- want: []semver.Version{semver.MustParse("1.3.0"), semver.MustParse("1.4.0")},
- },
- {
- names: names,
- currentVersion: semver.MustParse("1.0.3"),
- want: []semver.Version{semver.MustParse("1.0.0"), semver.MustParse("1.1.0"), semver.MustParse("1.2.0"), semver.MustParse("1.3.0"), semver.MustParse("1.4.0")},
- },
- {
- names: names,
- currentVersion: semver.MustParse("1.2.2"),
- want: []semver.Version{semver.MustParse("1.2.0"), semver.MustParse("1.3.0"), semver.MustParse("1.4.0")},
- },
- }
-
- for _, test := range tests {
- migrateVersions, _ := getMinorMigrationVersions(test.names, test.currentVersion)
- require.Equal(t, test.want, migrateVersions)
- }
-}
-
-func TestGetMinorVersions(t *testing.T) {
- tests := []struct {
- names []string
- want []semver.Version
- }{
- {
- names: []string{fmt.Sprintf("migration/dev/%s", latestSchemaFile), "migration/release/1.1", "migration/release/1.0"},
- want: []semver.Version{semver.MustParse("1.0.0"), semver.MustParse("1.1.0")},
- },
- {
- names: []string{fmt.Sprintf("migration/dev/%s", latestSchemaFile)},
- want: nil,
- },
- }
-
- for _, test := range tests {
- got, _ := getMinorVersions(test.names)
- require.Equal(t, test.want, got)
- }
-}
-
-func TestGetPatchVersions(t *testing.T) {
- tests := []struct {
- names []string
- minorVersion semver.Version
- currentVersion semver.Version
- want []patchVersion
- errPart string
- }{
- {
- names: []string{"0000##hello.sql", "0001##world.sql"},
- minorVersion: semver.MustParse("1.1.0"),
- currentVersion: semver.MustParse("1.2.3"),
- want: nil,
- errPart: "",
- },
- {
- names: []string{"0000##hello.sql", "0001##world.sql"},
- minorVersion: semver.MustParse("1.1.0"),
- currentVersion: semver.MustParse("1.0.0"),
- want: []patchVersion{{semver.MustParse("1.1.0"), "0000##hello.sql"}, {semver.MustParse("1.1.1"), "0001##world.sql"}},
- errPart: "",
- },
- {
- names: []string{"0000##hello.sql", "0001##world.sql"},
- minorVersion: semver.MustParse("1.1.0"),
- currentVersion: semver.MustParse("1.1.0"),
- want: []patchVersion{{semver.MustParse("1.1.1"), "0001##world.sql"}},
- errPart: "",
- },
- {
- names: []string{},
- minorVersion: semver.MustParse("1.1.0"),
- currentVersion: semver.MustParse("1.0.0"),
- want: nil,
- errPart: "",
- },
- {
- names: []string{"0000_hello.sql"},
- minorVersion: semver.MustParse("1.1.0"),
- currentVersion: semver.MustParse("1.0.0"),
- want: nil,
- errPart: "should include '##'",
- },
- {
- names: []string{"00a0##hello.sql"},
- minorVersion: semver.MustParse("1.1.0"),
- currentVersion: semver.MustParse("1.0.0"),
- want: nil,
- errPart: "should be four digits integer",
- },
- }
-
- for _, test := range tests {
- got, err := getPatchVersions(test.minorVersion, test.currentVersion, test.names)
- if test.errPart == "" {
- require.NoError(t, err)
- } else {
- require.Contains(t, err.Error(), test.errPart)
- }
- require.Equal(t, test.want, got)
- }
+func TestLatestVersion(t *testing.T) {
+ files, err := getSortedVersionedFiles()
+ require.NoError(t, err)
+ require.Equal(t, semver.MustParse("3.5.14"), *files[len(files)-1].version)
}
-func TestGetCutoffVersion(t *testing.T) {
- releaseVersion, err := getProdCutoffVersion()
+func TestGetVersionFromPath(t *testing.T) {
+ v, err := getVersionFromPath("migration/3.5/0000##vcs.sql")
require.NoError(t, err)
- require.Equal(t, semver.MustParse("3.5.14"), releaseVersion)
+ require.Equal(t, *v, semver.MustParse("3.5.0"))
}
diff --git a/backend/server/server.go b/backend/server/server.go
index f9ddadcd40..ca3e610dc4 100644
--- a/backend/server/server.go
+++ b/backend/server/server.go
@@ -169,7 +169,7 @@ func NewServer(ctx context.Context, profile *config.Profile) (*Server, error) {
if err := demo.LoadDemoDataIfNeeded(ctx, stores, profile.DemoName); err != nil {
return nil, errors.Wrapf(err, "failed to load demo data")
}
- if _, err := migrator.MigrateSchema(ctx, stores.GetDB()); err != nil {
+ if err := migrator.MigrateSchema(ctx, stores.GetDB()); err != nil {
return nil, err
}
}