Skip to content

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

feat(semantic): support semantic versioning in the engine (#963)

Danny Xuedcef146b6f0
diff --git a/api/instance.go b/api/instance.go
index fb34a6a5ff..828361f9b6 100644
--- a/api/instance.go
+++ b/api/instance.go
@@ -196,17 +196,19 @@ type MigrationHistory struct {
UpdatedTs int64 `jsonapi:"attr,updatedTs"`
// Domain specific fields
- ReleaseVersion string `jsonapi:"attr,releaseVersion"`
- Database string `jsonapi:"attr,database"`
- Source db.MigrationSource `jsonapi:"attr,source"`
- Type db.MigrationType `jsonapi:"attr,type"`
- Status db.MigrationStatus `jsonapi:"attr,status"`
- Version string `jsonapi:"attr,version"`
- Description string `jsonapi:"attr,description"`
- Statement string `jsonapi:"attr,statement"`
- Schema string `jsonapi:"attr,schema"`
- SchemaPrev string `jsonapi:"attr,schemaPrev"`
- ExecutionDurationNs int64 `jsonapi:"attr,executionDurationNs"`
+ ReleaseVersion string `jsonapi:"attr,releaseVersion"`
+ Database string `jsonapi:"attr,database"`
+ Source db.MigrationSource `jsonapi:"attr,source"`
+ Type db.MigrationType `jsonapi:"attr,type"`
+ Status db.MigrationStatus `jsonapi:"attr,status"`
+ Version string `jsonapi:"attr,version"`
+ UseSemanticVersion bool `jsonapi:"attr,useSemanticVersion"`
+ SemanticVersionSuffix string `jsonapi:"attr,semanticVersionSuffix"`
+ Description string `jsonapi:"attr,description"`
+ Statement string `jsonapi:"attr,statement"`
+ Schema string `jsonapi:"attr,schema"`
+ SchemaPrev string `jsonapi:"attr,schemaPrev"`
+ ExecutionDurationNs int64 `jsonapi:"attr,executionDurationNs"`
// This is a string instead of int as the issue id may come from other issue tracking system in the future
IssueID string `jsonapi:"attr,issueId"`
Payload string `jsonapi:"attr,payload"`
diff --git a/bin/bb/cmd/migrate.go b/bin/bb/cmd/migrate.go
index 130e15ab8d..c35d366dec 100644
--- a/bin/bb/cmd/migrate.go
+++ b/bin/bb/cmd/migrate.go
@@ -123,6 +123,7 @@ func migrateDatabase(ctx context.Context, databaseType, username, password, host
if _, err := io.Copy(&buf, sqlReader); err != nil {
return fmt.Errorf("failed to read sql file, got error: %w", err)
}
+ // TODO(d): support semantic versioning.
if _, _, err := driver.ExecuteMigration(ctx, &db.MigrationInfo{
ReleaseVersion: version,
Version: defaultMigrationVersion(),
diff --git a/go.mod b/go.mod
index 26ac4076cb..123d0a3605 100644
--- a/go.mod
+++ b/go.mod
@@ -5,6 +5,7 @@ go 1.16
require (
github.com/ClickHouse/clickhouse-go/v2 v2.0.7
github.com/VictoriaMetrics/fastcache v1.6.0
+ github.com/blang/semver/v4 v4.0.0
github.com/casbin/casbin/v2 v2.40.6
github.com/github/gh-ost v1.1.4
github.com/go-sql-driver/mysql v1.6.0
diff --git a/go.sum b/go.sum
index 25d769c563..4d88dd4a63 100644
--- a/go.sum
+++ b/go.sum
@@ -155,6 +155,8 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/bkaradzic/go-lz4 v1.0.0/go.mod h1:0YdlkowM3VswSROI7qDxhRvJ3sLhlFrRRwjwegp5jy4=
github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM=
github.com/blacktear23/go-proxyprotocol v0.0.0-20180807104634-af7a81e8dd0d/go.mod h1:VKt7CNAQxpFpSDz3sXyj9hY/GbVsQCr0sB3w59nE7lU=
+github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
+github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/bytebase/gh-ost v1.1.4 h1:mn8VQSu9i/Uu/0fDv3OXC6t/MlodN43c2iY2IpaAcN8=
github.com/bytebase/gh-ost v1.1.4/go.mod h1:qSgDrOa8CXEr6gjZJn3H/uW/+Sx7kXf0cu//ci7cNHQ=
github.com/cakturk/go-netstat v0.0.0-20200220111822-e5b49efee7a5 h1:BjkPE3785EwPhhyuFkbINB+2a1xATwk8SNDWnJiD41g=
diff --git a/plugin/db/clickhouse/clickhouse.go b/plugin/db/clickhouse/clickhouse.go
index 7389c95550..e9e1ec2219 100644
--- a/plugin/db/clickhouse/clickhouse.go
+++ b/plugin/db/clickhouse/clickhouse.go
@@ -469,7 +469,7 @@ func (Driver) FindLargestSequence(ctx context.Context, tx *sql.Tx, namespace str
}
// InsertPendingHistory will insert the migration record with pending status and return the inserted ID.
-func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int, prevSchema string, m *db.MigrationInfo, statement string) (int64, error) {
+func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int, prevSchema string, m *db.MigrationInfo, storedVersion, statement string) (int64, error) {
const insertHistoryQuery = `
INSERT INTO bytebase.migration_history (
id,
@@ -525,7 +525,7 @@ func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int
m.Source,
m.Type,
"PENDING",
- m.Version,
+ storedVersion,
m.Description,
statement,
prevSchema,
diff --git a/plugin/db/driver.go b/plugin/db/driver.go
index ed0503def2..8bc6f9bd7d 100644
--- a/plugin/db/driver.go
+++ b/plugin/db/driver.go
@@ -233,6 +233,14 @@ type MigrationInfo struct {
IssueID string
Payload string
CreateDatabase bool
+ // UseSemanticVersion is whether version is a semantic version.
+ // When UseSemanticVersion is set, version should be set to the format specified in Semantic Versioning 2.0.0 (https://semver.org/).
+ // For example, for setting non-semantic version "hello", the values should be Version = "hello", UseSemanticVersion = false, SemanticVersionSuffix = "".
+ // For setting semantic version "1.2.0", the values should be Version = "1.2.0", UseSemanticVersion = true, SemanticVersionSuffix = "20060102150405".
+ UseSemanticVersion bool
+ // SemanticVersionSuffix should be set to timestamp format of "20060102150405" if UseSemanticVersion is set.
+ // Since stored version should be unique, we have to append a suffix if we allow users to baseline to the same semantic version for fixing schema drift.
+ SemanticVersionSuffix string
}
// ParseMigrationInfo matches filePath against filePathTemplate
@@ -326,20 +334,22 @@ type MigrationHistory struct {
Updater string
UpdatedTs int64
- ReleaseVersion string
- Namespace string
- Sequence int
- Source MigrationSource
- Type MigrationType
- Status MigrationStatus
- Version string
- Description string
- Statement string
- Schema string
- SchemaPrev string
- ExecutionDurationNs int64
- IssueID string
- Payload string
+ ReleaseVersion string
+ Namespace string
+ Sequence int
+ Source MigrationSource
+ Type MigrationType
+ Status MigrationStatus
+ Version string
+ Description string
+ Statement string
+ Schema string
+ SchemaPrev string
+ ExecutionDurationNs int64
+ IssueID string
+ Payload string
+ UseSemanticVersion bool
+ SemanticVersionSuffix string
}
// MigrationHistoryFind is the API message for finding migration histories.
diff --git a/plugin/db/mysql/mysql.go b/plugin/db/mysql/mysql.go
index ca03699887..426d6c26e4 100644
--- a/plugin/db/mysql/mysql.go
+++ b/plugin/db/mysql/mysql.go
@@ -645,7 +645,7 @@ func (Driver) FindLargestSequence(ctx context.Context, tx *sql.Tx, namespace str
}
// InsertPendingHistory will insert the migration record with pending status and return the inserted ID.
-func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int, prevSchema string, m *db.MigrationInfo, statement string) (int64, error) {
+func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int, prevSchema string, m *db.MigrationInfo, storedVersion, statement string) (int64, error) {
const insertHistoryQuery = `
INSERT INTO bytebase.migration_history (
created_by,
@@ -677,7 +677,7 @@ func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int
sequence,
m.Source,
m.Type,
- m.Version,
+ storedVersion,
m.Description,
statement,
prevSchema,
diff --git a/plugin/db/pg/pg.go b/plugin/db/pg/pg.go
index 81f2317283..82ad1bccd0 100644
--- a/plugin/db/pg/pg.go
+++ b/plugin/db/pg/pg.go
@@ -568,7 +568,7 @@ func (Driver) FindLargestSequence(ctx context.Context, tx *sql.Tx, namespace str
}
// InsertPendingHistory will insert the migration record with pending status and return the inserted ID.
-func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int, prevSchema string, m *db.MigrationInfo, statement string) (int64, error) {
+func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int, prevSchema string, m *db.MigrationInfo, storedVersion, statement string) (int64, error) {
const insertHistoryQuery = `
INSERT INTO migration_history (
created_by,
@@ -602,7 +602,7 @@ func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int
sequence,
m.Source,
m.Type,
- m.Version,
+ storedVersion,
m.Description,
statement,
prevSchema,
diff --git a/plugin/db/snowflake/snowflake.go b/plugin/db/snowflake/snowflake.go
index 8ecf0f703f..d9ec030184 100644
--- a/plugin/db/snowflake/snowflake.go
+++ b/plugin/db/snowflake/snowflake.go
@@ -644,7 +644,7 @@ func (Driver) FindLargestSequence(ctx context.Context, tx *sql.Tx, namespace str
}
// InsertPendingHistory will insert the migration record with pending status and return the inserted ID.
-func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int, prevSchema string, m *db.MigrationInfo, statement string) (int64, error) {
+func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int, prevSchema string, m *db.MigrationInfo, storedVersion, statement string) (int64, error) {
const insertHistoryQuery = `
INSERT INTO bytebase.public.migration_history (
created_by,
@@ -700,7 +700,7 @@ func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int
sequence,
m.Source,
m.Type,
- m.Version,
+ storedVersion,
m.Description,
statement,
prevSchema,
diff --git a/plugin/db/sqlite/sqlite.go b/plugin/db/sqlite/sqlite.go
index 7ee44c74a6..114ef2dea3 100644
--- a/plugin/db/sqlite/sqlite.go
+++ b/plugin/db/sqlite/sqlite.go
@@ -492,7 +492,7 @@ func (Driver) FindLargestSequence(ctx context.Context, tx *sql.Tx, namespace str
}
// InsertPendingHistory will insert the migration record with pending status and return the inserted ID.
-func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int, prevSchema string, m *db.MigrationInfo, statement string) (int64, error) {
+func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int, prevSchema string, m *db.MigrationInfo, storedVersion, statement string) (int64, error) {
const insertHistoryQuery = `
INSERT INTO bytebase_migration_history (
created_by,
@@ -524,7 +524,7 @@ func (Driver) InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int
sequence,
m.Source,
m.Type,
- m.Version,
+ storedVersion,
m.Description,
statement,
prevSchema,
diff --git a/plugin/db/util/driverutil.go b/plugin/db/util/driverutil.go
index 12f593b518..595c97362a 100644
--- a/plugin/db/util/driverutil.go
+++ b/plugin/db/util/driverutil.go
@@ -6,9 +6,11 @@ import (
"context"
"database/sql"
"fmt"
+ "strconv"
"strings"
"time"
+ "github.com/blang/semver/v4"
"github.com/bytebase/bytebase/common"
"github.com/bytebase/bytebase/plugin/db"
"go.uber.org/zap"
@@ -118,7 +120,7 @@ type MigrationExecutor interface {
// Returns 0 if we haven't applied any migration for this namespace.
FindLargestSequence(ctx context.Context, tx *sql.Tx, namespace string, baseline bool) (int, error)
// InsertPendingHistory will insert the migration record with pending status and return the inserted ID.
- InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int, prevSchema string, m *db.MigrationInfo, statement string) (insertedID int64, err error)
+ InsertPendingHistory(ctx context.Context, tx *sql.Tx, sequence int, prevSchema string, m *db.MigrationInfo, storedVersion, statement string) (insertedID int64, err error)
// UpdateHistoryAsDone will update the migration record as done.
UpdateHistoryAsDone(ctx context.Context, tx *sql.Tx, migrationDurationNs int64, updatedSchema string, insertedID int64) error
// UpdateHistoryAsFailed will update the migration record as failed.
@@ -183,6 +185,11 @@ func ExecuteMigration(ctx context.Context, l *zap.Logger, executor MigrationExec
// beginMigration checks before executing migration and inserts a migration history record with pending status.
func beginMigration(ctx context.Context, executor MigrationExecutor, m *db.MigrationInfo, prevSchema string, statement string) (insertedID int64, err error) {
+ // Convert verion to stored version.
+ storedVersion, err := toStoredVersion(m.UseSemanticVersion, m.Version, m.SemanticVersionSuffix)
+ if err != nil {
+ return 0, fmt.Errorf("failed to convert to stored version, error %w", err)
+ }
// Phase 1 - Precheck before executing migration
// Check if the same migration version has already been applied
if list, err := executor.FindMigrationHistoryList(ctx, &db.MigrationHistoryFind{
@@ -233,7 +240,7 @@ func beginMigration(ctx context.Context, executor MigrationExecutor, m *db.Migra
// MySQL runs DDL in its own transaction, so we can't commit migration history together with DDL in a single transaction.
// Thus we sort of doing a 2-phase commit, where we first write a PENDING migration record, and after migration completes, we then
// update the record to DONE together with the updated schema.
- if insertedID, err = executor.InsertPendingHistory(ctx, tx, largestSequence+1, prevSchema, m, statement); err != nil {
+ if insertedID, err = executor.InsertPendingHistory(ctx, tx, largestSequence+1, prevSchema, m, storedVersion, statement); err != nil {
return -1, err
}
@@ -393,6 +400,7 @@ func FindMigrationHistoryList(ctx context.Context, findMigrationHistoryListQuery
var migrationHistoryList []*db.MigrationHistory
for rows.Next() {
var history db.MigrationHistory
+ var storedVersion string
if err := rows.Scan(
&history.ID,
&history.Creator,
@@ -405,7 +413,7 @@ func FindMigrationHistoryList(ctx context.Context, findMigrationHistoryListQuery
&history.Source,
&history.Type,
&history.Status,
- &history.Version,
+ &storedVersion,
&history.Description,
&history.Statement,
&history.Schema,
@@ -417,6 +425,11 @@ func FindMigrationHistoryList(ctx context.Context, findMigrationHistoryListQuery
return nil, err
}
+ useSemanticVersion, version, semanticVersionSuffix, err := fromStoredVersion(storedVersion)
+ if err != nil {
+ return nil, err
+ }
+ history.UseSemanticVersion, history.Version, history.SemanticVersionSuffix = useSemanticVersion, version, semanticVersionSuffix
migrationHistoryList = append(migrationHistoryList, &history)
}
if err := rows.Err(); err != nil {
@@ -443,3 +456,55 @@ func formatError(err error) error {
return err
}
+
+const nonSemanticPrefix = "0000.0000.0000-"
+
+// toStoredVersion converts semantic or non-semantic version to stored version format.
+// Non-semantic version will have additional "0000.0000.0000-" prefix.
+// Semantic version will add zero padding to MAJOR, MINOR, PATCH version with a timestamp suffix.
+func toStoredVersion(useSemanticVersion bool, version, semanticVersionSuffix string) (string, error) {
+ if !useSemanticVersion {
+ return fmt.Sprintf("%s%s", nonSemanticPrefix, version), nil
+ }
+ v, err := semver.Make(version)
+ if err != nil {
+ return "", err
+ }
+ major, minor, patch := fmt.Sprintf("%d", v.Major), fmt.Sprintf("%d", v.Minor), fmt.Sprintf("%d", v.Patch)
+ if len(major) > 4 || len(minor) > 4 || len(patch) > 4 {
+ return "", fmt.Errorf("invalid version %q, major, minor, patch version should be < 10000", version)
+ }
+ return fmt.Sprintf("%04s.%04s.%04s-%s", major, minor, patch, semanticVersionSuffix), nil
+}
+
+// fromStoredVersion converts stored version to semantic or non-semantic version.
+func fromStoredVersion(storedVersion string) (bool, string, string, error) {
+ if strings.HasPrefix(storedVersion, nonSemanticPrefix) {
+ return false, strings.TrimPrefix(storedVersion, nonSemanticPrefix), "", nil
+ }
+ idx := strings.Index(storedVersion, "-")
+ if idx < 0 {
+ return false, "", "", fmt.Errorf("invalid stored version %q, version should contain '-'", storedVersion)
+ }
+ prefix, suffix := storedVersion[:idx], storedVersion[idx+1:]
+ parts := strings.Split(prefix, ".")
+ if len(parts) != 3 {
+ return false, "", "", fmt.Errorf("invalid stored version %q, version prefix %q should be in semantic version format", storedVersion, prefix)
+ }
+ major, err := strconv.Atoi(parts[0])
+ if err != nil {
+ return false, "", "", fmt.Errorf("invalid stored version %q, version prefix %q should be in semantic version format", storedVersion, prefix)
+ }
+ minor, err := strconv.Atoi(parts[1])
+ if err != nil {
+ return false, "", "", fmt.Errorf("invalid stored version %q, version prefix %q should be in semantic version format", storedVersion, prefix)
+ }
+ patch, err := strconv.Atoi(parts[2])
+ if err != nil {
+ return false, "", "", fmt.Errorf("invalid stored version %q, version prefix %q should be in semantic version format", storedVersion, prefix)
+ }
+ if major >= 10000 || minor >= 10000 || patch >= 10000 {
+ return false, "", "", fmt.Errorf("invalid stored version %q, major, minor, patch version of %q should be < 10000", storedVersion, prefix)
+ }
+ return true, fmt.Sprintf("%d.%d.%d", major, minor, patch), suffix, nil
+}
diff --git a/plugin/db/util/driverutil_test.go b/plugin/db/util/driverutil_test.go
new file mode 100644
index 0000000000..5d8eba156b
--- /dev/null
+++ b/plugin/db/util/driverutil_test.go
@@ -0,0 +1,70 @@
+package util
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+func TestToStoredVersion(t *testing.T) {
+ type test struct {
+ useSemanticVersion bool
+ version string
+ semanticVersionSuffix string
+ want string
+ wantErr string
+ }
+ tests := []test{
+ {false, "hello", "", "0000.0000.0000-hello", ""},
+ {false, "hello", "world", "0000.0000.0000-hello", ""},
+ {true, "hello", "world", "", "No Major.Minor.Patch elements found"},
+ {true, "v1.2.3", "world", "", "Invalid character(s) found in major number"},
+ {true, "1.10000.3", "world", "", "major, minor, patch version should be < 10000"},
+ {true, "1.2.3", "world", "0001.0002.0003-world", ""},
+ {true, "2021.1.13", "world", "2021.0001.0013-world", ""},
+ }
+ for _, tc := range tests {
+ got, err := toStoredVersion(tc.useSemanticVersion, tc.version, tc.semanticVersionSuffix)
+ if tc.wantErr != "" {
+ require.Contains(t, err.Error(), tc.wantErr)
+ continue
+ }
+ require.NoError(t, err)
+ require.Equal(t, tc.want, got)
+ }
+}
+
+func TestFromStoredVersion(t *testing.T) {
+ type test struct {
+ storedVersion string
+ wantUseSemanticVersion bool
+ wantVersion string
+ wantSemanticVersionSuffix string
+ wantErr string
+ }
+ tests := []test{
+ {"0000.0000.0000-hello", false, "hello", "", ""},
+ {"0001.0001.0000-hello", true, "1.1.0", "hello", ""},
+ {"2021.0001.0013-world", true, "2021.1.13", "world", ""},
+ {"2021.0001.0013-hello-world", true, "2021.1.13", "hello-world", ""},
+ {"2021.0001.0013", false, "", "", "should contain '-'"},
+ {"2021.0001.0013.1234-hello", false, "", "", "should be in semantic version"},
+ {"2021.0001-hello", false, "", "", "should be in semantic version"},
+ {"2a21.0001.0013-hello", false, "", "", "should be in semantic version"},
+ {"10000.0001.0000-hello", false, "", "", "should be < 10000"},
+ {"", false, "", "", "should contain '-'"},
+ {"hello", false, "", "", "should contain '-'"},
+ {"1.2.3", false, "", "", "should contain '-'"},
+ }
+ for _, tc := range tests {
+ gotUseSemanticVersion, gotVersion, gotSemanticVersionSuffix, err := fromStoredVersion(tc.storedVersion)
+ if tc.wantErr != "" {
+ require.Contains(t, err.Error(), tc.wantErr)
+ continue
+ }
+ require.NoError(t, err)
+ require.Equal(t, tc.wantUseSemanticVersion, gotUseSemanticVersion)
+ require.Equal(t, tc.wantVersion, gotVersion)
+ require.Equal(t, tc.wantSemanticVersionSuffix, gotSemanticVersionSuffix)
+ }
+}
diff --git a/server/instance.go b/server/instance.go
index bb00c36fdb..8148e7692e 100644
--- a/server/instance.go
+++ b/server/instance.go
@@ -326,24 +326,26 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
if err := jsonapi.MarshalPayload(c.Response().Writer, &api.MigrationHistory{
- ID: entry.ID,
- Creator: entry.Creator,
- CreatedTs: entry.CreatedTs,
- Updater: entry.Updater,
- UpdatedTs: entry.UpdatedTs,
- ReleaseVersion: entry.ReleaseVersion,
- Database: entry.Namespace,
- Source: entry.Source,
- Type: entry.Type,
- Status: entry.Status,
- Version: entry.Version,
- Description: entry.Description,
- Statement: entry.Statement,
- Schema: entry.Schema,
- SchemaPrev: entry.SchemaPrev,
- ExecutionDurationNs: entry.ExecutionDurationNs,
- IssueID: entry.IssueID,
- Payload: entry.Payload,
+ ID: entry.ID,
+ Creator: entry.Creator,
+ CreatedTs: entry.CreatedTs,
+ Updater: entry.Updater,
+ UpdatedTs: entry.UpdatedTs,
+ ReleaseVersion: entry.ReleaseVersion,
+ Database: entry.Namespace,
+ Source: entry.Source,
+ Type: entry.Type,
+ Status: entry.Status,
+ Version: entry.Version,
+ UseSemanticVersion: entry.UseSemanticVersion,
+ SemanticVersionSuffix: entry.SemanticVersionSuffix,
+ Description: entry.Description,
+ Statement: entry.Statement,
+ Schema: entry.Schema,
+ SchemaPrev: entry.SchemaPrev,
+ ExecutionDurationNs: entry.ExecutionDurationNs,
+ IssueID: entry.IssueID,
+ Payload: entry.Payload,
}); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to marshal migration history response for instance: %v", instance.Name)).SetInternal(err)
}
@@ -395,24 +397,26 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {
for _, entry := range list {
historyList = append(historyList, &api.MigrationHistory{
- ID: entry.ID,
- Creator: entry.Creator,
- CreatedTs: entry.CreatedTs,
- Updater: entry.Updater,
- UpdatedTs: entry.UpdatedTs,
- ReleaseVersion: entry.ReleaseVersion,
- Database: entry.Namespace,
- Source: entry.Source,
- Type: entry.Type,
- Status: entry.Status,
- Version: entry.Version,
- Description: entry.Description,
- Statement: entry.Statement,
- Schema: entry.Schema,
- SchemaPrev: entry.SchemaPrev,
- ExecutionDurationNs: entry.ExecutionDurationNs,
- IssueID: entry.IssueID,
- Payload: entry.Payload,
+ ID: entry.ID,
+ Creator: entry.Creator,
+ CreatedTs: entry.CreatedTs,
+ Updater: entry.Updater,
+ UpdatedTs: entry.UpdatedTs,
+ ReleaseVersion: entry.ReleaseVersion,
+ Database: entry.Namespace,
+ Source: entry.Source,
+ Type: entry.Type,
+ Status: entry.Status,
+ Version: entry.Version,
+ UseSemanticVersion: entry.UseSemanticVersion,
+ SemanticVersionSuffix: entry.SemanticVersionSuffix,
+ Description: entry.Description,
+ Statement: entry.Statement,
+ Schema: entry.Schema,
+ SchemaPrev: entry.SchemaPrev,
+ ExecutionDurationNs: entry.ExecutionDurationNs,
+ IssueID: entry.IssueID,
+ Payload: entry.Payload,
})
}
diff --git a/server/sql.go b/server/sql.go
index e265628d6b..2fd56022c7 100644
--- a/server/sql.go
+++ b/server/sql.go
@@ -629,6 +629,7 @@ func (s *Server) syncEngineVersionAndSchema(ctx context.Context, instance *api.I
}
func getLatestSchemaVersion(ctx context.Context, driver db.Driver, databaseName string) (string, error) {
+ // TODO(d): support semantic versioning.
limit := 1
history, err := driver.FindMigrationHistoryList(ctx, &db.MigrationHistoryFind{
Database: &databaseName,
diff --git a/server/task_executor.go b/server/task_executor.go
index 2a64f6ca06..29c85ef11e 100644
--- a/server/task_executor.go
+++ b/server/task_executor.go
@@ -62,6 +62,7 @@ func runMigration(ctx context.Context, l *zap.Logger, server *Server, task *api.
} else {
mi.Creator = creator.Name
}
+ // TODO(d): support semantic versioning.
mi.Version = schemaVersion
mi.Database = databaseName
mi.Namespace = databaseName
diff --git a/server/task_executor_database_create.go b/server/task_executor_database_create.go
index cfc47e5f07..2372bbc8ec 100644
--- a/server/task_executor_database_create.go
+++ b/server/task_executor_database_create.go
@@ -62,6 +62,7 @@ func (exec *DatabaseCreateTaskExecutor) RunOnce(ctx context.Context, server *Ser
)
// Create a baseline migration history upon creating the database.
+ // TODO(d): support semantic versioning.
mi := &db.MigrationInfo{
ReleaseVersion: server.version,
Version: payload.SchemaVersion,
diff --git a/server/task_executor_database_restore.go b/server/task_executor_database_restore.go
index 5d5be6e986..860f91d28a 100644
--- a/server/task_executor_database_restore.go
+++ b/server/task_executor_database_restore.go
@@ -176,6 +176,7 @@ func createBranchMigrationHistory(ctx context.Context, server *Server, sourceDat
if sourceDatabase.InstanceID != targetDatabase.InstanceID {
description = fmt.Sprintf("Restored from backup %q of database %q in instance %q.", backup.Name, sourceDatabase.Name, sourceDatabase.Instance.Name)
}
+ // TODO(d): support semantic versioning.
m := &db.MigrationInfo{
ReleaseVersion: server.version,
Version: defaultMigrationVersionFromTaskID(),
diff --git a/store/pg_engine.go b/store/pg_engine.go
index 719cfb6325..b3bd60690c 100644
--- a/store/pg_engine.go
+++ b/store/pg_engine.go
@@ -152,6 +152,7 @@ func (db *DB) Open(ctx context.Context) (err error) {
}
func getLatestVersion(ctx context.Context, d dbdriver.Driver, database string) (ver version, err error) {
+ // TODO(d): support semantic versioning.
limit := 1
history, err := d.FindMigrationHistoryList(ctx, &dbdriver.MigrationHistoryFind{
Database: &database,
@@ -244,6 +245,7 @@ func (db *DB) migrate(ctx context.Context, d dbdriver.Driver, curVer version, da
if curVer.major == 0 && curVer.minor == 0 {
createDatabaseStatement := fmt.Sprintf("CREATE DATABASE %s", databaseName)
+ // TODO(d): support semantic versioning.
if _, _, err := d.ExecuteMigration(
ctx,
&dbdriver.MigrationInfo{
@@ -288,6 +290,7 @@ func (db *DB) migrate(ctx context.Context, d dbdriver.Driver, curVer version, da
if err != nil {
return err
}
+ // TODO(d): support semantic versioning.
if _, _, err := d.ExecuteMigration(
ctx,
&dbdriver.MigrationInfo{