Skip to content

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

fix: use CreateSettingIfNotExistV2 instead of UpsertSettingV2 (#6157)

ecmadaof67eac698748
diff --git a/backend/api/v1/subscription_service.go b/backend/api/v1/subscription_service.go
index 337de50f2e..f66e893806 100644
--- a/backend/api/v1/subscription_service.go
+++ b/backend/api/v1/subscription_service.go
@@ -116,12 +116,16 @@ func (s *SubscriptionService) TrialSubscription(ctx context.Context, request *v1
}
principalID := ctx.Value(common.PrincipalIDContextKey).(int)
- if _, err := s.store.UpsertSettingV2(ctx, &store.SetSettingMessage{
+ _, created, err := s.store.CreateSettingIfNotExistV2(ctx, &store.SettingMessage{
Name: api.SettingEnterpriseTrial,
Value: string(value),
- }, principalID); err != nil {
+ }, principalID)
+ if err != nil {
return nil, status.Errorf(codes.Internal, "failed to create license: %v", err.Error())
}
+ if !created {
+ return nil, status.Errorf(codes.InvalidArgument, "your trial already exists")
+ }
// we need to override the SettingEnterpriseLicense with an empty value to get the valid free trial.
if err := s.licenseService.StoreLicense(ctx, &enterpriseAPI.SubscriptionPatch{
diff --git a/backend/tests/subscription_test.go b/backend/tests/subscription_test.go
index 83a135d942..447dba4c3a 100644
--- a/backend/tests/subscription_test.go
+++ b/backend/tests/subscription_test.go
@@ -42,26 +42,10 @@ func TestSubscription(t *testing.T) {
// Test trial the TEAM plan.
instanceCount: 20,
expectInstanceCount: 20,
- plan: v1pb.PlanType_TEAM,
- expectPlan: v1pb.PlanType_TEAM,
- Days: 7,
- },
- {
- // Test trial the ENTERPRISE plan.
- instanceCount: 10,
- expectInstanceCount: 10,
plan: v1pb.PlanType_ENTERPRISE,
expectPlan: v1pb.PlanType_ENTERPRISE,
Days: 7,
},
- {
- // Downgrade should be ignored.
- instanceCount: 99,
- expectInstanceCount: 10,
- plan: v1pb.PlanType_TEAM,
- expectPlan: v1pb.PlanType_ENTERPRISE,
- Days: 7,
- },
}
for _, trial := range trialList {