Skip to content

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

fix(mongodb): schema version format (#4075)

h3n4l5990c0c6b37f
diff --git a/plugin/db/mongodb/migrate.go b/plugin/db/mongodb/migrate.go
index f71dadf718..badbaf52b3 100644
--- a/plugin/db/mongodb/migrate.go
+++ b/plugin/db/mongodb/migrate.go
@@ -159,33 +159,42 @@ func (driver *Driver) FindMigrationHistoryList(ctx context.Context, find *db.Mig
if err := cursor.Decode(&history); err != nil {
return nil, errors.Wrapf(err, "failed to decode migration history")
}
- migrationHistory := convertMigrationHistory(history)
+ migrationHistory, err := convertMigrationHistory(history)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to convert migration history")
+ }
migrationHistoryList = append(migrationHistoryList, &migrationHistory)
}
return migrationHistoryList, nil
}
-func convertMigrationHistory(history MigrationHistory) db.MigrationHistory {
- return db.MigrationHistory{
- ID: int(history.ID),
- Creator: history.CreatedBy,
- CreatedTs: int64(history.CreatedTs.T),
- Updater: history.UpdatedBy,
- UpdatedTs: int64(history.UpdatedTs.T),
- ReleaseVersion: history.ReleaseVersion,
- Namespace: history.Namespace,
- Sequence: int(history.Sequence),
- Source: db.MigrationSource(history.Source),
- Type: db.MigrationType(history.Type),
- Status: db.MigrationStatus(history.Status),
- Version: history.Version,
- Description: history.Description,
- Statement: history.Statement,
- ExecutionDurationNs: history.ExecutionDurationNs,
- IssueID: history.IssueID,
- Payload: history.Payload,
+func convertMigrationHistory(history MigrationHistory) (db.MigrationHistory, error) {
+ useSemanticVersion, version, semanticVersionSuffix, err := util.FromStoredVersion(history.Version)
+ if err != nil {
+ return db.MigrationHistory{}, err
}
+ return db.MigrationHistory{
+ ID: int(history.ID),
+ Creator: history.CreatedBy,
+ CreatedTs: int64(history.CreatedTs.T),
+ Updater: history.UpdatedBy,
+ UpdatedTs: int64(history.UpdatedTs.T),
+ ReleaseVersion: history.ReleaseVersion,
+ Namespace: history.Namespace,
+ Sequence: int(history.Sequence),
+ Source: db.MigrationSource(history.Source),
+ Type: db.MigrationType(history.Type),
+ Status: db.MigrationStatus(history.Status),
+ Version: version,
+ Description: history.Description,
+ Statement: history.Statement,
+ ExecutionDurationNs: history.ExecutionDurationNs,
+ IssueID: history.IssueID,
+ Payload: history.Payload,
+ UseSemanticVersion: useSemanticVersion,
+ SemanticVersionSuffix: semanticVersionSuffix,
+ }, nil
}
// FindLargestSequence finds the largest sequence, return 0 if not found.
diff --git a/plugin/db/util/driverutil.go b/plugin/db/util/driverutil.go
index a7095fcf2b..530f4e556f 100644
--- a/plugin/db/util/driverutil.go
+++ b/plugin/db/util/driverutil.go
@@ -633,7 +633,7 @@ func FindMigrationHistoryList(ctx context.Context, findMigrationHistoryListQuery
return nil, err
}
- useSemanticVersion, version, semanticVersionSuffix, err := fromStoredVersion(storedVersion)
+ useSemanticVersion, version, semanticVersionSuffix, err := FromStoredVersion(storedVersion)
if err != nil {
return nil, err
}
@@ -687,8 +687,8 @@ func ToStoredVersion(useSemanticVersion bool, version, semanticVersionSuffix str
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) {
+// 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
}
diff --git a/plugin/db/util/driverutil_test.go b/plugin/db/util/driverutil_test.go
index 1b0884b52f..cc8dc97c46 100644
--- a/plugin/db/util/driverutil_test.go
+++ b/plugin/db/util/driverutil_test.go
@@ -65,7 +65,7 @@ func TestFromStoredVersion(t *testing.T) {
{"1.2.3", false, "", "", "should contain '-'"},
}
for _, tc := range tests {
- gotUseSemanticVersion, gotVersion, gotSemanticVersionSuffix, err := fromStoredVersion(tc.storedVersion)
+ gotUseSemanticVersion, gotVersion, gotSemanticVersionSuffix, err := FromStoredVersion(tc.storedVersion)
if tc.wantErr != "" {
require.Contains(t, err.Error(), tc.wantErr)
continue