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-26 12:45:55 +0300
commit755d8a6dbc7d9c69f8859d42db383b753a4bb4d8 (patch)
tree973c3cf12b9dc160394385e6f89d521b481b44b1
parent1a2a24e98b6769834ee36eaacab60e1b3237a684 (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 616e1f967..6ca8bec52 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 (
@@ -237,7 +238,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) {
@@ -253,7 +254,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)