Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavlo Strokov <pstrokov@gitlab.com>2021-10-19 15:02:52 +0300
committerPavlo Strokov <pstrokov@gitlab.com>2021-10-27 13:38:59 +0300
commit7eda30fbc8bfc6bfde5bfee21d52f2ab5c7d02b9 (patch)
treeb0fa6f54e69950c9570ca5e8061652a6aa7dc2c0
parentd99f9cbac9164647666f1778eb912568c261813d (diff)
sql: List of migrations provided from outside
To pre-populate database with some data and run migrations on top of it we should have ability to inject additional migrations. This change extends 'Migrate' function to accept list of migrations. All callers now use 'migrations.All()' list, but it will be extended for the tests in upcoming commit.
-rw-r--r--cmd/praefect/subcmd.go3
-rw-r--r--internal/praefect/datastore/glsql/postgres.go4
-rw-r--r--internal/praefect/datastore/glsql/testing.go5
3 files changed, 7 insertions, 5 deletions
diff --git a/cmd/praefect/subcmd.go b/cmd/praefect/subcmd.go
index a85f0b772..83afe3d52 100644
--- a/cmd/praefect/subcmd.go
+++ b/cmd/praefect/subcmd.go
@@ -16,6 +16,7 @@ import (
"gitlab.com/gitlab-org/gitaly/v14/internal/praefect/config"
"gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore"
"gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore/glsql"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore/migrations"
"google.golang.org/grpc"
)
@@ -125,7 +126,7 @@ func (s *sqlMigrateSubcommand) Exec(flags *flag.FlagSet, conf config.Config) err
}
defer clean()
- n, err := glsql.Migrate(db, s.ignoreUnknown)
+ n, err := glsql.Migrate(db, s.ignoreUnknown, migrations.All())
if err != nil {
return fmt.Errorf("%s: fail: %v", subCmd, err)
}
diff --git a/internal/praefect/datastore/glsql/postgres.go b/internal/praefect/datastore/glsql/postgres.go
index 4b5efcd86..28a80306a 100644
--- a/internal/praefect/datastore/glsql/postgres.go
+++ b/internal/praefect/datastore/glsql/postgres.go
@@ -28,14 +28,14 @@ func OpenDB(conf config.DB) (*sql.DB, error) {
}
// Migrate will apply all pending SQL migrations.
-func Migrate(db *sql.DB, ignoreUnknown bool) (int, error) {
+func Migrate(db *sql.DB, ignoreUnknown bool, mgs []*migrate.Migration) (int, error) {
migrationSet := migrate.MigrationSet{
IgnoreUnknown: ignoreUnknown,
TableName: migrations.MigrationTableName,
}
migrationSource := &migrate.MemoryMigrationSource{
- Migrations: migrations.All(),
+ Migrations: mgs,
}
return migrationSet.Exec(db, "postgres", migrationSource, migrate.Up)
diff --git a/internal/praefect/datastore/glsql/testing.go b/internal/praefect/datastore/glsql/testing.go
index 915576985..9dd9e417e 100644
--- a/internal/praefect/datastore/glsql/testing.go
+++ b/internal/praefect/datastore/glsql/testing.go
@@ -16,6 +16,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v14/internal/praefect/config"
+ "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/datastore/migrations"
)
const (
@@ -215,7 +216,7 @@ func initPraefectTestDB(t testing.TB, database string) *sql.DB {
require.NoErrorf(t, templateDB.Close(), "release connection to the %q database", templateDBConf.DBName)
}()
- if _, err := Migrate(templateDB, false); err != nil {
+ if _, err := Migrate(templateDB, false, migrations.All()); err != nil {
// If database has unknown migration we try to re-create template database with
// current migration. It may be caused by other code changes done in another branch.
if pErr := (*migrate.PlanError)(nil); errors.As(err, &pErr) {
@@ -231,7 +232,7 @@ func initPraefectTestDB(t testing.TB, database string) *sql.DB {
defer func() {
require.NoErrorf(t, remigrateTemplateDB.Close(), "release connection to the %q database", templateDBConf.DBName)
}()
- _, err = Migrate(remigrateTemplateDB, false)
+ _, err = Migrate(remigrateTemplateDB, false, migrations.All())
require.NoErrorf(t, err, "failed to run database migration on %q", praefectTemplateDatabase)
} else {
require.NoErrorf(t, err, "failed to run database migration on %q", praefectTemplateDatabase)