Skip to content

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

fix: declarative version check, disallow equal or less versions. (#17185)

p0nye2e7dca962d7
diff --git a/backend/api/v1/release_service_check.go b/backend/api/v1/release_service_check.go
index 45a0042caa..3ef6039e53 100644
--- a/backend/api/v1/release_service_check.go
+++ b/backend/api/v1/release_service_check.go
@@ -143,8 +143,6 @@ func (s *ReleaseService) CheckRelease(ctx context.Context, req *connect.Request[
switch releaseFileType {
case v1pb.Release_File_DECLARATIVE:
- // TODO(p0ny): check sql
- // TODO(p0ny): make stopChecking effective. need to refactor first.
revisions, err := s.store.ListRevisions(ctx, &store.FindRevisionMessage{
InstanceID: &database.InstanceID,
DatabaseName: &database.DatabaseName,
@@ -165,7 +163,7 @@ func (s *ReleaseService) CheckRelease(ctx context.Context, req *connect.Request[
if err != nil {
return nil, connect.NewError(connect.CodeInternal, errors.Wrapf(err, "failed to parse version %q", file.Version))
}
- if fv.LessThan(rv) {
+ if fv.LessThanOrEqual(rv) {
checkResult := &v1pb.CheckReleaseResponse_CheckResult{
File: file.Path,
Target: common.FormatDatabase(instance.ResourceID, database.DatabaseName),
@@ -174,7 +172,7 @@ func (s *ReleaseService) CheckRelease(ctx context.Context, req *connect.Request[
Status: v1pb.Advice_WARNING,
Code: advisor.Internal.Int32(),
Title: "Applied file has been modified",
- Content: fmt.Sprintf("The file %q has version %q, but there is a higher version %q applied", file.Path, file.Version, revisions[0].Version),
+ Content: fmt.Sprintf("The file %q has version %q, but there is an equal or higher version %q applied", file.Path, file.Version, revisions[0].Version),
},
},
}
diff --git a/backend/api/v1/rollout_service_task.go b/backend/api/v1/rollout_service_task.go
index 350c9ddec2..49ef79e4d3 100644
--- a/backend/api/v1/rollout_service_task.go
+++ b/backend/api/v1/rollout_service_task.go
@@ -488,13 +488,13 @@ func getTaskCreatesFromChangeDatabaseConfigWithRelease(
}
taskCreates = append(taskCreates, taskCreate)
case storepb.ReleasePayload_File_DECLARATIVE:
- // error if applied revisions contain a higher version than the declarative file
+ // error if applied revisions contain an equal or higher version than the declarative file
v, err := model.NewVersion(file.Version)
if err != nil {
return nil, errors.Wrapf(err, "failed to parse file version %q", file.Version)
}
- if maxDeclarativeVersion != nil && v.LessThan(maxDeclarativeVersion) {
- return nil, errors.Errorf("cannot run declarative file %q with version %q, because there is a higher versioned declarative revision %q applied", file.Id, file.Version, maxDeclarativeVersion.String())
+ if maxDeclarativeVersion != nil && v.LessThanOrEqual(maxDeclarativeVersion) {
+ return nil, errors.Errorf("cannot run declarative file %q with version %q, because there is an equal or higher versioned declarative revision %q applied", file.Id, file.Version, maxDeclarativeVersion.String())
}
// Parse sheet ID from the file's sheet reference
diff --git a/backend/runner/taskrun/executor.go b/backend/runner/taskrun/executor.go
index a1e6918267..eee355c506 100644
--- a/backend/runner/taskrun/executor.go
+++ b/backend/runner/taskrun/executor.go
@@ -456,7 +456,7 @@ func beginMigration(ctx context.Context, stores *store.Store, mc *migrateContext
if err != nil {
return false, errors.Wrapf(err, "failed to parse current version %q", mc.version)
}
- if currentVersion.LessOrEqualThan(latestVersion) {
+ if currentVersion.LessThanOrEqual(latestVersion) {
return false, errors.Errorf("cannot apply SDL migration with version %s because an equal or newer version %s already exists", mc.version, latestRevision.Version)
}
}
diff --git a/backend/store/model/version.go b/backend/store/model/version.go
index 5c482d293f..4a9f97aa0d 100644
--- a/backend/store/model/version.go
+++ b/backend/store/model/version.go
@@ -40,7 +40,7 @@ func (v *Version) LessThan(other *Version) bool {
return len(v.parts) < len(other.parts)
}
-func (v *Version) LessOrEqualThan(other *Version) bool {
+func (v *Version) LessThanOrEqual(other *Version) bool {
return !other.LessThan(v)
}
diff --git a/backend/tests/action_test.go b/backend/tests/action_test.go
index ea2a0c5b63..720549676c 100644
--- a/backend/tests/action_test.go
+++ b/backend/tests/action_test.go
@@ -8,7 +8,6 @@ import (
"os"
"path/filepath"
"slices"
- "strings"
"testing"
"connectrpc.com/connect"
@@ -1203,32 +1202,7 @@ func TestActionRolloutDeclarativeMode(t *testing.T) {
// Get rollout details to check task run error
rolloutName := output2["rollout"]
- a.NotEmpty(rolloutName, "Should have rollout name in output")
-
- // Get the rollout to check task runs
- rolloutResp, err := ctl.rolloutServiceClient.GetRollout(ctx, connect.NewRequest(&v1pb.GetRolloutRequest{
- Name: rolloutName,
- }))
- a.NoError(err)
- rollout := rolloutResp.Msg
-
- // Check task runs for error message
- // Use the special parent format to list all task runs from the rollout
- taskRunsResp, err := ctl.rolloutServiceClient.ListTaskRuns(ctx, connect.NewRequest(&v1pb.ListTaskRunsRequest{
- Parent: fmt.Sprintf("%s/stages/-/tasks/-", rollout.Name),
- }))
- a.NoError(err)
-
- foundExpectedError := false
- for _, taskRun := range taskRunsResp.Msg.TaskRuns {
- if taskRun.Detail != "" && strings.Contains(taskRun.Detail, "cannot apply SDL migration with version") &&
- strings.Contains(taskRun.Detail, "because an equal or newer version") &&
- strings.Contains(taskRun.Detail, "already exists") {
- foundExpectedError = true
- break
- }
- }
- a.True(foundExpectedError, "Should find error message about SDL migration version conflict")
+ a.Empty(rolloutName, "Should not have rollout name in output")
// Execute third declarative rollout with same schema (should also fail)
result3, err := executeActionCommand(ctx,
@@ -1283,10 +1257,10 @@ func TestActionRolloutDeclarativeMode(t *testing.T) {
a.Equal(1, tableCount, "Should have exactly one users table (idempotent)")
// Verify first rollout succeeded
- a.NotContains(result1.Stderr, "failed to run and wait for rollout: found failed tasks", "First rollout should complete without errors")
+ a.NotContains(result1.Stderr, "there is an equal or higher versioned declarative revision", "first rollout should complete without errors")
// Second and third rollouts should have errors
- a.Contains(result2.Stderr, "failed to run and wait for rollout: found failed tasks", "Second rollout should have error")
- a.Contains(result3.Stderr, "failed to run and wait for rollout: found failed tasks", "Third rollout should have error")
+ a.Contains(result2.Stderr, "there is an equal or higher versioned declarative revision", "second rollout should have error")
+ a.Contains(result3.Stderr, "there is an equal or higher versioned declarative revision", "third rollout should have error")
})
t.Run("DeclarativeMultipleDatabases", func(t *testing.T) {