Skip to content

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

chore: rename engine to source in migration history table since it's better indicating whether the migration comes from (#645)

Danny Xufc77156a493b
diff --git a/api/instance.go b/api/instance.go
index de4be270bd..baacada757 100644
--- a/api/instance.go
+++ b/api/instance.go
@@ -137,7 +137,7 @@ type MigrationHistory struct {
// Domain specific fields
ReleaseVersion string `jsonapi:"attr,releaseVersion"`
Database string `jsonapi:"attr,database"`
- Engine db.MigrationEngine `jsonapi:"attr,engine"`
+ Source db.MigrationSource `jsonapi:"attr,source"`
Type db.MigrationType `jsonapi:"attr,type"`
Status db.MigrationStatus `jsonapi:"attr,status"`
Version string `jsonapi:"attr,version"`
diff --git a/frontend/src/types/instance.ts b/frontend/src/types/instance.ts
index cb84a7730d..d3bae36a25 100644
--- a/frontend/src/types/instance.ts
+++ b/frontend/src/types/instance.ts
@@ -103,7 +103,7 @@ export type InstanceMigration = {
error: string;
};
-export type MigrationEngine = "UI" | "VCS";
+export type MigrationSource = "UI" | "VCS" | "LIBRARY";
export type MigrationType = "BASELINE" | "MIGRATE" | "BRANCH" | "DATA";
@@ -121,7 +121,7 @@ export type MigrationHistory = {
updatedTs: number;
releaseVersion: string;
database: string;
- engine: MigrationEngine;
+ source: MigrationSource;
type: MigrationType;
status: MigrationStatus;
version: string;
diff --git a/frontend/src/views/MigrationHistoryDetail.vue b/frontend/src/views/MigrationHistoryDetail.vue
index 1e38b0b35a..05607f8b89 100644
--- a/frontend/src/views/MigrationHistoryDetail.vue
+++ b/frontend/src/views/MigrationHistoryDetail.vue
@@ -14,7 +14,7 @@
</h1>
</div>
<p class="text-control">
- {{ migrationHistory.engine }} {{ migrationHistory.type }} -
+ {{ migrationHistory.source }} {{ migrationHistory.type }} -
{{ migrationHistory.description }}
</p>
<dl
diff --git a/plugin/db/clickhouse/clickhouse.go b/plugin/db/clickhouse/clickhouse.go
index e2c62c6822..38a62f9d5d 100644
--- a/plugin/db/clickhouse/clickhouse.go
+++ b/plugin/db/clickhouse/clickhouse.go
@@ -410,13 +410,13 @@ func (driver *Driver) SetupMigrationIfNeeded(ctx context.Context) error {
}
// CheckDuplicateVersion will check whether the version is already applied.
-func (Driver) CheckDuplicateVersion(ctx context.Context, tx *sql.Tx, namespace string, engine db.MigrationEngine, version string) (bool, error) {
+func (Driver) CheckDuplicateVersion(ctx context.Context, tx *sql.Tx, namespace string, source db.MigrationSource, version string) (bool, error) {
const checkDuplicateVersionQuery = `
SELECT 1 FROM bytebase.migration_history
- WHERE namespace = $1 AND engine= $2 AND version = $3
+ WHERE namespace = $1 AND source = $2 AND version = $3
`
row, err := tx.QueryContext(ctx, checkDuplicateVersionQuery,
- namespace, engine.String(), version,
+ namespace, source.String(), version,
)
if err != nil {
return false, util.FormatErrorWithQuery(err, checkDuplicateVersionQuery)
@@ -430,13 +430,13 @@ func (Driver) CheckDuplicateVersion(ctx context.Context, tx *sql.Tx, namespace s
}
// CheckOutOfOrderVersion will return versions that are higher than the given version.
-func (Driver) CheckOutOfOrderVersion(ctx context.Context, tx *sql.Tx, namespace string, engine db.MigrationEngine, version string) (minVersionIfValid *string, err error) {
+func (Driver) CheckOutOfOrderVersion(ctx context.Context, tx *sql.Tx, namespace string, source db.MigrationSource, version string) (minVersionIfValid *string, err error) {
const checkOutofOrderVersionQuery = `
SELECT MIN(version) FROM bytebase.migration_history
- WHERE namespace = $1 AND engine = $2 AND version > $3
+ WHERE namespace = $1 AND source = $2 AND version > $3
`
row, err := tx.QueryContext(ctx, checkOutofOrderVersionQuery,
- namespace, engine.String(), version,
+ namespace, source.String(), version,
)
if err != nil {
return nil, util.FormatErrorWithQuery(err, checkOutofOrderVersionQuery)
@@ -522,7 +522,7 @@ func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int
release_version,
namespace,
sequence,
- engine,
+ source,
type,
status,
version,
@@ -564,7 +564,7 @@ func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int
m.ReleaseVersion,
m.Namespace,
sequence,
- m.Engine,
+ m.Source,
m.Type,
"PENDING",
m.Version,
@@ -629,7 +629,7 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Mig
release_version,
namespace,
sequence,
- engine,
+ source,
type,
status,
version,
diff --git a/plugin/db/clickhouse/clickhouse_migration_schema.sql b/plugin/db/clickhouse/clickhouse_migration_schema.sql
index b9137d00fb..04211d6354 100644
--- a/plugin/db/clickhouse/clickhouse_migration_schema.sql
+++ b/plugin/db/clickhouse/clickhouse_migration_schema.sql
@@ -19,9 +19,9 @@ CREATE TABLE bytebase.migration_history (
namespace TEXT NOT NULL,
-- Used to detect out of order migration together with 'namespace' and 'version' column.
sequence BIGINT UNSIGNED NOT NULL,
- -- We call it engine because maybe we could load history from other migration tool.
- -- Current allowed values are UI, VCS.
- engine TEXT NOT NULL,
+ -- We call it source because maybe we could load history from other migration tool.
+ -- Current allowed values are UI, VCS, LIBRARY.
+ source TEXT NOT NULL,
-- Current allowed values are BASELINE, MIGRATE, BRANCH, DATA.
type TEXT NOT NULL,
-- Current allowed values are PENDING, DONE, FAILED.
diff --git a/plugin/db/driver.go b/plugin/db/driver.go
index e8c6049f07..84fdd14e78 100644
--- a/plugin/db/driver.go
+++ b/plugin/db/driver.go
@@ -129,19 +129,19 @@ type DriverConfig struct {
type driverFunc func(DriverConfig) Driver
-// MigrationEngine is the migration engine.
-type MigrationEngine string
+// MigrationSource is the migration engine.
+type MigrationSource string
const (
- // UI is the migration engine type for UI.
- UI MigrationEngine = "UI"
- // VCS is the migration engine type for VCSUI.
- VCS MigrationEngine = "VCS"
- // LIBRARY is the migration engine type for LIBRARY.
- LIBRARY MigrationEngine = "LIBRARY"
+ // UI is the migration source type for UI.
+ UI MigrationSource = "UI"
+ // VCS is the migration source type for VCS.
+ VCS MigrationSource = "VCS"
+ // LIBRARY is the migration source type for LIBRARY.
+ LIBRARY MigrationSource = "LIBRARY"
)
-func (e MigrationEngine) String() string {
+func (e MigrationSource) String() string {
switch e {
case UI:
return "UI"
@@ -223,7 +223,7 @@ type MigrationInfo struct {
Namespace string
Database string
Environment string
- Engine MigrationEngine
+ Source MigrationSource
Type MigrationType
Status MigrationStatus
Description string
@@ -257,7 +257,7 @@ func ParseMigrationInfo(filePath string, filePathTemplate string) (*MigrationInf
}
mi := &MigrationInfo{
- Engine: VCS,
+ Source: VCS,
Type: Migrate,
}
matchList := myRegex.FindStringSubmatch(filePath)
@@ -327,7 +327,7 @@ type MigrationHistory struct {
ReleaseVersion string
Namespace string
Sequence int
- Engine MigrationEngine
+ Source MigrationSource
Type MigrationType
Status MigrationStatus
Version string
diff --git a/plugin/db/driver_test.go b/plugin/db/driver_test.go
index be47a308fe..0347e3620c 100644
--- a/plugin/db/driver_test.go
+++ b/plugin/db/driver_test.go
@@ -23,7 +23,7 @@ func TestParseMigrationInfo(t *testing.T) {
Namespace: "db1",
Database: "db1",
Environment: "",
- Engine: VCS,
+ Source: VCS,
Type: Migrate,
Description: "Create db1 schema migration",
Creator: "",
@@ -38,7 +38,7 @@ func TestParseMigrationInfo(t *testing.T) {
Namespace: "db foo_+-=/_#?!$.",
Database: "db foo_+-=/_#?!$.",
Environment: "",
- Engine: VCS,
+ Source: VCS,
Type: Migrate,
Description: "Create db foo_+-=/_#?!$. schema migration",
Creator: "",
@@ -53,7 +53,7 @@ func TestParseMigrationInfo(t *testing.T) {
Namespace: "db1",
Database: "db1",
Environment: "",
- Engine: VCS,
+ Source: VCS,
Type: Migrate,
Description: "Create db1 schema migration",
Creator: "",
@@ -68,7 +68,7 @@ func TestParseMigrationInfo(t *testing.T) {
Namespace: "db1",
Database: "db1",
Environment: "dev",
- Engine: VCS,
+ Source: VCS,
Type: Migrate,
Description: "Create db1 schema migration",
Creator: "",
@@ -83,7 +83,7 @@ func TestParseMigrationInfo(t *testing.T) {
Namespace: "db1",
Database: "db1",
Environment: "",
- Engine: VCS,
+ Source: VCS,
Type: Migrate,
Description: "Create t1",
Creator: "",
@@ -98,7 +98,7 @@ func TestParseMigrationInfo(t *testing.T) {
Namespace: "db1",
Database: "db1",
Environment: "",
- Engine: VCS,
+ Source: VCS,
Type: Migrate,
Description: "Create db1 schema migration",
Creator: "",
@@ -113,7 +113,7 @@ func TestParseMigrationInfo(t *testing.T) {
Namespace: "db1",
Database: "db1",
Environment: "",
- Engine: VCS,
+ Source: VCS,
Type: Baseline,
Description: "Create db1 baseline",
Creator: "",
@@ -128,7 +128,7 @@ func TestParseMigrationInfo(t *testing.T) {
Namespace: "db1",
Database: "db1",
Environment: "",
- Engine: VCS,
+ Source: VCS,
Type: Baseline,
Description: "Create t1",
Creator: "",
@@ -143,7 +143,7 @@ func TestParseMigrationInfo(t *testing.T) {
Namespace: "db_shop1",
Database: "db_shop1",
Environment: "",
- Engine: VCS,
+ Source: VCS,
Type: Baseline,
Description: "Create t1",
Creator: "",
@@ -158,7 +158,7 @@ func TestParseMigrationInfo(t *testing.T) {
Namespace: "db_shop1",
Database: "db_shop1",
Environment: "",
- Engine: VCS,
+ Source: VCS,
Type: Data,
Description: "Create db_shop1 data change",
Creator: "",
@@ -173,7 +173,7 @@ func TestParseMigrationInfo(t *testing.T) {
Namespace: "db_shop1",
Database: "db_shop1",
Environment: "",
- Engine: VCS,
+ Source: VCS,
Type: Data,
Description: "Fix customer info",
Creator: "",
diff --git a/plugin/db/mysql/mysql.go b/plugin/db/mysql/mysql.go
index c1586e1d84..0b20f675dc 100644
--- a/plugin/db/mysql/mysql.go
+++ b/plugin/db/mysql/mysql.go
@@ -591,13 +591,13 @@ func (driver *Driver) SetupMigrationIfNeeded(ctx context.Context) error {
}
// CheckDuplicateVersion will check whether the version is already applied.
-func (Driver) CheckDuplicateVersion(ctx context.Context, tx *sql.Tx, namespace string, engine db.MigrationEngine, version string) (bool, error) {
+func (Driver) CheckDuplicateVersion(ctx context.Context, tx *sql.Tx, namespace string, source db.MigrationSource, version string) (bool, error) {
const checkDuplicateVersionQuery = `
SELECT 1 FROM bytebase.migration_history
- WHERE namespace = ? AND engine = ? AND version = ?
+ WHERE namespace = ? AND source = ? AND version = ?
`
row, err := tx.QueryContext(ctx, checkDuplicateVersionQuery,
- namespace, engine.String(), version,
+ namespace, source.String(), version,
)
if err != nil {
return false, util.FormatErrorWithQuery(err, checkDuplicateVersionQuery)
@@ -611,13 +611,13 @@ func (Driver) CheckDuplicateVersion(ctx context.Context, tx *sql.Tx, namespace s
}
// CheckOutOfOrderVersion will return versions that are higher than the given version.
-func (Driver) CheckOutOfOrderVersion(ctx context.Context, tx *sql.Tx, namespace string, engine db.MigrationEngine, version string) (minVersionIfValid *string, err error) {
+func (Driver) CheckOutOfOrderVersion(ctx context.Context, tx *sql.Tx, namespace string, source db.MigrationSource, version string) (minVersionIfValid *string, err error) {
const checkOutofOrderVersionQuery = `
SELECT MIN(version) FROM bytebase.migration_history
- WHERE namespace = ? AND engine = ? AND version > ?
+ WHERE namespace = ? AND source = ? AND version > ?
`
row, err := tx.QueryContext(ctx, checkOutofOrderVersionQuery,
- namespace, engine.String(), version,
+ namespace, source.String(), version,
)
if err != nil {
return nil, util.FormatErrorWithQuery(err, checkOutofOrderVersionQuery)
@@ -702,7 +702,7 @@ func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int
release_version,
namespace,
sequence,
- engine,
+ source,
type,
status,
version,
@@ -722,7 +722,7 @@ func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int
m.ReleaseVersion,
m.Namespace,
sequence,
- m.Engine,
+ m.Source,
m.Type,
m.Version,
m.Description,
@@ -789,7 +789,7 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Mig
release_version,
namespace,
sequence,
- engine,
+ source,
type,
status,
version,
diff --git a/plugin/db/mysql/mysql_migration_schema.sql b/plugin/db/mysql/mysql_migration_schema.sql
index 9938c29a16..070527eb44 100644
--- a/plugin/db/mysql/mysql_migration_schema.sql
+++ b/plugin/db/mysql/mysql_migration_schema.sql
@@ -19,9 +19,9 @@ CREATE TABLE bytebase.migration_history (
namespace TEXT NOT NULL,
-- Used to detect out of order migration together with 'namespace' and 'version' column.
sequence BIGINT UNSIGNED NOT NULL,
- -- We call it engine because maybe we could load history from other migration tool.
- -- Current allowed values are UI, VCS.
- engine TEXT NOT NULL,
+ -- We call it source because maybe we could load history from other migration tool.
+ -- Current allowed values are UI, VCS, LIBRARY.
+ source TEXT NOT NULL,
-- Current allowed values are BASELINE, MIGRATE, BRANCH, DATA.
type TEXT NOT NULL,
-- Current allowed values are PENDING, DONE, FAILED.
@@ -45,8 +45,8 @@ CREATE TABLE bytebase.migration_history (
CREATE UNIQUE INDEX bytebase_idx_unique_migration_history_namespace_sequence ON bytebase.migration_history (namespace(256), sequence);
-CREATE UNIQUE INDEX bytebase_idx_unique_migration_history_namespace_engine_version ON bytebase.migration_history (namespace(256), engine(256), version(256));
+CREATE UNIQUE INDEX bytebase_idx_unique_migration_history_namespace_source_version ON bytebase.migration_history (namespace(256), source(256), version(256));
-CREATE INDEX bytebase_idx_migration_history_namespace_engine_type ON bytebase.migration_history(namespace(256), engine(256), type(256));
+CREATE INDEX bytebase_idx_migration_history_namespace_source_type ON bytebase.migration_history(namespace(256), source(256), type(256));
CREATE INDEX bytebase_idx_migration_history_namespace_created ON bytebase.migration_history(namespace(256), created_ts);
diff --git a/plugin/db/pg/pg.go b/plugin/db/pg/pg.go
index 940a109ba0..204fd59df2 100644
--- a/plugin/db/pg/pg.go
+++ b/plugin/db/pg/pg.go
@@ -651,13 +651,13 @@ func (driver *Driver) SetupMigrationIfNeeded(ctx context.Context) error {
}
// CheckDuplicateVersion will check whether the version is already applied.
-func (Driver) CheckDuplicateVersion(ctx context.Context, tx *sql.Tx, namespace string, engine db.MigrationEngine, version string) (bool, error) {
+func (Driver) CheckDuplicateVersion(ctx context.Context, tx *sql.Tx, namespace string, source db.MigrationSource, version string) (bool, error) {
const checkDuplicateVersionQuery = `
SELECT 1 FROM migration_history
- WHERE namespace = $1 AND engine = $2 AND version = $3
+ WHERE namespace = $1 AND source = $2 AND version = $3
`
row, err := tx.QueryContext(ctx, checkDuplicateVersionQuery,
- namespace, engine.String(), version,
+ namespace, source.String(), version,
)
if err != nil {
return false, util.FormatErrorWithQuery(err, checkDuplicateVersionQuery)
@@ -671,13 +671,13 @@ func (Driver) CheckDuplicateVersion(ctx context.Context, tx *sql.Tx, namespace s
}
// CheckOutOfOrderVersion will return versions that are higher than the given version.
-func (Driver) CheckOutOfOrderVersion(ctx context.Context, tx *sql.Tx, namespace string, engine db.MigrationEngine, version string) (minVersionIfValid *string, err error) {
+func (Driver) CheckOutOfOrderVersion(ctx context.Context, tx *sql.Tx, namespace string, source db.MigrationSource, version string) (minVersionIfValid *string, err error) {
const checkOutofOrderVersionQuery = `
SELECT MIN(version) FROM migration_history
- WHERE namespace = $1 AND engine = $2 AND version > $3
+ WHERE namespace = $1 AND source = $2 AND version > $3
`
row, err := tx.QueryContext(ctx, checkOutofOrderVersionQuery,
- namespace, engine.String(), version,
+ namespace, source.String(), version,
)
if err != nil {
return nil, util.FormatErrorWithQuery(err, checkOutofOrderVersionQuery)
@@ -762,7 +762,7 @@ func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int
release_version,
namespace,
sequence,
- engine,
+ source,
type,
status,
version,
@@ -784,7 +784,7 @@ func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int
m.ReleaseVersion,
m.Namespace,
sequence,
- m.Engine,
+ m.Source,
m.Type,
m.Version,
m.Description,
@@ -845,7 +845,7 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Mig
release_version,
namespace,
sequence,
- engine,
+ source,
type,
status,
version,
diff --git a/plugin/db/pg/pg_migration_schema.sql b/plugin/db/pg/pg_migration_schema.sql
index 7dd1097c3f..a2a5528902 100644
--- a/plugin/db/pg/pg_migration_schema.sql
+++ b/plugin/db/pg/pg_migration_schema.sql
@@ -19,9 +19,9 @@ CREATE TABLE migration_history (
namespace TEXT NOT NULL,
-- Used to detect out of order migration together with 'namespace' and 'version' column.
sequence BIGINT NOT NULL CHECK (sequence >= 0),
- -- We call it engine because maybe we could load history from other migration tool.
- -- Current allowed values are UI, VCS.
- engine TEXT NOT NULL,
+ -- We call it source because maybe we could load history from other migration tool.
+ -- Current allowed values are UI, VCS, LIBRARY.
+ source TEXT NOT NULL,
-- Current allowed values are BASELINE, MIGRATE, BRANCH, DATA.
type TEXT NOT NULL,
-- Current allowed values are PENDING, DONE, FAILED.
@@ -45,8 +45,8 @@ CREATE TABLE migration_history (
CREATE UNIQUE INDEX bytebase_idx_unique_migration_history_namespace_sequence ON migration_history (namespace, sequence);
-CREATE UNIQUE INDEX bytebase_idx_unique_migration_history_namespace_engine_version ON migration_history (namespace, engine, version);
+CREATE UNIQUE INDEX bytebase_idx_unique_migration_history_namespace_source_version ON migration_history (namespace, source, version);
-CREATE INDEX bytebase_idx_migration_history_namespace_engine_type ON migration_history(namespace, engine, type);
+CREATE INDEX bytebase_idx_migration_history_namespace_source_type ON migration_history(namespace, source, type);
CREATE INDEX bytebase_idx_migration_history_namespace_created ON migration_history(namespace, created_ts);
diff --git a/plugin/db/snowflake/snowflake.go b/plugin/db/snowflake/snowflake.go
index bbdb00631b..18cef39d99 100644
--- a/plugin/db/snowflake/snowflake.go
+++ b/plugin/db/snowflake/snowflake.go
@@ -584,13 +584,13 @@ func (driver *Driver) SetupMigrationIfNeeded(ctx context.Context) error {
}
// CheckDuplicateVersion will check whether the version is already applied.
-func (Driver) CheckDuplicateVersion(ctx context.Context, tx *sql.Tx, namespace string, engine db.MigrationEngine, version string) (bool, error) {
+func (Driver) CheckDuplicateVersion(ctx context.Context, tx *sql.Tx, namespace string, source db.MigrationSource, version string) (bool, error) {
const checkDuplicateVersionQuery = `
SELECT 1 FROM bytebase.public.migration_history
- WHERE namespace = ? AND engine = ? AND version = ?
+ WHERE namespace = ? AND source = ? AND version = ?
`
row, err := tx.QueryContext(ctx, checkDuplicateVersionQuery,
- namespace, engine.String(), version,
+ namespace, source.String(), version,
)
if err != nil {
return false, util.FormatErrorWithQuery(err, checkDuplicateVersionQuery)
@@ -604,13 +604,13 @@ func (Driver) CheckDuplicateVersion(ctx context.Context, tx *sql.Tx, namespace s
}
// CheckOutOfOrderVersion will return versions that are higher than the given version.
-func (Driver) CheckOutOfOrderVersion(ctx context.Context, tx *sql.Tx, namespace string, engine db.MigrationEngine, version string) (minVersionIfValid *string, err error) {
+func (Driver) CheckOutOfOrderVersion(ctx context.Context, tx *sql.Tx, namespace string, source db.MigrationSource, version string) (minVersionIfValid *string, err error) {
const checkOutofOrderVersionQuery = `
SELECT MIN(version) FROM bytebase.public.migration_history
- WHERE namespace = ? AND engine = ? AND version > ?
+ WHERE namespace = ? AND source = ? AND version > ?
`
row, err := tx.QueryContext(ctx, checkOutofOrderVersionQuery,
- namespace, engine.String(), version,
+ namespace, source.String(), version,
)
if err != nil {
return nil, util.FormatErrorWithQuery(err, checkOutofOrderVersionQuery)
@@ -695,7 +695,7 @@ func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int
release_version,
namespace,
sequence,
- engine,
+ source,
type,
status,
version,
@@ -739,7 +739,7 @@ func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int
m.ReleaseVersion,
m.Namespace,
sequence,
- m.Engine,
+ m.Source,
m.Type,
m.Version,
m.Description,
@@ -804,7 +804,7 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Mig
release_version,
namespace,
sequence,
- engine,
+ source,
type,
status,
version,
diff --git a/plugin/db/snowflake/snowflake_migration_schema.sql b/plugin/db/snowflake/snowflake_migration_schema.sql
index cc40191ccd..dd643049ce 100644
--- a/plugin/db/snowflake/snowflake_migration_schema.sql
+++ b/plugin/db/snowflake/snowflake_migration_schema.sql
@@ -19,9 +19,9 @@ CREATE TABLE bytebase.public.migration_history (
namespace TEXT NOT NULL,
-- Used to detect out of order migration together with 'namespace' and 'version' column.
sequence BIGINT NOT NULL,
- -- We call it engine because maybe we could load history from other migration tool.
- -- Current allowed values are UI, VCS.
- engine TEXT NOT NULL,
+ -- We call it source because maybe we could load history from other migration tool.
+ -- Current allowed values are UI, VCS, LIBRARY.
+ source TEXT NOT NULL,
-- Current allowed values are BASELINE, MIGRATE, BRANCH, DATA.
type TEXT NOT NULL,
-- Current allowed values are PENDING, DONE, FAILED.
diff --git a/plugin/db/sqlite/sqlite.go b/plugin/db/sqlite/sqlite.go
index f9815280d2..30f4db4dff 100644
--- a/plugin/db/sqlite/sqlite.go
+++ b/plugin/db/sqlite/sqlite.go
@@ -338,13 +338,13 @@ func (driver *Driver) SetupMigrationIfNeeded(ctx context.Context) error {
}
// CheckDuplicateVersion will check whether the version is already applied.
-func (Driver) CheckDuplicateVersion(ctx context.Context, tx *sql.Tx, namespace string, engine db.MigrationEngine, version string) (bool, error) {
+func (Driver) CheckDuplicateVersion(ctx context.Context, tx *sql.Tx, namespace string, source db.MigrationSource, version string) (bool, error) {
const checkDuplicateVersionQuery = `
SELECT 1 FROM bytebase_migration_history
- WHERE namespace = ? AND engine = ? AND version = ?
+ WHERE namespace = ? AND source = ? AND version = ?
`
row, err := tx.QueryContext(ctx, checkDuplicateVersionQuery,
- namespace, engine.String(), version,
+ namespace, source.String(), version,
)
if err != nil {
return false, util.FormatErrorWithQuery(err, checkDuplicateVersionQuery)
@@ -358,13 +358,13 @@ func (Driver) CheckDuplicateVersion(ctx context.Context, tx *sql.Tx, namespace s
}
// CheckOutOfOrderVersion will return versions that are higher than the given version.
-func (Driver) CheckOutOfOrderVersion(ctx context.Context, tx *sql.Tx, namespace string, engine db.MigrationEngine, version string) (minVersionIfValid *string, err error) {
+func (Driver) CheckOutOfOrderVersion(ctx context.Context, tx *sql.Tx, namespace string, source db.MigrationSource, version string) (minVersionIfValid *string, err error) {
const checkOutofOrderVersionQuery = `
SELECT MIN(version) FROM bytebase_migration_history
- WHERE namespace = ? AND engine = ? AND version > ?
+ WHERE namespace = ? AND source = ? AND version > ?
`
row, err := tx.QueryContext(ctx, checkOutofOrderVersionQuery,
- namespace, engine.String(), version,
+ namespace, source.String(), version,
)
if err != nil {
return nil, util.FormatErrorWithQuery(err, checkOutofOrderVersionQuery)
@@ -449,7 +449,7 @@ func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int
release_version,
namespace,
sequence,
- engine,
+ source,
type,
status,
version,
@@ -469,7 +469,7 @@ func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int
m.ReleaseVersion,
m.Namespace,
sequence,
- m.Engine,
+ m.Source,
m.Type,
m.Version,
m.Description,
@@ -536,7 +536,7 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Mig
release_version,
namespace,
sequence,
- engine,
+ source,
type,
status,
version,
diff --git a/plugin/db/sqlite/sqlite_migration_schema.sql b/plugin/db/sqlite/sqlite_migration_schema.sql
index e20d4890bd..230284fa49 100644
--- a/plugin/db/sqlite/sqlite_migration_schema.sql
+++ b/plugin/db/sqlite/sqlite_migration_schema.sql
@@ -13,9 +13,9 @@ CREATE TABLE bytebase_migration_history (
namespace TEXT NOT NULL,
-- Used to detect out of order migration together with 'namespace' and 'version' column.
sequence INTEGER UNSIGNED NOT NULL,
- -- We call it engine because maybe we could load history from other migration tool.
- -- Current allowed values are UI, VCS.
- engine TEXT NOT NULL,
+ -- We call it source because maybe we could load history from other migration tool.
+ -- Current allowed values are UI, VCS, LIBRARY.
+ source TEXT NOT NULL,
-- Current allowed values are BASELINE, MIGRATE, BRANCH, DATA.
type TEXT NOT NULL,
-- Current allowed values are PENDING, DONE, FAILED.
@@ -38,8 +38,8 @@ CREATE TABLE bytebase_migration_history (
CREATE UNIQUE INDEX bytebase_idx_unique_migration_history_namespace_sequence ON bytebase_migration_history (namespace, sequence);
-CREATE UNIQUE INDEX bytebase_idx_unique_migration_history_namespace_engine_version ON bytebase_migration_history (namespace, engine, version);
+CREATE UNIQUE INDEX bytebase_idx_unique_migration_history_namespace_source_version ON bytebase_migration_history (namespace, source, version);
-CREATE INDEX bytebase_idx_migration_history_namespace_engine_type ON bytebase_migration_history(namespace, engine, type);
+CREATE INDEX bytebase_idx_migration_history_namespace_source_type ON bytebase_migration_history(namespace, source, type);
CREATE INDEX bytebase_idx_migration_history_namespace_created ON bytebase_migration_history(namespace, created_ts);
diff --git a/plugin/db/util/driverutil.go b/plugin/db/util/driverutil.go
index 6df610f84d..48807cc0cf 100644
--- a/plugin/db/util/driverutil.go
+++ b/plugin/db/util/driverutil.go
@@ -113,9 +113,9 @@ func NeedsSetupMigrationSchema(ctx context.Context, sqldb *sql.DB, query string)
type MigrationExecutor interface {
db.Driver
// CheckDuplicateVersion will check whether the version is already applied.
- CheckDuplicateVersion(ctx context.Context, tx *sql.Tx, namespace string, engine db.MigrationEngine, version string) (isDuplicate bool, err error)
+ CheckDuplicateVersion(ctx context.Context, tx *sql.Tx, namespace string, source db.MigrationSource, version string) (isDuplicate bool, err error)
// CheckOutOfOrderVersion will return versions that are higher than the given version.
- CheckOutOfOrderVersion(ctx context.Context, tx *sql.Tx, namespace string, engine db.MigrationEngine, version string) (minVersionIfValid *string, err error)
+ CheckOutOfOrderVersion(ctx context.Context, tx *sql.Tx, namespace string, source db.MigrationSource, version string) (minVersionIfValid *string, err error)
// FindBaseline retruns true if any baseline is found.
FindBaseline(ctx context.Context, tx *sql.Tx, namespace string) (hasBaseline bool, err error)
// FindNextSequence will return the highest sequence number plus one.
@@ -201,14 +201,14 @@ func beginMigration(ctx context.Context, executor MigrationExecutor, m *db.Migra
// Phase 1 - Precheck before executing migration
// Check if the same migration version has alraedy been applied
- if duplicate, err := executor.CheckDuplicateVersion(ctx, tx, m.Namespace, m.Engine, m.Version); err != nil {
+ if duplicate, err := executor.CheckDuplicateVersion(ctx, tx, m.Namespace, m.Source, m.Version); err != nil {
return -1, err
} else if duplicate {
return -1, common.Errorf(common.MigrationAlreadyApplied, fmt.Errorf("database %q has already applied version %s", m.Database, m.Version))
}
// Check if there is any higher version already been applied
- if version, err := executor.CheckOutOfOrderVersion(ctx, tx, m.Namespace, m.Engine, m.Version); err != nil {
+ if version, err := executor.CheckOutOfOrderVersion(ctx, tx, m.Namespace, m.Source, m.Version); err != nil {
return -1, err
} else if version != nil && len(*version) > 0 {
// Clickhouse will always return non-nil version with empty string.
@@ -217,7 +217,7 @@ func beginMigration(ctx context.Context, executor MigrationExecutor, m *db.Migra
// If the migration engine is VCS and type is not baseline and is not branch, then we can only proceed if there is existing baseline
// This check is also wrapped in transaction to avoid edge case where two baselinings are running concurrently.
- if m.Engine == db.VCS && m.Type != db.Baseline && m.Type != db.Branch {
+ if m.Source == db.VCS && m.Type != db.Baseline && m.Type != db.Branch {
if hasBaseline, err := executor.FindBaseline(ctx, tx, m.Namespace); err != nil {
return -1, err
} else if !hasBaseline {
@@ -226,7 +226,7 @@ func beginMigration(ctx context.Context, executor MigrationExecutor, m *db.Migra
}
// VCS based SQL migration requires existing baselining
- requireBaseline := m.Engine == db.VCS && m.Type == db.Migrate
+ requireBaseline := m.Source == db.VCS && m.Type == db.Migrate
sequence, err := executor.FindNextSequence(ctx, tx, m.Namespace, requireBaseline)
if err != nil {
return -1, err
@@ -388,7 +388,7 @@ func FindMigrationHistoryList(ctx context.Context, findMigrationHistoryListQuery
&history.ReleaseVersion,
&history.Namespace,
&history.Sequence,
- &history.Engine,
+ &history.Source,
&history.Type,
&history.Status,
&history.Version,
diff --git a/server/instance.go b/server/instance.go
index 9b785d2033..e9c6401fa3 100644
--- a/server/instance.go
+++ b/server/instance.go
@@ -366,7 +366,7 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {
UpdatedTs: entry.UpdatedTs,
ReleaseVersion: entry.ReleaseVersion,
Database: entry.Namespace,
- Engine: entry.Engine,
+ Source: entry.Source,
Type: entry.Type,
Status: entry.Status,
Version: entry.Version,
@@ -435,7 +435,7 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {
UpdatedTs: entry.UpdatedTs,
ReleaseVersion: entry.ReleaseVersion,
Database: entry.Namespace,
- Engine: entry.Engine,
+ Source: entry.Source,
Type: entry.Type,
Status: entry.Status,
Version: entry.Version,
diff --git a/server/task_executor.go b/server/task_executor.go
index 58ef378e23..885873ad72 100644
--- a/server/task_executor.go
+++ b/server/task_executor.go
@@ -50,7 +50,7 @@ func runMigration(ctx context.Context, l *zap.Logger, server *Server, task *api.
Type: migrationType,
}
if vcsPushEvent == nil {
- mi.Engine = db.UI
+ mi.Source = db.UI
creator, err := server.composePrincipalByID(ctx, task.CreatorID)
if err != nil {
// If somehow we unable to find the principal, we just emit the error since it's not
@@ -143,7 +143,7 @@ func runMigration(ctx context.Context, l *zap.Logger, server *Server, task *api.
l.Debug("Start sql migration...",
zap.String("instance", task.Instance.Name),
zap.String("database", databaseName),
- zap.String("engine", mi.Engine.String()),
+ zap.String("source", mi.Source.String()),
zap.String("type", mi.Type.String()),
zap.String("statement", statement),
)
diff --git a/server/task_executor_database_create.go b/server/task_executor_database_create.go
index 61a1f0d120..8e303c300e 100644
--- a/server/task_executor_database_create.go
+++ b/server/task_executor_database_create.go
@@ -76,7 +76,7 @@ func (exec *DatabaseCreateTaskExecutor) RunOnce(ctx context.Context, server *Ser
Namespace: payload.DatabaseName,
Database: payload.DatabaseName,
Environment: instance.Environment.Name,
- Engine: db.UI,
+ Source: db.UI,
Type: db.Baseline,
Description: "Create database",
CreateDatabase: true,
diff --git a/server/task_executor_database_restore.go b/server/task_executor_database_restore.go
index a74b9adc61..554dc49762 100644
--- a/server/task_executor_database_restore.go
+++ b/server/task_executor_database_restore.go
@@ -183,7 +183,7 @@ func createBranchMigrationHistory(ctx context.Context, server *Server, sourceDat
Namespace: targetDatabase.Name,
Database: targetDatabase.Name,
Environment: targetDatabase.Instance.Environment.Name,
- Engine: db.MigrationEngine(targetDatabase.Project.WorkflowType),
+ Source: db.MigrationSource(targetDatabase.Project.WorkflowType),
Type: db.Branch,
Description: description,
Creator: task.Creator.Name,
diff --git a/store/sqlite.go b/store/sqlite.go
index e2d71ffe78..0e3bb34717 100644
--- a/store/sqlite.go
+++ b/store/sqlite.go
@@ -248,7 +248,7 @@ func (db *DB) migrate(ctx context.Context, d dbdriver.Driver, curVer version, da
Namespace: databaseName,
Database: databaseName,
Environment: "", /* unused in execute migration */
- Engine: dbdriver.LIBRARY,
+ Source: dbdriver.LIBRARY,
Type: dbdriver.Baseline,
Description: fmt.Sprintf("Create database %s.", databaseName),
CreateDatabase: true,
@@ -289,7 +289,7 @@ func (db *DB) migrate(ctx context.Context, d dbdriver.Driver, curVer version, da
Namespace: databaseName,
Database: databaseName,
Environment: "", /* unused in execute migration */
- Engine: dbdriver.LIBRARY,
+ Source: dbdriver.LIBRARY,
Type: dbdriver.Migrate,
Description: fmt.Sprintf("Migrate %s.", filepath.Base(name)),
},
diff --git a/tests/schema_update_test.go b/tests/schema_update_test.go
index 9762818e83..42b93045f8 100644
--- a/tests/schema_update_test.go
+++ b/tests/schema_update_test.go
@@ -194,7 +194,7 @@ func TestSchemaAndDataUpdate(t *testing.T) {
{
ID: 3,
Database: databaseName,
- Engine: db.UI,
+ Source: db.UI,
Type: db.Data,
Status: db.Done,
Schema: dumpedSchema,
@@ -203,7 +203,7 @@ func TestSchemaAndDataUpdate(t *testing.T) {
{
ID: 2,
Database: databaseName,
- Engine: db.UI,
+ Source: db.UI,
Type: db.Migrate,
Status: db.Done,
Schema: dumpedSchema,
@@ -212,7 +212,7 @@ func TestSchemaAndDataUpdate(t *testing.T) {
{
ID: 1,
Database: databaseName,
- Engine: db.UI,
+ Source: db.UI,
Type: db.Baseline,
Status: db.Done,
Schema: "",
@@ -226,7 +226,7 @@ func TestSchemaAndDataUpdate(t *testing.T) {
got := api.MigrationHistory{
ID: history.ID,
Database: history.Database,
- Engine: history.Engine,
+ Source: history.Source,
Type: history.Type,
Status: history.Status,
Schema: history.Schema,
@@ -284,7 +284,7 @@ func TestSchemaAndDataUpdate(t *testing.T) {
{
ID: 5,
Database: cloneDatabaseName,
- Engine: db.UI,
+ Source: db.UI,
Type: db.Branch,
Status: db.Done,
Schema: dumpedSchema,
@@ -293,7 +293,7 @@ func TestSchemaAndDataUpdate(t *testing.T) {
{
ID: 4,
Database: cloneDatabaseName,
- Engine: db.UI,
+ Source: db.UI,
Type: db.Baseline,
Status: db.Done,
Schema: "",
@@ -307,7 +307,7 @@ func TestSchemaAndDataUpdate(t *testing.T) {
got := api.MigrationHistory{
ID: history.ID,
Database: history.Database,
- Engine: history.Engine,
+ Source: history.Source,
Type: history.Type,
Status: history.Status,
Schema: history.Schema,
@@ -535,7 +535,7 @@ func TestVCS(t *testing.T) {
{
ID: 3,
Database: databaseName,
- Engine: db.VCS,
+ Source: db.VCS,
Type: db.Data,
Status: db.Done,
Schema: dumpedSchema,
@@ -544,7 +544,7 @@ func TestVCS(t *testing.T) {
{
ID: 2,
Database: databaseName,
- Engine: db.VCS,
+ Source: db.VCS,
Type: db.Migrate,
Status: db.Done,
Schema: dumpedSchema,
@@ -553,7 +553,7 @@ func TestVCS(t *testing.T) {
{
ID: 1,
Database: databaseName,
- Engine: db.UI,
+ Source: db.UI,
Type: db.Baseline,
Status: db.Done,
Schema: "",
@@ -567,7 +567,7 @@ func TestVCS(t *testing.T) {
got := api.MigrationHistory{
ID: history.ID,
Database: history.Database,
- Engine: history.Engine,
+ Source: history.Source,
Type: history.Type,
Status: history.Status,
Schema: history.Schema,