Skip to content

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

chore: clean schema (#15141)

Danny Xuc4998fd80221
diff --git a/backend/api/directory-sync/webhook.go b/backend/api/directory-sync/webhook.go
index 55717f2b31..ddc3796fe7 100644
--- a/backend/api/directory-sync/webhook.go
+++ b/backend/api/directory-sync/webhook.go
@@ -318,7 +318,7 @@ func (s *Service) RegisterDirectorySyncRoutes(g *echo.Group) {
Payload: &storepb.GroupPayload{
Source: entraIDSource,
},
- }, api.SystemBotID)
+ })
if err != nil {
return c.String(http.StatusInternalServerError, fmt.Sprintf("failed to create group, error %v", err))
}
@@ -544,7 +544,7 @@ func (s *Service) RegisterDirectorySyncRoutes(g *echo.Group) {
}
}
- updatedGroup, err := s.store.UpdateGroup(ctx, group.Email, updateGroup, api.SystemBotID)
+ updatedGroup, err := s.store.UpdateGroup(ctx, group.Email, updateGroup)
if err != nil {
return c.String(http.StatusInternalServerError, fmt.Sprintf("failed to update group, error %v", err))
}
diff --git a/backend/api/v1/anomaly_service.go b/backend/api/v1/anomaly_service.go
index 781b65721f..668ed54210 100644
--- a/backend/api/v1/anomaly_service.go
+++ b/backend/api/v1/anomaly_service.go
@@ -44,10 +44,8 @@ func (s *AnomalyService) SearchAnomalies(ctx context.Context, request *v1pb.Sear
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
- rowStatus := api.Normal
find := &store.ListAnomalyMessage{
ProjectID: projectID,
- RowStatus: &rowStatus,
}
if request.Filter != "" {
// We only support filter by type and resource now.
@@ -114,7 +112,7 @@ func (s *AnomalyService) SearchAnomalies(ctx context.Context, request *v1pb.Sear
func (s *AnomalyService) convertToAnomaly(ctx context.Context, anomaly *store.AnomalyMessage) (*v1pb.Anomaly, error) {
pbAnomaly := &v1pb.Anomaly{
- CreateTime: timestamppb.New(time.Unix(anomaly.CreatedTs, 0)),
+ CreateTime: timestamppb.New(time.Unix(anomaly.UpdatedTs, 0)),
UpdateTime: timestamppb.New(time.Unix(anomaly.UpdatedTs, 0)),
}
diff --git a/backend/api/v1/auth_service.go b/backend/api/v1/auth_service.go
index 057e732e7d..d5b7b346d3 100644
--- a/backend/api/v1/auth_service.go
+++ b/backend/api/v1/auth_service.go
@@ -229,9 +229,8 @@ func (s *AuthService) CreateUser(ctx context.Context, request *v1pb.CreateUserRe
if firstEndUser {
// The first end user should be workspace admin.
updateRole := &store.PatchIamPolicyMessage{
- Member: common.FormatUserUID(user.ID),
- UpdaterUID: creatorUID,
- Roles: []string{common.FormatRole(api.WorkspaceAdmin.String())},
+ Member: common.FormatUserUID(user.ID),
+ Roles: []string{common.FormatRole(api.WorkspaceAdmin.String())},
}
if _, err := s.store.PatchWorkspaceIamPolicy(ctx, updateRole); err != nil {
return nil, err
diff --git a/backend/api/v1/database_group_service.go b/backend/api/v1/database_group_service.go
index 2d193125ed..0c1bd6a3c4 100644
--- a/backend/api/v1/database_group_service.go
+++ b/backend/api/v1/database_group_service.go
@@ -88,11 +88,7 @@ func (s *DatabaseGroupService) CreateDatabaseGroup(ctx context.Context, request
return s.convertStoreToAPIDatabaseGroupFull(ctx, storeDatabaseGroup, projectResourceID)
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
- databaseGroup, err := s.store.CreateDatabaseGroup(ctx, principalID, storeDatabaseGroup)
+ databaseGroup, err := s.store.CreateDatabaseGroup(ctx, storeDatabaseGroup)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
@@ -155,11 +151,7 @@ func (s *DatabaseGroupService) UpdateDatabaseGroup(ctx context.Context, request
return nil, status.Errorf(codes.InvalidArgument, "unsupported path: %q", path)
}
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
- databaseGroup, err := s.store.UpdateDatabaseGroup(ctx, principalID, existedDatabaseGroup.UID, &updateDatabaseGroup)
+ databaseGroup, err := s.store.UpdateDatabaseGroup(ctx, existedDatabaseGroup.UID, &updateDatabaseGroup)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
diff --git a/backend/api/v1/environment_service.go b/backend/api/v1/environment_service.go
index 03b7bef4d6..b3dd27754d 100644
--- a/backend/api/v1/environment_service.go
+++ b/backend/api/v1/environment_service.go
@@ -53,10 +53,6 @@ func (s *EnvironmentService) ListEnvironments(ctx context.Context, request *v1pb
// CreateEnvironment creates an environment.
func (s *EnvironmentService) CreateEnvironment(ctx context.Context, request *v1pb.CreateEnvironmentRequest) (*v1pb.Environment, error) {
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
if request.Environment == nil {
return nil, status.Errorf(codes.InvalidArgument, "environment must be set")
}
@@ -93,7 +89,6 @@ func (s *EnvironmentService) CreateEnvironment(ctx context.Context, request *v1p
environment, err := s.store.CreateEnvironmentV2(ctx,
pendingCreate,
- principalID,
)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
@@ -103,10 +98,6 @@ func (s *EnvironmentService) CreateEnvironment(ctx context.Context, request *v1p
// UpdateEnvironment updates an environment.
func (s *EnvironmentService) UpdateEnvironment(ctx context.Context, request *v1pb.UpdateEnvironmentRequest) (*v1pb.Environment, error) {
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
if request.Environment == nil {
return nil, status.Errorf(codes.InvalidArgument, "environment must be set")
}
@@ -146,7 +137,6 @@ func (s *EnvironmentService) UpdateEnvironment(ctx context.Context, request *v1p
environment, err = s.store.UpdateEnvironmentV2(ctx,
environment.ResourceID,
patch,
- principalID,
)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
@@ -156,11 +146,6 @@ func (s *EnvironmentService) UpdateEnvironment(ctx context.Context, request *v1p
// DeleteEnvironment deletes an environment.
func (s *EnvironmentService) DeleteEnvironment(ctx context.Context, request *v1pb.DeleteEnvironmentRequest) (*emptypb.Empty, error) {
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
-
environment, err := s.getEnvironmentMessage(ctx, request.Name)
if err != nil {
return nil, err
@@ -178,7 +163,7 @@ func (s *EnvironmentService) DeleteEnvironment(ctx context.Context, request *v1p
return nil, status.Errorf(codes.FailedPrecondition, "all instances in the environment should be deleted first")
}
- if _, err := s.store.UpdateEnvironmentV2(ctx, environment.ResourceID, &store.UpdateEnvironmentMessage{Delete: &deletePatch}, principalID); err != nil {
+ if _, err := s.store.UpdateEnvironmentV2(ctx, environment.ResourceID, &store.UpdateEnvironmentMessage{Delete: &deletePatch}); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return &emptypb.Empty{}, nil
@@ -186,11 +171,6 @@ func (s *EnvironmentService) DeleteEnvironment(ctx context.Context, request *v1p
// UndeleteEnvironment undeletes an environment.
func (s *EnvironmentService) UndeleteEnvironment(ctx context.Context, request *v1pb.UndeleteEnvironmentRequest) (*v1pb.Environment, error) {
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
-
environment, err := s.getEnvironmentMessage(ctx, request.Name)
if err != nil {
return nil, err
@@ -199,7 +179,7 @@ func (s *EnvironmentService) UndeleteEnvironment(ctx context.Context, request *v
return nil, status.Errorf(codes.InvalidArgument, "environment %q is active", request.Name)
}
- environment, err = s.store.UpdateEnvironmentV2(ctx, environment.ResourceID, &store.UpdateEnvironmentMessage{Delete: &undeletePatch}, principalID)
+ environment, err = s.store.UpdateEnvironmentV2(ctx, environment.ResourceID, &store.UpdateEnvironmentMessage{Delete: &undeletePatch})
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
diff --git a/backend/api/v1/group_service.go b/backend/api/v1/group_service.go
index db60f6d35a..293e0477e5 100644
--- a/backend/api/v1/group_service.go
+++ b/backend/api/v1/group_service.go
@@ -6,7 +6,6 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
- "google.golang.org/protobuf/types/known/timestamppb"
"github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/component/iam"
@@ -82,12 +81,7 @@ func (s *GroupService) CreateGroup(ctx context.Context, request *v1pb.CreateGrou
return nil, status.Errorf(codes.InvalidArgument, "invalid email %q, error: %v", groupMessage.Email, err)
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
-
- group, err := s.store.CreateGroup(ctx, groupMessage, principalID)
+ group, err := s.store.CreateGroup(ctx, groupMessage)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
@@ -157,7 +151,7 @@ func (s *GroupService) UpdateGroup(ctx context.Context, request *v1pb.UpdateGrou
}
}
- groupMessage, err := s.store.UpdateGroup(ctx, groupEmail, patch, user.ID)
+ groupMessage, err := s.store.UpdateGroup(ctx, groupEmail, patch)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
@@ -282,20 +276,11 @@ func (s *GroupService) convertToV1Group(ctx context.Context, groupMessage *store
if groupMessage == nil {
return nil, status.Errorf(codes.NotFound, "cannot found group")
}
- creator, err := s.store.GetUserByID(ctx, groupMessage.CreatorUID)
- if err != nil {
- return nil, status.Errorf(codes.Internal, "failed to get creator, error %v", err)
- }
- if creator == nil {
- return nil, status.Errorf(codes.NotFound, "creator %d not found", groupMessage.CreatorUID)
- }
group := &v1pb.Group{
Name: common.FormatGroupEmail(groupMessage.Email),
Title: groupMessage.Title,
Description: groupMessage.Description,
- Creator: common.FormatUserEmail(creator.Email),
- CreateTime: timestamppb.New(groupMessage.CreatedTime),
Source: groupMessage.Payload.Source,
}
diff --git a/backend/api/v1/instance_service.go b/backend/api/v1/instance_service.go
index 278b3a5307..ae045d2e6b 100644
--- a/backend/api/v1/instance_service.go
+++ b/backend/api/v1/instance_service.go
@@ -173,13 +173,8 @@ func (s *InstanceService) CreateInstance(ctx context.Context, request *v1pb.Crea
return nil, err
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
instance, err := s.store.CreateInstanceV2(ctx,
instanceMessage,
- principalID,
instanceCountLimit,
)
if err != nil {
@@ -267,13 +262,8 @@ func (s *InstanceService) UpdateInstance(ctx context.Context, request *v1pb.Upda
return nil, status.Errorf(codes.NotFound, "instance %q has been deleted", request.Instance.Name)
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
patch := &store.UpdateInstanceMessage{
ResourceID: instance.ResourceID,
- UpdaterID: principalID,
}
for _, path := range request.UpdateMask.Paths {
switch path {
@@ -556,14 +546,9 @@ func (s *InstanceService) DeleteInstance(ctx context.Context, request *v1pb.Dele
}
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
if _, err := s.store.UpdateInstanceV2(ctx, &store.UpdateInstanceMessage{
ResourceID: instance.ResourceID,
Deleted: &deletePatch,
- UpdaterID: principalID,
}, -1 /* don't need to pass the instance limition */); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
@@ -581,14 +566,9 @@ func (s *InstanceService) UndeleteInstance(ctx context.Context, request *v1pb.Un
return nil, status.Errorf(codes.InvalidArgument, "instance %q is active", request.Name)
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
ins, err := s.store.UpdateInstanceV2(ctx, &store.UpdateInstanceMessage{
ResourceID: instance.ResourceID,
Deleted: &undeletePatch,
- UpdaterID: principalID,
}, -1 /* don't need to pass the instance limition */)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
@@ -705,11 +685,7 @@ func (s *InstanceService) AddDataSource(ctx context.Context, request *v1pb.AddDa
return nil, status.Error(codes.PermissionDenied, err.Error())
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
- if err := s.store.AddDataSourceToInstanceV2(ctx, instance.UID, principalID, instance.ResourceID, dataSource); err != nil {
+ if err := s.store.AddDataSourceToInstanceV2(ctx, instance.UID, instance.ResourceID, dataSource); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
@@ -759,12 +735,7 @@ func (s *InstanceService) UpdateDataSource(ctx context.Context, request *v1pb.Up
}
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
patch := &store.UpdateDataSourceMessage{
- UpdaterID: principalID,
InstanceUID: instance.UID,
InstanceID: instance.ResourceID,
DataSourceID: request.DataSource.Id,
diff --git a/backend/api/v1/issue_service.go b/backend/api/v1/issue_service.go
index 2fd788c165..bb003d3ec3 100644
--- a/backend/api/v1/issue_service.go
+++ b/backend/api/v1/issue_service.go
@@ -1516,13 +1516,8 @@ func (s *IssueService) UpdateIssueComment(ctx context.Context, request *v1pb.Upd
return nil, status.Errorf(codes.NotFound, "issue comment not found")
}
- user, ok := ctx.Value(common.UserContextKey).(*store.UserMessage)
- if !ok {
- return nil, status.Errorf(codes.Internal, "user not found")
- }
update := &store.UpdateIssueCommentMessage{
- UID: issueCommentUID,
- UpdaterID: user.ID,
+ UID: issueCommentUID,
}
for _, path := range request.UpdateMask.Paths {
switch path {
@@ -1577,10 +1572,7 @@ func (s *IssueService) updateExternalApprovalWithStatus(ctx context.Context, iss
}
}
- if _, err := s.store.UpdateExternalApprovalV2(ctx, &store.UpdateExternalApprovalMessage{
- ID: approval.ID,
- RowStatus: api.Archived,
- }); err != nil {
+ if err := s.store.DeleteExternalApprovalV2(ctx, approval.ID); err != nil {
return nil, status.Errorf(codes.Internal, "failed to update external approval, error: %v", err)
}
diff --git a/backend/api/v1/org_policy_service.go b/backend/api/v1/org_policy_service.go
index c999619c30..b11b14dd7a 100644
--- a/backend/api/v1/org_policy_service.go
+++ b/backend/api/v1/org_policy_service.go
@@ -104,16 +104,12 @@ func (s *OrgPolicyService) ListPolicies(ctx context.Context, request *v1pb.ListP
// CreatePolicy creates a policy in a specific resource.
func (s *OrgPolicyService) CreatePolicy(ctx context.Context, request *v1pb.CreatePolicyRequest) (*v1pb.Policy, error) {
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
if request.Policy == nil {
return nil, status.Errorf(codes.InvalidArgument, "policy must be set")
}
// TODO(d): validate policy.
- return s.createPolicyMessage(ctx, principalID, request.Parent, request.Policy)
+ return s.createPolicyMessage(ctx, request.Parent, request.Policy)
}
// UpdatePolicy updates a policy in a specific resource.
@@ -122,15 +118,11 @@ func (s *OrgPolicyService) UpdatePolicy(ctx context.Context, request *v1pb.Updat
return nil, status.Errorf(codes.InvalidArgument, "policy must be set")
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
policy, parent, err := s.findPolicyMessage(ctx, request.Policy.Name)
if err != nil {
st := status.Convert(err)
if st.Code() == codes.NotFound && request.AllowMissing {
- return s.createPolicyMessage(ctx, principalID, parent, request.Policy)
+ return s.createPolicyMessage(ctx, parent, request.Policy)
}
return nil, err
}
@@ -140,7 +132,6 @@ func (s *OrgPolicyService) UpdatePolicy(ctx context.Context, request *v1pb.Updat
}
patch := &store.UpdatePolicyMessage{
- UpdaterID: principalID,
ResourceType: policy.ResourceType,
Type: policy.Type,
ResourceUID: policy.ResourceUID,
@@ -376,7 +367,7 @@ func (s *OrgPolicyService) findActiveDatabase(ctx context.Context, find *store.F
return database, nil
}
-func (s *OrgPolicyService) createPolicyMessage(ctx context.Context, creatorID int, parent string, policy *v1pb.Policy) (*v1pb.Policy, error) {
+func (s *OrgPolicyService) createPolicyMessage(ctx context.Context, parent string, policy *v1pb.Policy) (*v1pb.Policy, error) {
resourceType, resourceID, err := s.getPolicyResourceTypeAndID(ctx, parent)
if err != nil {
return nil, err
@@ -415,7 +406,7 @@ func (s *OrgPolicyService) createPolicyMessage(ctx context.Context, creatorID in
create.ResourceUID = *resourceID
}
- p, err := s.store.CreatePolicyV2(ctx, create, creatorID)
+ p, err := s.store.CreatePolicyV2(ctx, create)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
diff --git a/backend/api/v1/project_service.go b/backend/api/v1/project_service.go
index 53bc50c557..f56f3ecae5 100644
--- a/backend/api/v1/project_service.go
+++ b/backend/api/v1/project_service.go
@@ -166,12 +166,7 @@ func (s *ProjectService) UpdateProject(ctx context.Context, request *v1pb.Update
return nil, status.Errorf(codes.InvalidArgument, "default project cannot be updated")
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
patch := &store.UpdateProjectMessage{
- UpdaterID: principalID,
ResourceID: project.ResourceID,
}
@@ -310,12 +305,7 @@ func (s *ProjectService) DeleteProject(ctx context.Context, request *v1pb.Delete
}
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
if _, err := s.store.UpdateProjectV2(ctx, &store.UpdateProjectMessage{
- UpdaterID: principalID,
ResourceID: project.ResourceID,
Delete: &deletePatch,
}); err != nil {
@@ -335,12 +325,7 @@ func (s *ProjectService) UndeleteProject(ctx context.Context, request *v1pb.Unde
return nil, status.Errorf(codes.InvalidArgument, "project %q is active", request.Name)
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
project, err = s.store.UpdateProjectV2(ctx, &store.UpdateProjectMessage{
- UpdaterID: principalID,
ResourceID: project.ResourceID,
Delete: &undeletePatch,
})
@@ -417,11 +402,6 @@ func (s *ProjectService) SetIamPolicy(ctx context.Context, request *v1pb.SetIamP
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
- creatorUID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "cannot get principal ID from context")
- }
-
if err := s.validateIAMPolicy(ctx, request.Policy); err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
@@ -465,7 +445,7 @@ func (s *ProjectService) SetIamPolicy(ctx context.Context, request *v1pb.SetIamP
InheritFromParent: false,
// Enforce cannot be false while creating a policy.
Enforce: true,
- }, creatorUID); err != nil {
+ }); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
@@ -652,11 +632,7 @@ func (s *ProjectService) UpdateDeploymentConfig(ctx context.Context, request *v1
return nil, status.Error(codes.InvalidArgument, err.Error())
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
- deploymentConfig, err := s.store.UpsertDeploymentConfigV2(ctx, project.UID, principalID, storeDeploymentConfig)
+ deploymentConfig, err := s.store.UpsertDeploymentConfigV2(ctx, project.UID, storeDeploymentConfig)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
@@ -687,11 +663,7 @@ func (s *ProjectService) AddWebhook(ctx context.Context, request *v1pb.AddWebhoo
return nil, status.Error(codes.InvalidArgument, err.Error())
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
- if _, err := s.store.CreateProjectWebhookV2(ctx, principalID, project.UID, project.ResourceID, create); err != nil {
+ if _, err := s.store.CreateProjectWebhookV2(ctx, project.UID, project.ResourceID, create); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
@@ -766,11 +738,7 @@ func (s *ProjectService) UpdateWebhook(ctx context.Context, request *v1pb.Update
}
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
- if _, err := s.store.UpdateProjectWebhookV2(ctx, principalID, project.ResourceID, webhook.ID, update); err != nil {
+ if _, err := s.store.UpdateProjectWebhookV2(ctx, project.ResourceID, webhook.ID, update); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
diff --git a/backend/api/v1/review_config_service.go b/backend/api/v1/review_config_service.go
index 52923a2aa3..ade37a4bf1 100644
--- a/backend/api/v1/review_config_service.go
+++ b/backend/api/v1/review_config_service.go
@@ -6,7 +6,6 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
- "google.golang.org/protobuf/types/known/timestamppb"
"github.com/pkg/errors"
@@ -47,12 +46,6 @@ func (s *ReviewConfigService) CreateReviewConfig(ctx context.Context, request *v
return nil, err
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
-
- reviewConfigMessage.CreatorUID = principalID
created, err := s.store.CreateReviewConfig(ctx, reviewConfigMessage)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
@@ -104,10 +97,6 @@ func (s *ReviewConfigService) UpdateReviewConfig(ctx context.Context, request *v
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
existed, err := s.store.GetReviewConfig(ctx, id)
if err != nil {
@@ -123,8 +112,7 @@ func (s *ReviewConfigService) UpdateReviewConfig(ctx context.Context, request *v
}
patch := &store.PatchReviewConfigMessage{
- ID: id,
- UpdaterID: principalID,
+ ID: id,
}
for _, path := range request.UpdateMask.Paths {
@@ -193,14 +181,6 @@ func convertToReviewConfigMessage(reviewConfig *v1pb.ReviewConfig) (*store.Revie
}
func (s *ReviewConfigService) convertToV1ReviewConfig(ctx context.Context, reviewConfigMessage *store.ReviewConfigMessage) (*v1pb.ReviewConfig, error) {
- creator, err := s.store.GetUserByID(ctx, reviewConfigMessage.CreatorUID)
- if err != nil {
- return nil, status.Errorf(codes.Internal, "failed to get creator, error %v", err)
- }
- if creator == nil {
- return nil, status.Errorf(codes.NotFound, "creator %d not found", reviewConfigMessage.CreatorUID)
- }
-
policyType := api.PolicyTypeTag
tagPolicies, err := s.store.ListPoliciesV2(ctx, &store.FindPolicyMessage{
Type: &policyType,
@@ -211,13 +191,10 @@ func (s *ReviewConfigService) convertToV1ReviewConfig(ctx context.Context, revie
}
config := &v1pb.ReviewConfig{
- Name: common.FormatReviewConfig(reviewConfigMessage.ID),
- Creator: common.FormatUserEmail(creator.Email),
- CreateTime: timestamppb.New(reviewConfigMessage.CreatedTime),
- UpdateTime: timestamppb.New(reviewConfigMessage.CreatedTime),
- Title: reviewConfigMessage.Name,
- Enabled: reviewConfigMessage.Enforce,
- Rules: convertToV1PBSQLReviewRules(reviewConfigMessage.Payload.SqlReviewRules),
+ Name: common.FormatReviewConfig(reviewConfigMessage.ID),
+ Title: reviewConfigMessage.Name,
+ Enabled: reviewConfigMessage.Enforce,
+ Rules: convertToV1PBSQLReviewRules(reviewConfigMessage.Payload.SqlReviewRules),
}
for _, policy := range tagPolicies {
diff --git a/backend/api/v1/risk_service.go b/backend/api/v1/risk_service.go
index f2f2477113..a4f1934dcc 100644
--- a/backend/api/v1/risk_service.go
+++ b/backend/api/v1/risk_service.go
@@ -67,10 +67,6 @@ func (s *RiskService) CreateRisk(ctx context.Context, request *v1pb.CreateRiskRe
if _, err := common.ConvertUnparsedRisk(request.Risk.Condition); err != nil {
return nil, status.Errorf(codes.InvalidArgument, "failed to validate risk expression, error: %v", err)
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
risk, err := s.store.CreateRisk(ctx, &store.RiskMessage{
Source: convertSource(request.Risk.Source),
@@ -78,7 +74,7 @@ func (s *RiskService) CreateRisk(ctx context.Context, request *v1pb.CreateRiskRe
Name: request.Risk.Title,
Active: request.Risk.Active,
Expression: request.Risk.Condition,
- }, principalID)
+ })
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
@@ -90,10 +86,6 @@ func (s *RiskService) UpdateRisk(ctx context.Context, request *v1pb.UpdateRiskRe
if err := s.licenseService.IsFeatureEnabled(api.FeatureCustomApproval); err != nil {
return nil, status.Error(codes.PermissionDenied, err.Error())
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
if request.UpdateMask == nil {
return nil, status.Errorf(codes.InvalidArgument, "update_mask must be set")
}
@@ -108,9 +100,6 @@ func (s *RiskService) UpdateRisk(ctx context.Context, request *v1pb.UpdateRiskRe
if risk == nil {
return nil, status.Errorf(codes.NotFound, "risk %v not found", request.Risk.Name)
}
- if risk.Deleted {
- return nil, status.Errorf(codes.InvalidArgument, "risk %v has been deleted", request.Risk.Name)
- }
patch := &store.UpdateRiskMessage{}
for _, path := range request.UpdateMask.Paths {
@@ -129,7 +118,7 @@ func (s *RiskService) UpdateRisk(ctx context.Context, request *v1pb.UpdateRiskRe
}
}
- risk, err = s.store.UpdateRisk(ctx, patch, riskID, principalID)
+ risk, err = s.store.UpdateRisk(ctx, patch, riskID)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
@@ -139,10 +128,6 @@ func (s *RiskService) UpdateRisk(ctx context.Context, request *v1pb.UpdateRiskRe
// DeleteRisk deletes a risk.
func (s *RiskService) DeleteRisk(ctx context.Context, request *v1pb.DeleteRiskRequest) (*emptypb.Empty, error) {
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
riskID, err := common.GetRiskID(request.Name)
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
@@ -154,17 +139,8 @@ func (s *RiskService) DeleteRisk(ctx context.Context, request *v1pb.DeleteRiskRe
if risk == nil {
return nil, status.Errorf(codes.NotFound, "risk %v not found", request.Name)
}
- if risk.Deleted {
- return nil, status.Errorf(codes.InvalidArgument, "risk %v has been deleted", request.Name)
- }
- rowStatusArchived := api.Archived
- if _, err := s.store.UpdateRisk(ctx,
- &store.UpdateRiskMessage{
- RowStatus: &rowStatusArchived,
- },
- riskID,
- principalID); err != nil {
+ if err := s.store.DeleteRisk(ctx, riskID); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
diff --git a/backend/api/v1/role_service.go b/backend/api/v1/role_service.go
index 91749dd5d1..6029596069 100644
--- a/backend/api/v1/role_service.go
+++ b/backend/api/v1/role_service.go
@@ -84,10 +84,6 @@ func (s *RoleService) CreateRole(ctx context.Context, request *v1pb.CreateRoleRe
if err := s.licenseService.IsFeatureEnabled(api.FeatureCustomRole); err != nil {
return nil, status.Error(codes.PermissionDenied, err.Error())
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
if predefinedRole := s.getBuildinRole(request.RoleId); predefinedRole != nil {
return nil, status.Errorf(codes.InvalidArgument, "role %s is a built-in role", request.RoleId)
@@ -110,7 +106,7 @@ func (s *RoleService) CreateRole(ctx context.Context, request *v1pb.CreateRoleRe
if ok := iam.PermissionsExist(request.Role.Permissions...); !ok {
return nil, status.Errorf(codes.InvalidArgument, "invalid permissions")
}
- roleMessage, err := s.store.CreateRole(ctx, create, principalID)
+ roleMessage, err := s.store.CreateRole(ctx, create)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to create role: %v", err)
}
@@ -128,10 +124,6 @@ func (s *RoleService) UpdateRole(ctx context.Context, request *v1pb.UpdateRoleRe
if request.UpdateMask == nil {
return nil, status.Errorf(codes.InvalidArgument, "update_mask must be set")
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
roleID, err := common.GetRoleID(request.Role.Name)
if err != nil {
return nil, status.Error(codes.InvalidArgument, err.Error())
@@ -153,7 +145,6 @@ func (s *RoleService) UpdateRole(ctx context.Context, request *v1pb.UpdateRoleRe
return nil, status.Errorf(codes.NotFound, "role not found: %s", roleID)
}
patch := &store.UpdateRoleMessage{
- UpdaterID: principalID,
ResourceID: roleID,
}
for _, path := range request.UpdateMask.Paths {
diff --git a/backend/api/v1/setting_service.go b/backend/api/v1/setting_service.go
index 56250b8bc2..1da78a1ec7 100644
--- a/backend/api/v1/setting_service.go
+++ b/backend/api/v1/setting_service.go
@@ -620,14 +620,10 @@ func (s *SettingService) UpdateSetting(ctx context.Context, request *v1pb.Update
default:
storeSettingValue = request.Setting.Value.GetStringValue()
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
setting, err := s.store.UpsertSettingV2(ctx, &store.SetSettingMessage{
Name: apiSettingName,
Value: storeSettingValue,
- }, principalID)
+ })
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to set setting: %v", err)
}
@@ -646,7 +642,6 @@ func (s *SettingService) UpdateSetting(ctx context.Context, request *v1pb.Update
}
for _, project := range projects {
patch := &store.UpdateProjectMessage{
- UpdaterID: principalID,
ResourceID: project.ResourceID,
DataClassificationConfigID: &classificationID,
}
diff --git a/backend/api/v1/vcs_connector_service.go b/backend/api/v1/vcs_connector_service.go
index 7c8811fc70..9ee37b9508 100644
--- a/backend/api/v1/vcs_connector_service.go
+++ b/backend/api/v1/vcs_connector_service.go
@@ -6,12 +6,10 @@ import (
"fmt"
"log/slog"
"strings"
- "time"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
- "google.golang.org/protobuf/types/known/timestamppb"
"github.com/pkg/errors"
@@ -45,10 +43,6 @@ func (s *VCSConnectorService) CreateVCSConnector(ctx context.Context, request *v
if request.VcsConnector == nil {
return nil, status.Errorf(codes.InvalidArgument, "vcs connector must be set")
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
setting, err := s.store.GetWorkspaceGeneralSetting(ctx)
if err != nil {
@@ -124,7 +118,6 @@ func (s *VCSConnectorService) CreateVCSConnector(ctx context.Context, request *v
vcsConnectorCreate := &store.VCSConnectorMessage{
ProjectID: project.ResourceID,
ResourceID: request.VcsConnectorId,
- CreatorID: principalID,
VCSUID: vcsProvider.ID,
VCSResourceID: vcsProvider.ResourceID,
Payload: &storepb.VCSConnector{
@@ -162,7 +155,7 @@ func (s *VCSConnectorService) CreateVCSConnector(ctx context.Context, request *v
if err != nil {
return nil, err
}
- v1VCSConnector, err := convertStoreVCSConnector(ctx, s.store, vcsConnector)
+ v1VCSConnector, err := convertStoreVCSConnector(vcsConnector)
if err != nil {
return nil, err
}
@@ -192,7 +185,7 @@ func (s *VCSConnectorService) GetVCSConnector(ctx context.Context, request *v1pb
if vcsConnector == nil {
return nil, status.Errorf(codes.NotFound, "vcs connector %q not found", vcsConnectorID)
}
- v1VCSConnector, err := convertStoreVCSConnector(ctx, s.store, vcsConnector)
+ v1VCSConnector, err := convertStoreVCSConnector(vcsConnector)
if err != nil {
return nil, err
}
@@ -222,7 +215,7 @@ func (s *VCSConnectorService) ListVCSConnectors(ctx context.Context, request *v1
resp := &v1pb.ListVCSConnectorsResponse{}
for _, vcsConnector := range vcsConnectors {
- v1VCSConnector, err := convertStoreVCSConnector(ctx, s.store, vcsConnector)
+ v1VCSConnector, err := convertStoreVCSConnector(vcsConnector)
if err != nil {
return nil, err
}
@@ -270,13 +263,8 @@ func (s *VCSConnectorService) UpdateVCSConnector(ctx context.Context, request *v
return nil, status.Errorf(codes.NotFound, "vcs provider %s not found", vcsConnector.VCSResourceID)
}
- user, ok := ctx.Value(common.UserContextKey).(*store.UserMessage)
- if !ok {
- return nil, status.Errorf(codes.Internal, "user not found")
- }
update := &store.UpdateVCSConnectorMessage{
ProjectID: project.ResourceID,
- UpdaterID: user.ID,
UID: vcsConnector.UID,
}
@@ -315,7 +303,7 @@ func (s *VCSConnectorService) UpdateVCSConnector(ctx context.Context, request *v
return nil, err
}
- v1VCSConnector, err := convertStoreVCSConnector(ctx, s.store, vcsConnector)
+ v1VCSConnector, err := convertStoreVCSConnector(vcsConnector)
if err != nil {
return nil, err
}
@@ -377,28 +365,9 @@ func (s *VCSConnectorService) DeleteVCSConnector(ctx context.Context, request *v
return &emptypb.Empty{}, nil
}
-func convertStoreVCSConnector(ctx context.Context, stores *store.Store, vcsConnector *store.VCSConnectorMessage) (*v1pb.VCSConnector, error) {
- creator, err := stores.GetUserByID(ctx, vcsConnector.CreatorID)
- if err != nil {
- return nil, status.Errorf(codes.Internal, "failed to get creator: %v", err)
- }
- if creator == nil {
- return nil, status.Errorf(codes.NotFound, "cannot find the creator: %d", vcsConnector.CreatorID)
- }
- updater, err := stores.GetUserByID(ctx, vcsConnector.UpdaterID)
- if err != nil {
- return nil, status.Errorf(codes.Internal, "failed to get updater: %v", err)
- }
- if updater == nil {
- return nil, status.Errorf(codes.NotFound, "cannot find the updater: %d", vcsConnector.UpdaterID)
- }
-
+func convertStoreVCSConnector(vcsConnector *store.VCSConnectorMessage) (*v1pb.VCSConnector, error) {
v1VCSConnector := &v1pb.VCSConnector{
Name: fmt.Sprintf("%s/%s%s", common.FormatProject(vcsConnector.ProjectID), common.VCSConnectorPrefix, vcsConnector.ResourceID),
- CreateTime: timestamppb.New(time.Unix(vcsConnector.CreatedTs, 0)),
- UpdateTime: timestamppb.New(time.Unix(vcsConnector.UpdatedTs, 0)),
- Creator: fmt.Sprintf("users/%s", creator.Email),
- Updater: fmt.Sprintf("users/%s", updater.Email),
Title: vcsConnector.Payload.Title,
VcsProvider: fmt.Sprintf("%s%s", common.VCSProviderPrefix, vcsConnector.VCSResourceID),
ExternalId: vcsConnector.Payload.ExternalId,
diff --git a/backend/api/v1/vcs_provider_service.go b/backend/api/v1/vcs_provider_service.go
index 7fe704f142..6b831dd63b 100644
--- a/backend/api/v1/vcs_provider_service.go
+++ b/backend/api/v1/vcs_provider_service.go
@@ -68,11 +68,7 @@ func (s *VCSProviderService) CreateVCSProvider(ctx context.Context, request *v1p
return nil, err
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
- storeVCSProvider, err := s.store.CreateVCSProvider(ctx, principalID, vcsProvider)
+ storeVCSProvider, err := s.store.CreateVCSProvider(ctx, vcsProvider)
if err != nil {
return nil, status.Errorf(codes.Internal, "Failed to create vcs provider: %v", err)
}
@@ -108,11 +104,7 @@ func (s *VCSProviderService) UpdateVCSProvider(ctx context.Context, request *v1p
}
}
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
- vcsProvider, err = s.store.UpdateVCSProvider(ctx, principalID, vcsProvider.ID, update)
+ vcsProvider, err = s.store.UpdateVCSProvider(ctx, vcsProvider.ID, update)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
@@ -177,7 +169,7 @@ func (s *VCSProviderService) ListVCSConnectorsInProvider(ctx context.Context, re
resp := &v1pb.ListVCSConnectorsInProviderResponse{}
for _, vcsConnector := range vcsConnectors {
- v1VCSConnector, err := convertStoreVCSConnector(ctx, s.store, vcsConnector)
+ v1VCSConnector, err := convertStoreVCSConnector(vcsConnector)
if err != nil {
return nil, err
}
diff --git a/backend/api/v1/workspace_service.go b/backend/api/v1/workspace_service.go
index 7512a7e99e..e755c07b80 100644
--- a/backend/api/v1/workspace_service.go
+++ b/backend/api/v1/workspace_service.go
@@ -7,7 +7,6 @@ import (
"google.golang.org/grpc/status"
"google.golang.org/protobuf/encoding/protojson"
- "github.com/bytebase/bytebase/backend/common"
"github.com/bytebase/bytebase/backend/component/iam"
api "github.com/bytebase/bytebase/backend/legacyapi"
"github.com/bytebase/bytebase/backend/store"
@@ -61,14 +60,8 @@ func (s *WorkspaceService) SetIamPolicy(ctx context.Context, request *v1pb.SetIa
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to marshal iam policy with error: %v", err.Error())
}
-
- principalID, ok := ctx.Value(common.PrincipalIDContextKey).(int)
- if !ok {
- return nil, status.Errorf(codes.Internal, "principal ID not found")
- }
payloadStr := string(payloadBytes)
patch := &store.UpdatePolicyMessage{
- UpdaterID: principalID,
ResourceType: api.PolicyResourceTypeWorkspace,
Type: api.PolicyTypeIAM,
Payload: &payloadStr,
diff --git a/backend/component/iam/manager.go b/backend/component/iam/manager.go
index 54f112a25c..db3f846ff3 100644
--- a/backend/component/iam/manager.go
+++ b/backend/component/iam/manager.go
@@ -178,7 +178,6 @@ func loadPredefinedRoles() ([]*store.RoleMessage, error) {
permissions[p] = true
}
roles = append(roles, &store.RoleMessage{
- CreatorID: api.SystemBotID,
ResourceID: resourceID,
Name: role.Title,
Description: "",
diff --git a/backend/enterprise/plugin/hub/hub.go b/backend/enterprise/plugin/hub/hub.go
index 419c9cb672..348465eae2 100644
--- a/backend/enterprise/plugin/hub/hub.go
+++ b/backend/enterprise/plugin/hub/hub.go
@@ -63,7 +63,7 @@ func (p *Provider) StoreLicense(ctx context.Context, patch *enterprise.Subscript
if _, err := p.store.UpsertSettingV2(ctx, &store.SetSettingMessage{
Name: api.SettingEnterpriseLicense,
Value: patch.License,
- }, patch.UpdaterID); err != nil {
+ }); err != nil {
return err
}
@@ -112,7 +112,7 @@ func (p *Provider) fetchLicense(ctx context.Context) (*enterprise.License, error
if _, err := p.store.UpsertSettingV2(ctx, &store.SetSettingMessage{
Name: api.SettingEnterpriseLicense,
Value: license,
- }, api.SystemBotID); err != nil {
+ }); err != nil {
return nil, errors.Wrapf(err, "failed to store the license")
}
diff --git a/backend/migrator/migration/3.4/0002##less_creator.sql b/backend/migrator/migration/3.4/0002##less_creator.sql
new file mode 100644
index 0000000000..6c2f2c94a6
--- /dev/null
+++ b/backend/migrator/migration/3.4/0002##less_creator.sql
@@ -0,0 +1,30 @@
+ALTER TABLE idp DROP COLUMN IF EXISTS created_ts, DROP COLUMN IF EXISTS updated_ts;
+ALTER TABLE setting DROP COLUMN IF EXISTS row_status, DROP COLUMN IF EXISTS creator_id, DROP COLUMN IF EXISTS created_ts, DROP COLUMN IF EXISTS updater_id, DROP COLUMN IF EXISTS updated_ts, DROP COLUMN IF EXISTS description;
+ALTER TABLE role DROP COLUMN IF EXISTS row_status, DROP COLUMN IF EXISTS creator_id, DROP COLUMN IF EXISTS created_ts, DROP COLUMN IF EXISTS updater_id, DROP COLUMN IF EXISTS updated_ts;
+ALTER TABLE environment DROP COLUMN IF EXISTS creator_id, DROP COLUMN IF EXISTS created_ts, DROP COLUMN IF EXISTS updater_id, DROP COLUMN IF EXISTS updated_ts;
+ALTER TABLE policy DROP COLUMN IF EXISTS creator_id, DROP COLUMN IF EXISTS created_ts, DROP COLUMN IF EXISTS updater_id, DROP COLUMN IF EXISTS updated_ts;
+ALTER TABLE policy ADD COLUMN IF NOT EXISTS updated_ts TIMESTAMPTZ NOT NULL DEFAULT now();
+ALTER TABLE project DROP COLUMN IF EXISTS creator_id, DROP COLUMN IF EXISTS created_ts, DROP COLUMN IF EXISTS updater_id, DROP COLUMN IF EXISTS updated_ts;
+ALTER TABLE project_webhook DROP COLUMN IF EXISTS row_status, DROP COLUMN IF EXISTS creator_id, DROP COLUMN IF EXISTS created_ts, DROP COLUMN IF EXISTS updater_id, DROP COLUMN IF EXISTS updated_ts;
+ALTER TABLE instance DROP COLUMN IF EXISTS creator_id, DROP COLUMN IF EXISTS created_ts, DROP COLUMN IF EXISTS updater_id, DROP COLUMN IF EXISTS updated_ts;
+DROP TABLE IF EXISTS instance_user;
+ALTER TABLE data_source DROP COLUMN IF EXISTS row_status, DROP COLUMN IF EXISTS creator_id, DROP COLUMN IF EXISTS created_ts, DROP COLUMN IF EXISTS updater_id, DROP COLUMN IF EXISTS updated_ts;
+ALTER TABLE task_dag DROP COLUMN IF EXISTS created_ts, DROP COLUMN IF EXISTS updated_ts, DROP COLUMN IF EXISTS payload;
+DROP TABLE IF EXISTS activity;
+ALTER TABLE issue_comment DROP COLUMN IF EXISTS row_status, DROP COLUMN IF EXISTS updater_id;
+ALTER TABLE query_history DROP COLUMN IF EXISTS row_status;
+ALTER TABLE vcs DROP COLUMN IF EXISTS row_status, DROP COLUMN IF EXISTS creator_id, DROP COLUMN IF EXISTS created_ts, DROP COLUMN IF EXISTS updater_id, DROP COLUMN IF EXISTS updated_ts;
+ALTER TABLE vcs_connector DROP COLUMN IF EXISTS row_status, DROP COLUMN IF EXISTS creator_id, DROP COLUMN IF EXISTS created_ts, DROP COLUMN IF EXISTS updater_id, DROP COLUMN IF EXISTS updated_ts;
+ALTER TABLE anomaly DROP COLUMN IF EXISTS row_status, DROP COLUMN IF EXISTS creator_id, DROP COLUMN IF EXISTS created_ts, DROP COLUMN IF EXISTS updater_id;
+ALTER TABLE deployment_config DROP COLUMN IF EXISTS row_status, DROP COLUMN IF EXISTS creator_id, DROP COLUMN IF EXISTS created_ts, DROP COLUMN IF EXISTS updater_id, DROP COLUMN IF EXISTS updated_ts;
+ALTER TABLE external_approval DROP COLUMN IF EXISTS row_status, DROP COLUMN IF EXISTS created_ts, DROP COLUMN IF EXISTS updated_ts;
+ALTER TABLE risk DROP COLUMN IF EXISTS row_status, DROP COLUMN IF EXISTS created_ts, DROP COLUMN IF EXISTS updated_ts;
+ALTER TABLE slow_query DROP COLUMN IF EXISTS row_status, DROP COLUMN IF EXISTS created_ts, DROP COLUMN IF EXISTS updated_ts;
+ALTER TABLE db_group DROP COLUMN IF EXISTS row_status, DROP COLUMN IF EXISTS created_ts, DROP COLUMN IF EXISTS updated_ts;
+ALTER TABLE changelist DROP COLUMN IF EXISTS row_status, DROP COLUMN IF EXISTS created_ts, DROP COLUMN IF EXISTS updated_ts;
+DROP TABLE IF EXISTS sql_lint_config;
+ALTER TABLE user_group DROP COLUMN IF EXISTS creator_id, DROP COLUMN IF EXISTS created_ts, DROP COLUMN IF EXISTS updater_id, DROP COLUMN IF EXISTS updated_ts;
+ALTER TABLE review_config DROP COLUMN IF EXISTS creator_id, DROP COLUMN IF EXISTS created_ts, DROP COLUMN IF EXISTS updater_id, DROP COLUMN IF EXISTS updated_ts;
+ALTER TABLE sync_history DROP COLUMN IF EXISTS creator_id;
+DROP INDEX IF EXISTS idx_external_approval_row_status_issue_id;
+CREATE INDEX idx_external_approval_issue_id ON external_approval(issue_id);
\ No newline at end of file
diff --git a/backend/migrator/migration/LATEST.sql b/backend/migrator/migration/LATEST.sql
index 09b6fa20a2..0322432284 100644
--- a/backend/migrator/migration/LATEST.sql
+++ b/backend/migrator/migration/LATEST.sql
@@ -5,8 +5,6 @@ CREATE TYPE row_status AS ENUM ('NORMAL', 'ARCHIVED');
CREATE TABLE idp (
id SERIAL PRIMARY KEY,
row_status row_status NOT NULL DEFAULT 'NORMAL',
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
resource_id TEXT NOT NULL,
name TEXT NOT NULL,
domain TEXT NOT NULL,
@@ -39,14 +37,8 @@ CREATE TABLE principal (
-- Setting
CREATE TABLE setting (
id SERIAL PRIMARY KEY,
- row_status row_status NOT NULL DEFAULT 'NORMAL',
- creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
name TEXT NOT NULL,
- value TEXT NOT NULL,
- description TEXT NOT NULL DEFAULT ''
+ value TEXT NOT NULL
);
CREATE UNIQUE INDEX idx_setting_unique_name ON setting(name);
@@ -56,12 +48,7 @@ ALTER SEQUENCE setting_id_seq RESTART WITH 101;
-- Role
CREATE TABLE role (
id BIGSERIAL PRIMARY KEY,
- row_status row_status NOT NULL DEFAULT 'NORMAL',
- creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- resource_id TEXT NOT NULL, -- user-defined id, such as projectDBA
+ resource_id TEXT NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
permissions JSONB NOT NULL DEFAULT '{}',
@@ -76,10 +63,6 @@ ALTER SEQUENCE role_id_seq RESTART WITH 101;
CREATE TABLE environment (
id SERIAL PRIMARY KEY,
row_status row_status NOT NULL DEFAULT 'NORMAL',
- creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
name TEXT NOT NULL,
"order" INTEGER NOT NULL CHECK ("order" >= 0),
resource_id TEXT NOT NULL
@@ -97,10 +80,7 @@ CREATE TYPE resource_type AS ENUM ('WORKSPACE', 'ENVIRONMENT', 'PROJECT', 'INSTA
CREATE TABLE policy (
id SERIAL PRIMARY KEY,
row_status row_status NOT NULL DEFAULT 'NORMAL',
- creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updated_ts TIMESTAMPTZ NOT NULL DEFAULT now(),
type TEXT NOT NULL CHECK (type LIKE 'bb.policy.%'),
payload JSONB NOT NULL DEFAULT '{}',
resource_type resource_type NOT NULL,
@@ -116,10 +96,6 @@ ALTER SEQUENCE policy_id_seq RESTART WITH 101;
CREATE TABLE project (
id SERIAL PRIMARY KEY,
row_status row_status NOT NULL DEFAULT 'NORMAL',
- creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
name TEXT NOT NULL,
key TEXT NOT NULL,
resource_id TEXT NOT NULL,
@@ -134,11 +110,6 @@ CREATE UNIQUE INDEX idx_project_unique_resource_id ON project(resource_id);
-- Project Hook
CREATE TABLE project_webhook (
id SERIAL PRIMARY KEY,
- row_status row_status NOT NULL DEFAULT 'NORMAL',
- creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
project_id INTEGER NOT NULL REFERENCES project (id),
type TEXT NOT NULL CHECK (type LIKE 'bb.plugin.webhook.%'),
name TEXT NOT NULL,
@@ -157,10 +128,6 @@ ALTER SEQUENCE project_webhook_id_seq RESTART WITH 101;
CREATE TABLE instance (
id SERIAL PRIMARY KEY,
row_status row_status NOT NULL DEFAULT 'NORMAL',
- creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
environment TEXT REFERENCES environment (resource_id),
name TEXT NOT NULL,
engine TEXT NOT NULL,
@@ -177,23 +144,6 @@ CREATE UNIQUE INDEX idx_instance_unique_resource_id ON instance(resource_id);
ALTER SEQUENCE instance_id_seq RESTART WITH 101;
--- Instance user stores the users for a particular instance
-CREATE TABLE instance_user (
- id SERIAL PRIMARY KEY,
- row_status row_status NOT NULL DEFAULT 'NORMAL',
- creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- instance_id INTEGER NOT NULL REFERENCES instance (id),
- name TEXT NOT NULL,
- "grant" TEXT NOT NULL
-);
-
-ALTER SEQUENCE instance_user_id_seq RESTART WITH 101;
-
-CREATE UNIQUE INDEX idx_instance_user_unique_instance_id_name ON instance_user(instance_id, name);
-
-- db stores the databases for a particular instance
-- data is synced periodically from the instance
CREATE TABLE db (
@@ -246,11 +196,6 @@ ALTER SEQUENCE db_schema_id_seq RESTART WITH 101;
-- data_source table stores the data source for a particular database
CREATE TABLE data_source (
id SERIAL PRIMARY KEY,
- row_status row_status NOT NULL DEFAULT 'NORMAL',
- creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
instance_id INTEGER NOT NULL REFERENCES instance (id),
name TEXT NOT NULL,
type TEXT NOT NULL CHECK (type IN ('ADMIN', 'RW', 'RO')),
@@ -364,11 +309,8 @@ ALTER SEQUENCE task_id_seq RESTART WITH 101;
-- from_task_id blocks to_task_id
CREATE TABLE task_dag (
id SERIAL PRIMARY KEY,
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
from_task_id INTEGER NOT NULL REFERENCES task (id),
- to_task_id INTEGER NOT NULL REFERENCES task (id),
- payload JSONB NOT NULL DEFAULT '{}'
+ to_task_id INTEGER NOT NULL REFERENCES task (id)
);
CREATE INDEX idx_task_dag_from_task_id ON task_dag(from_task_id);
@@ -517,30 +459,6 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_instance_change_history_unique_version ON
ALTER SEQUENCE instance_change_history_id_seq RESTART WITH 101;
--- activity table stores the activity for the container such as issue
-CREATE TABLE activity (
- id SERIAL PRIMARY KEY,
- row_status row_status NOT NULL DEFAULT 'NORMAL',
- creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- resource_container TEXT NOT NULL DEFAULT '',
- container_id INTEGER NOT NULL CHECK (container_id > 0),
- type TEXT NOT NULL CHECK (type LIKE 'bb.%'),
- level TEXT NOT NULL CHECK (level IN ('INFO', 'WARN', 'ERROR')),
- comment TEXT NOT NULL DEFAULT '',
- payload JSONB NOT NULL DEFAULT '{}'
-);
-
-CREATE INDEX idx_activity_resource_container ON activity(resource_container);
-
-CREATE INDEX idx_activity_container_id ON activity(container_id);
-
-CREATE INDEX idx_activity_created_ts ON activity(created_ts);
-
-ALTER SEQUENCE activity_id_seq RESTART WITH 101;
-
CREATE TABLE audit_log (
id BIGSERIAL PRIMARY KEY,
created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
@@ -561,10 +479,8 @@ ALTER SEQUENCE audit_log_id_seq RESTART WITH 101;
CREATE TABLE issue_comment (
id BIGSERIAL PRIMARY KEY,
- row_status row_status NOT NULL DEFAULT 'NORMAL',
creator_id INTEGER NOT NULL REFERENCES principal (id),
created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
issue_id INTEGER NOT NULL REFERENCES issue (id),
payload JSONB NOT NULL DEFAULT '{}'
@@ -576,7 +492,6 @@ ALTER SEQUENCE issue_comment_id_seq RESTART WITH 101;
CREATE TABLE query_history (
id BIGSERIAL PRIMARY KEY,
- row_status row_status NOT NULL DEFAULT 'NORMAL',
creator_id INTEGER NOT NULL REFERENCES principal (id),
created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
project_id TEXT NOT NULL, -- the project resource id
@@ -593,11 +508,6 @@ ALTER SEQUENCE query_history_id_seq RESTART WITH 101;
-- vcs table stores the version control provider config
CREATE TABLE vcs (
id SERIAL PRIMARY KEY,
- row_status row_status NOT NULL DEFAULT 'NORMAL',
- creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
resource_id TEXT NOT NULL,
name TEXT NOT NULL,
type TEXT NOT NULL CHECK (type IN ('GITLAB', 'GITHUB', 'BITBUCKET', 'AZURE_DEVOPS')),
@@ -612,11 +522,6 @@ ALTER SEQUENCE vcs_id_seq RESTART WITH 101;
-- vcs_connector table stores vcs connectors for a project
CREATE TABLE vcs_connector (
id SERIAL PRIMARY KEY,
- row_status row_status NOT NULL DEFAULT 'NORMAL',
- creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
vcs_id INTEGER NOT NULL REFERENCES vcs (id),
project_id INTEGER NOT NULL REFERENCES project (id),
resource_id TEXT NOT NULL,
@@ -632,10 +537,6 @@ ALTER SEQUENCE vcs_connector_id_seq RESTART WITH 101;
-- For now, anomaly can be associated with a particular instance or database.
CREATE TABLE anomaly (
id SERIAL PRIMARY KEY,
- row_status row_status NOT NULL DEFAULT 'NORMAL',
- creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
project TEXT NOT NULL,
instance_id INTEGER NOT NULL REFERENCES instance (id),
@@ -652,11 +553,6 @@ ALTER SEQUENCE anomaly_id_seq RESTART WITH 101;
-- deployment_config stores deployment configurations at project level.
CREATE TABLE deployment_config (
id SERIAL PRIMARY KEY,
- row_status row_status NOT NULL DEFAULT 'NORMAL',
- creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
project_id INTEGER NOT NULL REFERENCES project (id),
name TEXT NOT NULL,
config JSONB NOT NULL DEFAULT '{}'
@@ -701,9 +597,6 @@ CREATE INDEX idx_worksheet_organizer_principal_id ON worksheet_organizer(princip
-- external_approval stores approval instances of third party applications.
CREATE TABLE external_approval (
id SERIAL PRIMARY KEY,
- row_status row_status NOT NULL DEFAULT 'NORMAL',
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
issue_id INTEGER NOT NULL REFERENCES issue (id),
requester_id INTEGER NOT NULL REFERENCES principal (id),
approver_id INTEGER NOT NULL REFERENCES principal (id),
@@ -711,18 +604,13 @@ CREATE TABLE external_approval (
payload JSONB NOT NULL
);
-CREATE INDEX idx_external_approval_row_status_issue_id ON external_approval(row_status, issue_id);
+CREATE INDEX idx_external_approval_issue_id ON external_approval(issue_id);
ALTER SEQUENCE external_approval_id_seq RESTART WITH 101;
-- risk stores the definition of a risk.
CREATE TABLE risk (
id BIGSERIAL PRIMARY KEY,
- row_status row_status NOT NULL DEFAULT 'NORMAL',
- creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
source TEXT NOT NULL CHECK (source LIKE 'bb.risk.%'),
-- how risky is the risk, the higher the riskier
level BIGINT NOT NULL,
@@ -736,12 +624,6 @@ ALTER SEQUENCE risk_id_seq RESTART WITH 101;
-- slow_query stores slow query statistics for each database.
CREATE TABLE slow_query (
id SERIAL PRIMARY KEY,
- row_status row_status NOT NULL DEFAULT 'NORMAL',
- creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- -- updated_ts is used to identify the latest timestamp for syncing slow query logs.
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
-- In MySQL, users can query without specifying a database. In this case, instance_id is used to identify the instance.
instance_id INTEGER NOT NULL REFERENCES instance (id),
-- In MySQL, users can query without specifying a database. In this case, database_id is NULL.
@@ -761,11 +643,6 @@ ALTER SEQUENCE slow_query_id_seq RESTART WITH 101;
CREATE TABLE db_group (
id BIGSERIAL PRIMARY KEY,
- row_status row_status NOT NULL DEFAULT 'NORMAL',
- creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
project_id INTEGER NOT NULL REFERENCES project (id),
resource_id TEXT NOT NULL,
placeholder TEXT NOT NULL DEFAULT '',
@@ -782,11 +659,6 @@ ALTER SEQUENCE db_group_id_seq RESTART WITH 101;
-- changelist table stores project changelists.
CREATE TABLE changelist (
id SERIAL PRIMARY KEY,
- row_status row_status NOT NULL DEFAULT 'NORMAL',
- creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
project_id INTEGER NOT NULL REFERENCES project (id),
name TEXT NOT NULL,
payload JSONB NOT NULL DEFAULT '{}'
@@ -803,35 +675,17 @@ CREATE TABLE export_archive (
payload JSONB NOT NULL DEFAULT '{}'
);
-CREATE TABLE sql_lint_config (
- id TEXT NOT NULL PRIMARY KEY,
- creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- config JSONB NOT NULL DEFAULT '{}'
-);
-
CREATE TABLE user_group (
email TEXT PRIMARY KEY,
- creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
name TEXT NOT NULL,
description TEXT NOT NULL DEFAULT '',
payload JSONB NOT NULL DEFAULT '{}'
);
-- review config table.
-CREATE TABLE review_config
-(
+CREATE TABLE review_config (
id TEXT NOT NULL PRIMARY KEY,
row_status row_status NOT NULL DEFAULT 'NORMAL',
- creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updater_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
name TEXT NOT NULL,
payload JSONB NOT NULL DEFAULT '{}'
);
@@ -855,7 +709,6 @@ CREATE INDEX IF NOT EXISTS idx_revision_database_id_version ON revision (databas
CREATE TABLE sync_history (
id BIGSERIAL PRIMARY KEY,
- creator_id INTEGER NOT NULL REFERENCES principal (id),
created_ts TIMESTAMPTZ NOT NULL DEFAULT now(),
database_id INTEGER NOT NULL REFERENCES db (id),
metadata JSON NOT NULL DEFAULT '{}',
@@ -901,12 +754,12 @@ INSERT INTO principal (id, creator_id, updater_id, type, name, email, password_h
ALTER SEQUENCE principal_id_seq RESTART WITH 101;
-- Default project.
-INSERT INTO project (id, creator_id, updater_id, name, key, resource_id) VALUES (1, 1, 1, 'Default', 'DEFAULT', 'default');
+INSERT INTO project (id, name, key, resource_id) VALUES (1, 'Default', 'DEFAULT', 'default');
ALTER SEQUENCE project_id_seq RESTART WITH 101;
-- Create "test" and "prod" environments
-INSERT INTO environment (id, creator_id, updater_id, name, "order", resource_id) VALUES (101, 1, 1, 'Test', 0, 'test');
-INSERT INTO environment (id, creator_id, updater_id, name, "order", resource_id) VALUES (102, 1, 1, 'Prod', 1, 'prod');
+INSERT INTO environment (id, name, "order", resource_id) VALUES (101, 'Test', 0, 'test');
+INSERT INTO environment (id, name, "order", resource_id) VALUES (102, 'Prod', 1, 'prod');
ALTER SEQUENCE environment_id_seq RESTART WITH 103;
diff --git a/backend/migrator/migrator_test.go b/backend/migrator/migrator_test.go
index 77e0dbf0bd..64bcf81524 100644
--- a/backend/migrator/migrator_test.go
+++ b/backend/migrator/migrator_test.go
@@ -212,5 +212,5 @@ func TestMigrationCompatibility(t *testing.T) {
func TestGetCutoffVersion(t *testing.T) {
releaseVersion, err := getProdCutoffVersion()
require.NoError(t, err)
- require.Equal(t, semver.MustParse("3.4.1"), releaseVersion)
+ require.Equal(t, semver.MustParse("3.4.2"), releaseVersion)
}
diff --git a/backend/runner/relay/runner.go b/backend/runner/relay/runner.go
index 4aa38e60bf..3879609b75 100644
--- a/backend/runner/relay/runner.go
+++ b/backend/runner/relay/runner.go
@@ -133,20 +133,14 @@ func (r *Runner) checkExternalApproval(ctx context.Context, approval *store.Exte
if err := r.ApproveExternalApprovalNode(ctx, approval.IssueUID); err != nil {
return err
}
- if _, err := r.store.UpdateExternalApprovalV2(ctx, &store.UpdateExternalApprovalMessage{
- ID: approval.ID,
- RowStatus: api.Archived,
- }); err != nil {
+ if err := r.store.DeleteExternalApprovalV2(ctx, approval.ID); err != nil {
return err
}
} else if resp.Status == relayplugin.StatusRejected {
if err := r.RejectExternalApprovalNode(ctx, approval.IssueUID); err != nil {
return err
}
- if _, err := r.store.UpdateExternalApprovalV2(ctx, &store.UpdateExternalApprovalMessage{
- ID: approval.ID,
- RowStatus: api.Archived,
- }); err != nil {
+ if err := r.store.DeleteExternalApprovalV2(ctx, approval.ID); err != nil {
return err
}
}
@@ -178,10 +172,7 @@ func (r *Runner) cancelExternalApproval(ctx context.Context, issueUID int) {
return
}
for _, approval := range approvals {
- if _, err := r.store.UpdateExternalApprovalV2(ctx, &store.UpdateExternalApprovalMessage{
- ID: approval.ID,
- RowStatus: api.Archived,
- }); err != nil {
+ if err := r.store.DeleteExternalApprovalV2(ctx, approval.ID); err != nil {
slog.Error("failed to archive external approval", log.BBError(err))
continue
}
diff --git a/backend/runner/schemasync/syncer.go b/backend/runner/schemasync/syncer.go
index f64c781498..194da0af48 100644
--- a/backend/runner/schemasync/syncer.go
+++ b/backend/runner/schemasync/syncer.go
@@ -291,7 +291,6 @@ func (s *Syncer) SyncInstance(ctx context.Context, instance *store.InstanceMessa
updateInstance := &store.UpdateInstanceMessage{
ResourceID: instance.ResourceID,
Metadata: instanceMeta.Metadata,
- UpdaterID: api.SystemBotID,
}
if instanceMeta.Version != instance.EngineVersion {
updateInstance.EngineVersion = &instanceMeta.Version
@@ -454,7 +453,7 @@ func (s *Syncer) SyncDatabaseSchemaToHistory(ctx context.Context, database *stor
return 0, errors.Wrapf(err, "failed to upsert database schema for database %q", database.DatabaseName)
}
- id, err := s.store.CreateSyncHistory(ctx, database.UID, databaseMetadata, string(rawDump), api.SystemBotID)
+ id, err := s.store.CreateSyncHistory(ctx, database.UID, databaseMetadata, string(rawDump))
if err != nil {
if strings.Contains(err.Error(), "escape sequence") {
if metadataBytes, err := protojson.Marshal(databaseMetadata); err == nil {
@@ -601,7 +600,7 @@ func (s *Syncer) SyncDatabaseSchema(ctx context.Context, database *store.Databas
}
latestSchema := string(rawDump)
if changelog.Schema != latestSchema {
- if _, err = s.store.UpsertActiveAnomalyV2(ctx, api.SystemBotID, &store.AnomalyMessage{
+ if _, err = s.store.UpsertActiveAnomalyV2(ctx, &store.AnomalyMessage{
ProjectID: database.ProjectID,
InstanceUID: instance.UID,
DatabaseUID: database.UID,
@@ -669,7 +668,7 @@ func (s *Syncer) hasBackupSchema(ctx context.Context, instance *store.InstanceMe
func (s *Syncer) upsertDatabaseConnectionAnomaly(ctx context.Context, instance *store.InstanceMessage, database *store.DatabaseMessage, connErr error) {
if connErr != nil {
- if _, err := s.store.UpsertActiveAnomalyV2(ctx, api.SystemBotID, &store.AnomalyMessage{
+ if _, err := s.store.UpsertActiveAnomalyV2(ctx, &store.AnomalyMessage{
ProjectID: database.ProjectID,
InstanceUID: instance.UID,
DatabaseUID: database.UID,
diff --git a/backend/runner/slowquerysync/syncer.go b/backend/runner/slowquerysync/syncer.go
index 14b4f8e1f1..31113db511 100644
--- a/backend/runner/slowquerysync/syncer.go
+++ b/backend/runner/slowquerysync/syncer.go
@@ -225,7 +225,6 @@ func (s *Syncer) syncPostgreSQLSlowQuery(ctx context.Context, instance *store.In
InstanceUID: instance.UID,
LogDate: latestLogDate,
SlowLog: statistics,
- UpdaterID: api.SystemBotID,
}); err != nil {
slog.Warn("Failed to upsert slow query log",
slog.String("instance", instance.ResourceID),
@@ -324,7 +323,6 @@ func (s *Syncer) syncMySQLSlowQuery(ctx context.Context, instance *store.Instanc
InstanceUID: instance.UID,
LogDate: date,
SlowLog: slowLog,
- UpdaterID: api.SystemBotID,
}); err != nil {
return err
}
diff --git a/backend/server/init.go b/backend/server/init.go
index 46390f5f78..bb5b61b3cb 100644
--- a/backend/server/init.go
+++ b/backend/server/init.go
@@ -24,10 +24,9 @@ func (s *Server) getInitSetting(ctx context.Context) (string, error) {
// initial branding
if _, _, err := s.store.CreateSettingIfNotExistV2(ctx, &store.SettingMessage{
- Name: api.SettingBrandingLogo,
- Value: "",
- Description: "The branding slogo image in base64 string format.",
- }, api.SystemBotID); err != nil {
+ Name: api.SettingBrandingLogo,
+ Value: "",
+ }); err != nil {
return "", err
}
@@ -37,10 +36,9 @@ func (s *Server) getInitSetting(ctx context.Context) (string, error) {
return "", errors.Wrap(err, "failed to generate random JWT secret")
}
authSetting, _, err := s.store.CreateSettingIfNotExistV2(ctx, &store.SettingMessage{
- Name: api.SettingAuthSecret,
- Value: secret,
- Description: "Random string used to sign the JWT auth token.",
- }, api.SystemBotID)
+ Name: api.SettingAuthSecret,
+ Value: secret,
+ })
if err != nil {
return "", err
}
@@ -49,10 +47,9 @@ func (s *Server) getInitSetting(ctx context.Context) (string, error) {
// initial workspace
if _, _, err := s.store.CreateSettingIfNotExistV2(ctx, &store.SettingMessage{
- Name: api.SettingWorkspaceID,
- Value: uuid.New().String(),
- Description: "The workspace identifier",
- }, api.SystemBotID); err != nil {
+ Name: api.SettingWorkspaceID,
+ Value: uuid.New().String(),
+ }); err != nil {
return "", err
}
@@ -68,10 +65,9 @@ func (s *Server) getInitSetting(ctx context.Context) (string, error) {
return "", errors.Wrap(err, "failed to marshal initial scim setting")
}
if _, _, err := s.store.CreateSettingIfNotExistV2(ctx, &store.SettingMessage{
- Name: api.SettingSCIM,
- Value: string(scimSettingValue),
- Description: "The SCIM sync",
- }, api.SystemBotID); err != nil {
+ Name: api.SettingSCIM,
+ Value: string(scimSettingValue),
+ }); err != nil {
return "", err
}
@@ -88,62 +84,55 @@ func (s *Server) getInitSetting(ctx context.Context) (string, error) {
return "", errors.Wrap(err, "failed to marshal initial password validation setting")
}
if _, _, err := s.store.CreateSettingIfNotExistV2(ctx, &store.SettingMessage{
- Name: api.SettingPasswordRestriction,
- Value: string(passwordSettingValue),
- Description: "The password validation",
- }, api.SystemBotID); err != nil {
+ Name: api.SettingPasswordRestriction,
+ Value: string(passwordSettingValue),
+ }); err != nil {
return "", err
}
// initial license
if _, _, err = s.store.CreateSettingIfNotExistV2(ctx, &store.SettingMessage{
- Name: api.SettingEnterpriseLicense,
- Value: "",
- Description: "Enterprise license",
- }, api.SystemBotID); err != nil {
+ Name: api.SettingEnterpriseLicense,
+ Value: "",
+ }); err != nil {
return "", err
}
// initial IM app
if _, _, err := s.store.CreateSettingIfNotExistV2(ctx, &store.SettingMessage{
- Name: api.SettingAppIM,
- Value: "{}",
- Description: "",
- }, api.SystemBotID); err != nil {
+ Name: api.SettingAppIM,
+ Value: "{}",
+ }); err != nil {
return "", err
}
// initial watermark setting
if _, _, err := s.store.CreateSettingIfNotExistV2(ctx, &store.SettingMessage{
- Name: api.SettingWatermark,
- Value: "0",
- Description: "Display watermark",
- }, api.SystemBotID); err != nil {
+ Name: api.SettingWatermark,
+ Value: "0",
+ }); err != nil {
return "", err
}
// initial OpenAI key setting
if _, _, err := s.store.CreateSettingIfNotExistV2(ctx, &store.SettingMessage{
- Name: api.SettingPluginOpenAIKey,
- Value: "",
- Description: "API key to request OpenAI (ChatGPT)",
- }, api.SystemBotID); err != nil {
+ Name: api.SettingPluginOpenAIKey,
+ Value: "",
+ }); err != nil {
return "", err
}
if _, _, err := s.store.CreateSettingIfNotExistV2(ctx, &store.SettingMessage{
- Name: api.SettingPluginOpenAIEndpoint,
- Value: "",
- Description: "API Endpoint for OpenAI",
- }, api.SystemBotID); err != nil {
+ Name: api.SettingPluginOpenAIEndpoint,
+ Value: "",
+ }); err != nil {
return "", err
}
if _, _, err := s.store.CreateSettingIfNotExistV2(ctx, &store.SettingMessage{
- Name: api.SettingPluginOpenAIModel,
- Value: "",
- Description: "Model for OpenAI",
- }, api.SystemBotID); err != nil {
+ Name: api.SettingPluginOpenAIModel,
+ Value: "",
+ }); err != nil {
return "", err
}
@@ -153,10 +142,9 @@ func (s *Server) getInitSetting(ctx context.Context) (string, error) {
return "", errors.Wrap(err, "failed to marshal initial external approval setting")
}
if _, _, err := s.store.CreateSettingIfNotExistV2(ctx, &store.SettingMessage{
- Name: api.SettingWorkspaceExternalApproval,
- Value: string(externalApprovalSettingValue),
- Description: "The external approval setting",
- }, api.SystemBotID); err != nil {
+ Name: api.SettingWorkspaceExternalApproval,
+ Value: string(externalApprovalSettingValue),
+ }); err != nil {
return "", err
}
@@ -166,10 +154,9 @@ func (s *Server) getInitSetting(ctx context.Context) (string, error) {
return "", errors.Wrap(err, "failed to marshal initial schema template setting")
}
if _, _, err := s.store.CreateSettingIfNotExistV2(ctx, &store.SettingMessage{
- Name: api.SettingSchemaTemplate,
- Value: string(schemaTemplateSettingValue),
- Description: "The schema template setting",
- }, api.SystemBotID); err != nil {
+ Name: api.SettingSchemaTemplate,
+ Value: string(schemaTemplateSettingValue),
+ }); err != nil {
return "", err
}
@@ -179,10 +166,9 @@ func (s *Server) getInitSetting(ctx context.Context) (string, error) {
return "", errors.Wrap(err, "failed to marshal initial data classification setting")
}
if _, _, err := s.store.CreateSettingIfNotExistV2(ctx, &store.SettingMessage{
- Name: api.SettingDataClassification,
- Value: string(dataClassificationSettingValue),
- Description: "The data classification setting",
- }, api.SystemBotID); err != nil {
+ Name: api.SettingDataClassification,
+ Value: string(dataClassificationSettingValue),
+ }); err != nil {
return "", err
}
@@ -194,9 +180,8 @@ func (s *Server) getInitSetting(ctx context.Context) (string, error) {
if _, _, err := s.store.CreateSettingIfNotExistV2(ctx, &store.SettingMessage{
Name: api.SettingWorkspaceApproval,
// Value is ""
- Value: string(approvalSettingValue),
- Description: "The workspace approval setting",
- }, api.SystemBotID); err != nil {
+ Value: string(approvalSettingValue),
+ }); err != nil {
return "", err
}
@@ -227,7 +212,7 @@ func (s *Server) getInitSetting(ctx context.Context) (string, error) {
if _, err := s.store.UpsertSettingV2(ctx, &store.SetSettingMessage{
Name: api.SettingWorkspaceProfile,
Value: string(bytes),
- }, api.SystemBotID); err != nil {
+ }); err != nil {
return "", err
}
@@ -237,7 +222,6 @@ func (s *Server) getInitSetting(ctx context.Context) (string, error) {
Roles: []string{
common.FormatRole(api.WorkspaceAdmin.String()),
},
- UpdaterUID: api.SystemBotID,
}); err != nil {
return "", err
}
@@ -246,7 +230,6 @@ func (s *Server) getInitSetting(ctx context.Context) (string, error) {
Roles: []string{
common.FormatRole(api.WorkspaceMember.String()),
},
- UpdaterUID: api.SystemBotID,
}); err != nil {
return "", err
}
diff --git a/backend/server/onboard.go b/backend/server/onboard.go
index f41a1f6d26..f41f21eef9 100644
--- a/backend/server/onboard.go
+++ b/backend/server/onboard.go
@@ -55,7 +55,7 @@ func (s *Server) generateOnboardingData(ctx context.Context, user *store.UserMes
},
EnvironmentID: api.DefaultTestEnvironmentID,
Activation: false,
- }, userID, -1)
+ }, -1)
if err != nil {
return errors.Wrapf(err, "failed to create test onboarding instance")
}
@@ -114,7 +114,7 @@ func (s *Server) generateOnboardingData(ctx context.Context, user *store.UserMes
},
EnvironmentID: api.DefaultProdEnvironmentID,
Activation: false,
- }, userID, -1)
+ }, -1)
if err != nil {
return errors.Wrapf(err, "failed to create prod onboarding instance")
}
@@ -157,11 +157,10 @@ func (s *Server) generateOnboardingData(ctx context.Context, user *store.UserMes
// Add a sample SQL Review policy to the prod environment. This pairs with the following schema
// change issue to demonstrate the SQL Review feature.
sqlReviewConfig := &store.ReviewConfigMessage{
- ID: "sample",
- Name: "SQL Review Sample Policy",
- CreatorUID: userID,
- Enforce: true,
- Payload: getSampleSQLReviewPayload(),
+ ID: "sample",
+ Name: "SQL Review Sample Policy",
+ Enforce: true,
+ Payload: getSampleSQLReviewPayload(),
}
config, err := s.store.CreateReviewConfig(ctx, sqlReviewConfig)
@@ -186,7 +185,7 @@ func (s *Server) generateOnboardingData(ctx context.Context, user *store.UserMes
InheritFromParent: true,
// Enforce cannot be false while creating a policy.
Enforce: true,
- }, userID)
+ })
if err != nil {
return errors.Wrapf(err, "failed to create onboarding environment tag policy")
}
diff --git a/backend/store/anomaly.go b/backend/store/anomaly.go
index adef7978a8..027f4338c5 100644
--- a/backend/store/anomaly.go
+++ b/backend/store/anomaly.go
@@ -25,8 +25,6 @@ type AnomalyMessage struct {
//
// UID is the unique identifier of the anomaly.
UID int
- // CreatedTs is the timestamp when the anomaly is created.
- CreatedTs int64
// UpdatedTs is the timestamp when the anomaly is updated.
UpdatedTs int64
}
@@ -34,7 +32,6 @@ type AnomalyMessage struct {
// ListAnomalyMessage is the message to list anomalies.
type ListAnomalyMessage struct {
ProjectID string
- RowStatus *api.RowStatus
InstanceID *string
DatabaseUID *int
Types []api.AnomalyType
@@ -48,7 +45,7 @@ type DeleteAnomalyMessage struct {
}
// UpsertActiveAnomalyV2 upserts an instance of anomaly.
-func (s *Store) UpsertActiveAnomalyV2(ctx context.Context, principalUID int, upsert *AnomalyMessage) (*AnomalyMessage, error) {
+func (s *Store) UpsertActiveAnomalyV2(ctx context.Context, upsert *AnomalyMessage) (*AnomalyMessage, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
return nil, err
@@ -56,27 +53,20 @@ func (s *Store) UpsertActiveAnomalyV2(ctx context.Context, principalUID int, ups
defer tx.Rollback()
t := time.Now().Unix()
- upsert.CreatedTs = t
upsert.UpdatedTs = t
query := `
INSERT INTO anomaly (
- creator_id,
- updater_id,
- created_ts,
updated_ts,
project,
instance_id,
database_id,
type
)
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
+ VALUES ($1, $2, $3, $4, $5)
ON CONFLICT (project, database_id, type) DO UPDATE SET
updated_ts = EXCLUDED.updated_ts
`
if _, err := tx.ExecContext(ctx, query,
- principalUID,
- principalUID,
- t,
t,
upsert.ProjectID,
upsert.InstanceUID,
@@ -135,9 +125,6 @@ func (s *Store) DeleteAnomalyV2(ctx context.Context, d *DeleteAnomalyMessage) er
func (*Store) listAnomalyImplV2(ctx context.Context, tx *Tx, list *ListAnomalyMessage) ([]*AnomalyMessage, error) {
where, args := []string{"TRUE"}, []any{}
where, args = append(where, fmt.Sprintf("anomaly.project = $%d", len(args)+1)), append(args, list.ProjectID)
- if v := list.RowStatus; v != nil {
- where, args = append(where, fmt.Sprintf("anomaly.row_status = $%d", len(args)+1)), append(args, *v)
- }
if v := list.InstanceID; v != nil {
where, args = append(where, fmt.Sprintf("instance.resource_id = $%d", len(args)+1)), append(args, *v)
}
@@ -155,7 +142,6 @@ func (*Store) listAnomalyImplV2(ctx context.Context, tx *Tx, list *ListAnomalyMe
query := fmt.Sprintf(`
SELECT
anomaly.id,
- anomaly.created_ts,
anomaly.updated_ts,
anomaly.instance_id,
anomaly.database_id,
@@ -166,7 +152,7 @@ func (*Store) listAnomalyImplV2(ctx context.Context, tx *Tx, list *ListAnomalyMe
AND EXISTS (
SELECT 1
FROM instance
- WHERE instance.id = anomaly.instance_id AND instance.row_status != 'ARCHIVED'
+ WHERE instance.id = anomaly.instance_id
)
)
`, strings.Join(where, " AND "))
@@ -184,7 +170,6 @@ func (*Store) listAnomalyImplV2(ctx context.Context, tx *Tx, list *ListAnomalyMe
var databaseID sql.NullInt32
if err := rows.Scan(
&anomaly.UID,
- &anomaly.CreatedTs,
&anomaly.UpdatedTs,
&anomaly.InstanceUID,
&databaseID,
diff --git a/backend/store/data_source.go b/backend/store/data_source.go
index c63ae1b8f9..e5b0706d46 100644
--- a/backend/store/data_source.go
+++ b/backend/store/data_source.go
@@ -5,7 +5,6 @@ import (
"fmt"
"slices"
"strings"
- "time"
"github.com/pkg/errors"
@@ -110,7 +109,6 @@ func (m *DataSourceMessage) Copy() *DataSourceMessage {
// UpdateDataSourceMessage is the message for the data source.
type UpdateDataSourceMessage struct {
- UpdaterID int
InstanceUID int
InstanceID string
DataSourceID string
@@ -286,14 +284,14 @@ func (s *Store) GetDataSource(ctx context.Context, find *FindDataSourceMessage)
}
// AddDataSourceToInstanceV2 adds a RO data source to an instance and return the instance where the data source is added.
-func (s *Store) AddDataSourceToInstanceV2(ctx context.Context, instanceUID, creatorID int, instanceID string, dataSource *DataSourceMessage) error {
+func (s *Store) AddDataSourceToInstanceV2(ctx context.Context, instanceUID int, instanceID string, dataSource *DataSourceMessage) error {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
return errors.New("Failed to begin transaction")
}
defer tx.Rollback()
- if err := s.addDataSourceToInstanceImplV2(ctx, tx, instanceUID, creatorID, dataSource); err != nil {
+ if err := s.addDataSourceToInstanceImplV2(ctx, tx, instanceUID, dataSource); err != nil {
return err
}
@@ -340,7 +338,7 @@ func (s *Store) RemoveDataSourceV2(ctx context.Context, instanceUID int, instanc
// UpdateDataSourceV2 updates a data source and returns the instance.
func (s *Store) UpdateDataSourceV2(ctx context.Context, patch *UpdateDataSourceMessage) error {
- set, args := []string{"updater_id = $1", "updated_ts = $2"}, []any{patch.UpdaterID, time.Now().Unix()}
+ set, args := []string{}, []any{}
if v := patch.Username; v != nil {
set, args = append(set, fmt.Sprintf("username = $%d", len(args)+1)), append(args, *v)
@@ -494,7 +492,7 @@ func (s *Store) UpdateDataSourceV2(ctx context.Context, patch *UpdateDataSourceM
return nil
}
-func (*Store) addDataSourceToInstanceImplV2(ctx context.Context, tx *Tx, instanceUID, creatorID int, dataSource *DataSourceMessage) error {
+func (*Store) addDataSourceToInstanceImplV2(ctx context.Context, tx *Tx, instanceUID int, dataSource *DataSourceMessage) error {
// We flatten the data source fields in DataSourceMessage, so we need to compose them in store layer before INSERT.
dataSourceOptions := storepb.DataSourceOptions{
Srv: dataSource.SRV,
@@ -528,8 +526,6 @@ func (*Store) addDataSourceToInstanceImplV2(ctx context.Context, tx *Tx, instanc
if _, err := tx.ExecContext(ctx, `
INSERT INTO data_source (
- creator_id,
- updater_id,
instance_id,
name,
type,
@@ -543,8 +539,8 @@ func (*Store) addDataSourceToInstanceImplV2(ctx context.Context, tx *Tx, instanc
options,
database
)
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)
- `, creatorID, creatorID, instanceUID, dataSource.ID,
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)
+ `, instanceUID, dataSource.ID,
dataSource.Type, dataSource.Username, dataSource.ObfuscatedPassword, dataSource.ObfuscatedSslKey,
dataSource.ObfuscatedSslCert, dataSource.ObfuscatedSslCa, dataSource.Host, dataSource.Port,
protoBytes, dataSource.Database,
diff --git a/backend/store/database_group.go b/backend/store/database_group.go
index e74b6c3548..caeb4e5ab6 100644
--- a/backend/store/database_group.go
+++ b/backend/store/database_group.go
@@ -5,7 +5,6 @@ import (
"database/sql"
"fmt"
"strings"
- "time"
"github.com/pkg/errors"
"google.golang.org/genproto/googleapis/type/expr"
@@ -18,11 +17,7 @@ import (
// DatabaseGroupMessage is the message for database groups.
type DatabaseGroupMessage struct {
// Output only fields.
- UID int64
- CreatedTs int64
- UpdatedTs int64
- CreatorID int
- UpdaterID int
+ UID int64
// Normal fields.
ProjectUID int
@@ -153,10 +148,6 @@ func (*Store) listDatabaseGroupImpl(ctx context.Context, tx *Tx, find *FindDatab
}
fields := []string{
"id",
- "created_ts",
- "updated_ts",
- "creator_id",
- "updater_id",
"project_id",
"resource_id",
"placeholder",
@@ -175,10 +166,6 @@ func (*Store) listDatabaseGroupImpl(ctx context.Context, tx *Tx, find *FindDatab
var exprBytes, payloadBytes []byte
dest := []any{
&databaseGroup.UID,
- &databaseGroup.CreatedTs,
- &databaseGroup.UpdatedTs,
- &databaseGroup.CreatorID,
- &databaseGroup.UpdaterID,
&databaseGroup.ProjectUID,
&databaseGroup.ResourceID,
&databaseGroup.Placeholder,
@@ -207,8 +194,8 @@ func (*Store) listDatabaseGroupImpl(ctx context.Context, tx *Tx, find *FindDatab
}
// UpdateDatabaseGroup updates a database group.
-func (s *Store) UpdateDatabaseGroup(ctx context.Context, updaterPrincipalID int, databaseGroupUID int64, patch *UpdateDatabaseGroupMessage) (*DatabaseGroupMessage, error) {
- set, args := []string{"updater_id = $1", "updated_ts = $2"}, []any{updaterPrincipalID, time.Now().Unix()}
+func (s *Store) UpdateDatabaseGroup(ctx context.Context, databaseGroupUID int64, patch *UpdateDatabaseGroupMessage) (*DatabaseGroupMessage, error) {
+ set, args := []string{}, []any{}
if v := patch.Placeholder; v != nil {
set, args = append(set, fmt.Sprintf("placeholder = $%d", len(args)+1)), append(args, *v)
}
@@ -231,7 +218,7 @@ func (s *Store) UpdateDatabaseGroup(ctx context.Context, updaterPrincipalID int,
UPDATE db_group SET
%s
WHERE id = $%d
- RETURNING id, created_ts, updated_ts, creator_id, updater_id, project_id, resource_id, placeholder, expression, payload;
+ RETURNING id, project_id, resource_id, placeholder, expression, payload;
`, strings.Join(set, ", "), len(args))
tx, err := s.db.BeginTx(ctx, nil)
@@ -247,10 +234,6 @@ func (s *Store) UpdateDatabaseGroup(ctx context.Context, updaterPrincipalID int,
args...,
).Scan(
&updatedDatabaseGroup.UID,
- &updatedDatabaseGroup.CreatedTs,
- &updatedDatabaseGroup.UpdatedTs,
- &updatedDatabaseGroup.CreatorID,
- &updatedDatabaseGroup.UpdaterID,
&updatedDatabaseGroup.ProjectUID,
&updatedDatabaseGroup.ResourceID,
&updatedDatabaseGroup.Placeholder,
@@ -278,18 +261,16 @@ func (s *Store) UpdateDatabaseGroup(ctx context.Context, updaterPrincipalID int,
}
// CreateDatabaseGroup creates a database group.
-func (s *Store) CreateDatabaseGroup(ctx context.Context, creatorPrincipalID int, create *DatabaseGroupMessage) (*DatabaseGroupMessage, error) {
+func (s *Store) CreateDatabaseGroup(ctx context.Context, create *DatabaseGroupMessage) (*DatabaseGroupMessage, error) {
query := `
INSERT INTO db_group (
- creator_id,
- updater_id,
project_id,
resource_id,
placeholder,
expression,
payload
- ) VALUES ($1, $2, $3, $4, $5, $6, $7)
- RETURNING id, created_ts, updated_ts;
+ ) VALUES ($1, $2, $3, $4, $5)
+ RETURNING id;
`
exprBytes, err := protojson.Marshal(create.Expression)
if err != nil {
@@ -309,8 +290,6 @@ func (s *Store) CreateDatabaseGroup(ctx context.Context, creatorPrincipalID int,
if err := tx.QueryRowContext(
ctx,
query,
- creatorPrincipalID,
- creatorPrincipalID,
create.ProjectUID,
create.ResourceID,
create.Placeholder,
@@ -318,8 +297,6 @@ func (s *Store) CreateDatabaseGroup(ctx context.Context, creatorPrincipalID int,
payloadBytes,
).Scan(
&create.UID,
- &create.CreatedTs,
- &create.UpdatedTs,
); err != nil {
return nil, errors.Wrapf(err, "failed to scan")
}
@@ -327,8 +304,6 @@ func (s *Store) CreateDatabaseGroup(ctx context.Context, creatorPrincipalID int,
return nil, errors.Wrapf(err, "failed to commit transaction")
}
- create.CreatorID = creatorPrincipalID
- create.UpdaterID = creatorPrincipalID
s.databaseGroupCache.Add(getDatabaseGroupCacheKey(create.ProjectUID, create.ResourceID), create)
s.databaseGroupIDCache.Add(create.UID, create)
return create, nil
diff --git a/backend/store/deploy.go b/backend/store/deploy.go
index e85036d104..603e1998f4 100644
--- a/backend/store/deploy.go
+++ b/backend/store/deploy.go
@@ -5,7 +5,6 @@ import (
"database/sql"
"fmt"
"strings"
- "time"
"github.com/pkg/errors"
"google.golang.org/protobuf/encoding/protojson"
@@ -73,7 +72,7 @@ func (s *Store) GetDeploymentConfigV2(ctx context.Context, projectUID int) (*Dep
}
// UpsertDeploymentConfigV2 upserts the deployment config.
-func (s *Store) UpsertDeploymentConfigV2(ctx context.Context, projectUID, principalUID int, upsert *DeploymentConfigMessage) (*DeploymentConfigMessage, error) {
+func (s *Store) UpsertDeploymentConfigV2(ctx context.Context, projectUID int, upsert *DeploymentConfigMessage) (*DeploymentConfigMessage, error) {
configB, err := protojson.Marshal(upsert.Config)
if err != nil {
return nil, errors.Wrapf(err, "failed to marshal deployment config")
@@ -81,17 +80,12 @@ func (s *Store) UpsertDeploymentConfigV2(ctx context.Context, projectUID, princi
query := `
INSERT INTO deployment_config (
- creator_id,
- updater_id,
- updated_ts,
project_id,
name,
config
)
- VALUES ($1, $2, $3, $4, $5, $6)
+ VALUES ($1, $2, $3)
ON CONFLICT(project_id) DO UPDATE SET
- updater_id = excluded.updater_id,
- updated_ts = excluded.updated_ts,
name = excluded.name,
config = excluded.config
RETURNING id, name, config
@@ -108,9 +102,6 @@ func (s *Store) UpsertDeploymentConfigV2(ctx context.Context, projectUID, princi
defer tx.Rollback()
if err := tx.QueryRowContext(ctx, query,
- principalUID,
- principalUID,
- time.Now().Unix(),
projectUID,
upsert.Name,
configB,
diff --git a/backend/store/environment.go b/backend/store/environment.go
index 9a603009d3..a58d859355 100644
--- a/backend/store/environment.go
+++ b/backend/store/environment.go
@@ -5,7 +5,6 @@ import (
"database/sql"
"fmt"
"strings"
- "time"
"github.com/pkg/errors"
"google.golang.org/protobuf/encoding/protojson"
@@ -110,7 +109,7 @@ func (s *Store) ListEnvironmentV2(ctx context.Context, find *FindEnvironmentMess
}
// CreateEnvironmentV2 creates an environment.
-func (s *Store) CreateEnvironmentV2(ctx context.Context, create *EnvironmentMessage, creatorID int) (*EnvironmentMessage, error) {
+func (s *Store) CreateEnvironmentV2(ctx context.Context, create *EnvironmentMessage) (*EnvironmentMessage, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
return nil, err
@@ -122,18 +121,14 @@ func (s *Store) CreateEnvironmentV2(ctx context.Context, create *EnvironmentMess
INSERT INTO environment (
resource_id,
name,
- "order",
- creator_id,
- updater_id
+ "order"
)
- VALUES ($1, $2, $3, $4, $5)
+ VALUES ($1, $2, $3)
RETURNING id
`,
create.ResourceID,
create.Title,
create.Order,
- creatorID,
- creatorID,
).Scan(
&uid,
); err != nil {
@@ -158,7 +153,7 @@ func (s *Store) CreateEnvironmentV2(ctx context.Context, create *EnvironmentMess
InheritFromParent: true,
Payload: string(payload),
Enforce: true,
- }, creatorID); err != nil {
+ }); err != nil {
return nil, err
}
@@ -181,8 +176,8 @@ func (s *Store) CreateEnvironmentV2(ctx context.Context, create *EnvironmentMess
}
// UpdateEnvironmentV2 updates an environment.
-func (s *Store) UpdateEnvironmentV2(ctx context.Context, environmentID string, patch *UpdateEnvironmentMessage, updaterID int) (*EnvironmentMessage, error) {
- set, args := []string{"updater_id = $1", "updated_ts = $2"}, []any{updaterID, time.Now().Unix()}
+func (s *Store) UpdateEnvironmentV2(ctx context.Context, environmentID string, patch *UpdateEnvironmentMessage) (*EnvironmentMessage, error) {
+ set, args := []string{}, []any{}
if v := patch.Name; v != nil {
set, args = append(set, fmt.Sprintf("name = $%d", len(args)+1)), append(args, *v)
}
@@ -262,7 +257,7 @@ func (s *Store) UpdateEnvironmentV2(ctx context.Context, environmentID string, p
InheritFromParent: true,
Payload: string(payload),
Enforce: true,
- }, updaterID); err != nil {
+ }); err != nil {
return nil, err
}
}
diff --git a/backend/store/external_approval.go b/backend/store/external_approval.go
index aeaee1eb07..bff268a4d9 100644
--- a/backend/store/external_approval.go
+++ b/backend/store/external_approval.go
@@ -33,16 +33,6 @@ type ExternalApprovalMessage struct {
ID int
}
-// UpdateExternalApprovalMessage is the message for updating an external approval.
-type UpdateExternalApprovalMessage struct {
- // ID is the unique identifier of the external approval.
- ID int
- // RowStatus is the row status of the external approval.
- RowStatus api.RowStatus
- // Payload is the external approval payload.
- Payload *string
-}
-
// ListExternalApprovalMessage is the message for listing external approvals.
type ListExternalApprovalMessage struct {
// IssueUID is the unique identifier of the issue.
@@ -68,6 +58,8 @@ func (s *Store) CreateExternalApprovalV2(ctx context.Context, create *ExternalAp
if err != nil {
return nil, errors.Wrapf(err, "failed to begin transaction")
}
+ defer tx.Rollback()
+
var externalApproval ExternalApprovalMessage
if err := tx.QueryRowContext(ctx, query,
create.IssueUID,
@@ -84,6 +76,7 @@ func (s *Store) CreateExternalApprovalV2(ctx context.Context, create *ExternalAp
); err != nil {
return nil, err
}
+
if err := tx.Commit(); err != nil {
return nil, errors.Wrapf(err, "failed to commit transaction")
}
@@ -115,6 +108,7 @@ func (s *Store) GetExternalApprovalByIssueIDV2(ctx context.Context, issueID int)
if err != nil {
return nil, errors.Wrapf(err, "failed to begin transaction")
}
+ defer tx.Rollback()
externalApprovals, err := s.findExternalApprovalImplV2(ctx, tx, &ListExternalApprovalMessage{IssueUID: &issueID})
if err != nil {
@@ -133,40 +127,22 @@ func (s *Store) GetExternalApprovalByIssueIDV2(ctx context.Context, issueID int)
return externalApprovals[0], nil
}
-// UpdateExternalApprovalV2 updates an ExternalApproval.
-func (s *Store) UpdateExternalApprovalV2(ctx context.Context, update *UpdateExternalApprovalMessage) (*ExternalApprovalMessage, error) {
- set, args := []string{"row_status = $1"}, []any{update.RowStatus}
- if v := update.Payload; v != nil {
- set, args = append(set, fmt.Sprintf("payload = $%d", len(args)+1)), append(args, *v)
- }
- args = append(args, update.ID)
-
+// DeleteExternalApprovalV2 updates an ExternalApproval.
+func (s *Store) DeleteExternalApprovalV2(ctx context.Context, id int) error {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
- return nil, errors.Wrapf(err, "failed to begin transaction")
+ return errors.Wrapf(err, "failed to begin transaction")
}
+ defer tx.Rollback()
- var externalApproval ExternalApprovalMessage
- query := fmt.Sprintf(`
- UPDATE external_approval
- SET `+strings.Join(set, ", ")+`
- WHERE id = $%d
- RETURNING id, issue_id, approver_id, type, payload
- `, len(args))
- if err := tx.QueryRowContext(ctx, query, args...).Scan(
- &externalApproval.ID,
- &externalApproval.IssueUID,
- &externalApproval.ApproverUID,
- &externalApproval.Type,
- &externalApproval.Payload,
- ); err != nil {
- return nil, err
+ if _, err := tx.ExecContext(ctx, `DELETE FROM external_approval WHERE id = $1`, id); err != nil {
+ return err
}
if err := tx.Commit(); err != nil {
- return nil, errors.Wrapf(err, "failed to commit transaction")
+ return errors.Wrapf(err, "failed to commit transaction")
}
- return &externalApproval, nil
+ return nil
}
func (*Store) findExternalApprovalImplV2(ctx context.Context, tx *Tx, find *ListExternalApprovalMessage) ([]*ExternalApprovalMessage, error) {
diff --git a/backend/store/group.go b/backend/store/group.go
index 1adfd60c9f..82bc4b7e0d 100644
--- a/backend/store/group.go
+++ b/backend/store/group.go
@@ -4,7 +4,6 @@ import (
"context"
"fmt"
"strings"
- "time"
"google.golang.org/protobuf/encoding/protojson"
@@ -31,9 +30,7 @@ type GroupMessage struct {
Email string
Title string
Description string
- CreatorUID int
Payload *storepb.GroupPayload
- CreatedTime time.Time
}
// GetGroup gets a group.
@@ -98,14 +95,12 @@ func (*Store) listGroupImpl(ctx context.Context, tx *Tx, find *FindGroupMessage)
rows, err := tx.QueryContext(ctx, fmt.Sprintf(`
SELECT
email,
- created_ts,
- creator_id,
name,
description,
payload
FROM user_group
WHERE %s
- ORDER BY created_ts DESC
+ ORDER BY email
`, strings.Join(where, " AND ")), args...)
if err != nil {
return nil, err
@@ -115,18 +110,14 @@ func (*Store) listGroupImpl(ctx context.Context, tx *Tx, find *FindGroupMessage)
for rows.Next() {
var group GroupMessage
var payload []byte
- var createdTs int64
if err := rows.Scan(
&group.Email,
- &createdTs,
- &group.CreatorUID,
&group.Title,
&group.Description,
&payload,
); err != nil {
return nil, err
}
- group.CreatedTime = time.Unix(createdTs, 0)
groupPayload := storepb.GroupPayload{}
if err := common.ProtojsonUnmarshaler.Unmarshal(payload, &groupPayload); err != nil {
return nil, err
@@ -142,22 +133,18 @@ func (*Store) listGroupImpl(ctx context.Context, tx *Tx, find *FindGroupMessage)
}
// CreateGroup creates a group.
-func (s *Store) CreateGroup(ctx context.Context, create *GroupMessage, creatorUID int) (*GroupMessage, error) {
+func (s *Store) CreateGroup(ctx context.Context, create *GroupMessage) (*GroupMessage, error) {
if create.Payload == nil {
create.Payload = &storepb.GroupPayload{}
}
- create.CreatorUID = creatorUID
query := `
INSERT INTO user_group (
email,
- creator_id,
- updater_id,
name,
description,
payload
- ) VALUES ($1, $2, $3, $4, $5, $6)
- RETURNING created_ts
+ ) VALUES ($1, $2, $3, $4)
`
payloadBytes, err := protojson.Marshal(create.Payload)
if err != nil {
@@ -170,20 +157,16 @@ func (s *Store) CreateGroup(ctx context.Context, create *GroupMessage, creatorUI
}
defer tx.Rollback()
- var createdTs int64
- if err := tx.QueryRowContext(
+ if _, err := tx.ExecContext(
ctx,
query,
create.Email,
- create.CreatorUID,
- create.CreatorUID,
create.Title,
create.Description,
payloadBytes,
- ).Scan(&createdTs); err != nil {
+ ); err != nil {
return nil, err
}
- create.CreatedTime = time.Unix(createdTs, 0)
if err := tx.Commit(); err != nil {
return nil, errors.Wrap(err, "failed to commit")
@@ -194,13 +177,13 @@ func (s *Store) CreateGroup(ctx context.Context, create *GroupMessage, creatorUI
}
// UpdateGroup updates a group.
-func (s *Store) UpdateGroup(ctx context.Context, email string, patch *UpdateGroupMessage, updaterID int) (*GroupMessage, error) {
+func (s *Store) UpdateGroup(ctx context.Context, email string, patch *UpdateGroupMessage) (*GroupMessage, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
return nil, errors.Wrapf(err, "failed to begin transaction")
}
- set, args := []string{"updater_id = $1", "updated_ts = $2"}, []any{updaterID, time.Now().Unix()}
+ set, args := []string{}, []any{}
if v := patch.Title; v != nil {
set, args = append(set, fmt.Sprintf("name = $%d", len(args)+1)), append(args, *v)
@@ -219,7 +202,6 @@ func (s *Store) UpdateGroup(ctx context.Context, email string, patch *UpdateGrou
var group GroupMessage
var payload []byte
- var createdTs int64
if err := tx.QueryRowContext(ctx, fmt.Sprintf(`
UPDATE user_group
@@ -227,15 +209,11 @@ func (s *Store) UpdateGroup(ctx context.Context, email string, patch *UpdateGrou
WHERE email = $%d
RETURNING
email,
- created_ts,
- creator_id,
name,
description,
payload
`, strings.Join(set, ", "), len(set)+1), args...).Scan(
&group.Email,
- &createdTs,
- &group.CreatorUID,
&group.Title,
&group.Description,
&payload,
@@ -243,7 +221,6 @@ func (s *Store) UpdateGroup(ctx context.Context, email string, patch *UpdateGrou
return nil, err
}
- group.CreatedTime = time.Unix(createdTs, 0)
groupPayload := storepb.GroupPayload{}
if err := common.ProtojsonUnmarshaler.Unmarshal(payload, &groupPayload); err != nil {
return nil, err
diff --git a/backend/store/idp.go b/backend/store/idp.go
index e3f9d7b1eb..25454b0a76 100644
--- a/backend/store/idp.go
+++ b/backend/store/idp.go
@@ -5,7 +5,6 @@ import (
"database/sql"
"fmt"
"strings"
- "time"
"github.com/pkg/errors"
"google.golang.org/protobuf/encoding/protojson"
@@ -189,7 +188,7 @@ func (s *Store) UpdateIdentityProvider(ctx context.Context, patch *UpdateIdentit
}
func (*Store) updateIdentityProviderImpl(ctx context.Context, tx *Tx, patch *UpdateIdentityProviderMessage) (*IdentityProviderMessage, error) {
- set, args := []string{"updated_ts = $1"}, []any{time.Now().Unix()}
+ set, args := []string{}, []any{}
if v := patch.Title; v != nil {
set, args = append(set, fmt.Sprintf("name = $%d", len(args)+1)), append(args, *v)
}
diff --git a/backend/store/instance.go b/backend/store/instance.go
index 8f77a19909..d97a7cfb9a 100644
--- a/backend/store/instance.go
+++ b/backend/store/instance.go
@@ -5,7 +5,6 @@ import (
"database/sql"
"fmt"
"strings"
- "time"
"github.com/pkg/errors"
"google.golang.org/grpc/codes"
@@ -50,7 +49,6 @@ type UpdateInstanceMessage struct {
EnvironmentID string
// Output only.
- UpdaterID int
ResourceID string
}
@@ -128,7 +126,7 @@ func (s *Store) ListInstancesV2(ctx context.Context, find *FindInstanceMessage)
}
// CreateInstanceV2 creates the instance.
-func (s *Store) CreateInstanceV2(ctx context.Context, instanceCreate *InstanceMessage, creatorID, maximumActivation int) (*InstanceMessage, error) {
+func (s *Store) CreateInstanceV2(ctx context.Context, instanceCreate *InstanceMessage, maximumActivation int) (*InstanceMessage, error) {
if err := validateDataSourceList(instanceCreate.DataSources); err != nil {
return nil, err
}
@@ -162,8 +160,6 @@ func (s *Store) CreateInstanceV2(ctx context.Context, instanceCreate *InstanceMe
if err := tx.QueryRowContext(ctx, fmt.Sprintf(`
INSERT INTO instance (
resource_id,
- creator_id,
- updater_id,
environment,
name,
engine,
@@ -172,13 +168,11 @@ func (s *Store) CreateInstanceV2(ctx context.Context, instanceCreate *InstanceMe
options,
metadata
)
- SELECT $1, $2, $3, $4, $5, $6, $7, $8, $9, $10
+ SELECT $1, $2, $3, $4, $5, $6, $7, $8
%s
RETURNING id
`, where),
instanceCreate.ResourceID,
- creatorID,
- creatorID,
environment,
instanceCreate.Title,
instanceCreate.Engine.String(),
@@ -191,7 +185,7 @@ func (s *Store) CreateInstanceV2(ctx context.Context, instanceCreate *InstanceMe
}
for _, ds := range instanceCreate.DataSources {
- if err := s.addDataSourceToInstanceImplV2(ctx, tx, instanceID, creatorID, ds); err != nil {
+ if err := s.addDataSourceToInstanceImplV2(ctx, tx, instanceID, ds); err != nil {
return nil, err
}
}
@@ -232,7 +226,7 @@ func (s *Store) UpdateInstanceV2(ctx context.Context, patch *UpdateInstanceMessa
}
}
- set, args, where := []string{"updater_id = $1", "updated_ts = $2"}, []any{patch.UpdaterID, time.Now().Unix()}, []string{}
+ set, args, where := []string{}, []any{}, []string{}
if v := patch.Title; v != nil {
set, args = append(set, fmt.Sprintf("name = $%d", len(args)+1)), append(args, *v)
}
@@ -341,7 +335,7 @@ func (s *Store) UpdateInstanceV2(ctx context.Context, patch *UpdateInstanceMessa
}
for _, ds := range *patch.DataSources {
- if err := s.addDataSourceToInstanceImplV2(ctx, tx, instance.UID, patch.UpdaterID, ds); err != nil {
+ if err := s.addDataSourceToInstanceImplV2(ctx, tx, instance.UID, ds); err != nil {
return nil, err
}
}
diff --git a/backend/store/issue_comment.go b/backend/store/issue_comment.go
index 4b8e93370b..1992268936 100644
--- a/backend/store/issue_comment.go
+++ b/backend/store/issue_comment.go
@@ -22,7 +22,6 @@ type IssueCommentMessage struct {
Creator *UserMessage
creatorUID int
- updaterUID int
}
type FindIssueCommentMessage struct {
@@ -34,8 +33,7 @@ type FindIssueCommentMessage struct {
}
type UpdateIssueCommentMessage struct {
- UID int
- UpdaterID int
+ UID int
Comment *string
}
@@ -79,7 +77,6 @@ func (s *Store) ListIssueComment(ctx context.Context, find *FindIssueCommentMess
id,
creator_id,
created_ts,
- updater_id,
updated_ts,
issue_id,
payload
@@ -104,7 +101,6 @@ func (s *Store) ListIssueComment(ctx context.Context, find *FindIssueCommentMess
&ic.UID,
&ic.creatorUID,
&ic.CreatedTs,
- &ic.updaterUID,
&ic.UpdatedTs,
&ic.IssueUID,
&p,
@@ -154,14 +150,12 @@ func (s *Store) CreateIssueComment(ctx context.Context, create *IssueCommentMess
query := `
INSERT INTO issue_comment (
creator_id,
- updater_id,
issue_id,
payload
) VALUES (
$1,
$2,
- $3,
- $4
+ $3
) RETURNING id, created_ts, updated_ts
`
@@ -172,7 +166,7 @@ func (s *Store) CreateIssueComment(ctx context.Context, create *IssueCommentMess
var id int
var createdTs, updatedTs int64
- if err := s.db.db.QueryRowContext(ctx, query, creatorUID, creatorUID, create.IssueUID, payload).Scan(&id, &createdTs, &updatedTs); err != nil {
+ if err := s.db.db.QueryRowContext(ctx, query, creatorUID, create.IssueUID, payload).Scan(&id, &createdTs, &updatedTs); err != nil {
return nil, errors.Wrapf(err, "failed to insert")
}
@@ -183,7 +177,6 @@ func (s *Store) CreateIssueComment(ctx context.Context, create *IssueCommentMess
IssueUID: create.IssueUID,
Payload: create.Payload,
creatorUID: creatorUID,
- updaterUID: creatorUID,
}
creator, err := s.GetUserByID(ctx, ic.creatorUID)
@@ -196,7 +189,7 @@ func (s *Store) CreateIssueComment(ctx context.Context, create *IssueCommentMess
}
func (s *Store) UpdateIssueComment(ctx context.Context, patch *UpdateIssueCommentMessage) error {
- set, args := []string{"updater_id = $1", "updated_ts = $2"}, []any{patch.UpdaterID, time.Now().Unix()}
+ set, args := []string{"updated_ts = $2"}, []any{time.Now().Unix()}
if v := patch.Comment; v != nil {
set, args = append(set, fmt.Sprintf("payload = payload || jsonb_build_object('comment',$%d::TEXT)", len(args)+1)), append(args, *v)
diff --git a/backend/store/policy.go b/backend/store/policy.go
index 9ac014f2eb..69a2a0a751 100644
--- a/backend/store/policy.go
+++ b/backend/store/policy.go
@@ -36,9 +36,8 @@ func (s *Store) GetWorkspaceIamPolicy(ctx context.Context) (*IamPolicyMessage, e
}
type PatchIamPolicyMessage struct {
- Member string
- Roles []string
- UpdaterUID int
+ Member string
+ Roles []string
}
// PatchWorkspaceIamPolicy will set or remove the member for the workspace role.
@@ -89,7 +88,7 @@ func (s *Store) PatchWorkspaceIamPolicy(ctx context.Context, patch *PatchIamPoli
InheritFromParent: false,
// Enforce cannot be false while creating a policy.
Enforce: true,
- }, patch.UpdaterUID); err != nil {
+ }); err != nil {
return nil, err
}
@@ -349,7 +348,6 @@ type FindPolicyMessage struct {
// UpdatePolicyMessage is the message for updating a policy.
type UpdatePolicyMessage struct {
- UpdaterID int
ResourceType api.PolicyResourceType
ResourceUID int
Type api.PolicyType
@@ -424,14 +422,14 @@ func (s *Store) ListPoliciesV2(ctx context.Context, find *FindPolicyMessage) ([]
}
// CreatePolicyV2 creates a policy.
-func (s *Store) CreatePolicyV2(ctx context.Context, create *PolicyMessage, creatorID int) (*PolicyMessage, error) {
+func (s *Store) CreatePolicyV2(ctx context.Context, create *PolicyMessage) (*PolicyMessage, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
return nil, err
}
defer tx.Rollback()
- policy, err := upsertPolicyV2Impl(ctx, tx, create, creatorID)
+ policy, err := upsertPolicyV2Impl(ctx, tx, create)
if err != nil {
return nil, err
}
@@ -447,7 +445,7 @@ func (s *Store) CreatePolicyV2(ctx context.Context, create *PolicyMessage, creat
// UpdatePolicyV2 updates the policy.
func (s *Store) UpdatePolicyV2(ctx context.Context, patch *UpdatePolicyMessage) (*PolicyMessage, error) {
- set, args := []string{"updater_id = $1", "updated_ts = $2"}, []any{patch.UpdaterID, time.Now().Unix()}
+ set, args := []string{"updated_ts = $1"}, []any{time.Now()}
if v := patch.InheritFromParent; v != nil {
set, args = append(set, fmt.Sprintf("inherit_from_parent = $%d", len(args)+1)), append(args, *v)
}
@@ -475,7 +473,6 @@ func (s *Store) UpdatePolicyV2(ctx context.Context, patch *UpdatePolicyMessage)
Type: patch.Type,
}
var rowStatus string
- var updatedTs int64
if err := tx.QueryRowContext(ctx, fmt.Sprintf(`
UPDATE policy
@@ -492,7 +489,7 @@ func (s *Store) UpdatePolicyV2(ctx context.Context, patch *UpdatePolicyMessage)
&policy.Payload,
&policy.InheritFromParent,
&rowStatus,
- &updatedTs,
+ &policy.UpdatedTime,
); err != nil {
if err == sql.ErrNoRows {
return nil, nil
@@ -502,7 +499,6 @@ func (s *Store) UpdatePolicyV2(ctx context.Context, patch *UpdatePolicyMessage)
if rowStatus == string(api.Normal) {
policy.Enforce = true
}
- policy.UpdatedTime = time.Unix(updatedTs, 0)
if err := tx.Commit(); err != nil {
return nil, err
@@ -538,9 +534,8 @@ func (s *Store) DeletePolicyV2(ctx context.Context, policy *PolicyMessage) error
return nil
}
-func upsertPolicyV2Impl(ctx context.Context, tx *Tx, create *PolicyMessage, creatorID int) (*PolicyMessage, error) {
+func upsertPolicyV2Impl(ctx context.Context, tx *Tx, create *PolicyMessage) (*PolicyMessage, error) {
var uid int
- var updatedTs int64
rowStatus := api.Normal
if !create.Enforce {
@@ -548,8 +543,6 @@ func upsertPolicyV2Impl(ctx context.Context, tx *Tx, create *PolicyMessage, crea
}
if err := tx.QueryRowContext(ctx, `
INSERT INTO policy (
- creator_id,
- updater_id,
resource_type,
resource_id,
inherit_from_parent,
@@ -557,19 +550,15 @@ func upsertPolicyV2Impl(ctx context.Context, tx *Tx, create *PolicyMessage, crea
payload,
row_status
)
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
+ VALUES ($1, $2, $3, $4, $5, $6)
ON CONFLICT(resource_type, resource_id, type) DO UPDATE SET
inherit_from_parent = EXCLUDED.inherit_from_parent,
payload = EXCLUDED.payload,
- updated_ts = extract(epoch from now()),
- row_status = EXCLUDED.row_status,
- updater_id = EXCLUDED.updater_id
+ row_status = EXCLUDED.row_status
RETURNING
id,
updated_ts
`,
- creatorID,
- creatorID,
create.ResourceType,
create.ResourceUID,
create.InheritFromParent,
@@ -578,12 +567,11 @@ func upsertPolicyV2Impl(ctx context.Context, tx *Tx, create *PolicyMessage, crea
rowStatus,
).Scan(
&uid,
- &updatedTs,
+ &create.UpdatedTime,
); err != nil {
return nil, err
}
create.UID = uid
- create.UpdatedTime = time.Unix(updatedTs, 0)
return create, nil
}
@@ -625,11 +613,10 @@ func (*Store) listPolicyImplV2(ctx context.Context, tx *Tx, find *FindPolicyMess
for rows.Next() {
var policyMessage PolicyMessage
var rowStatus api.RowStatus
- var updatedTs int64
if err := rows.Scan(
&policyMessage.UID,
- &updatedTs,
+ &policyMessage.UpdatedTime,
&policyMessage.ResourceType,
&policyMessage.ResourceUID,
&policyMessage.InheritFromParent,
@@ -642,7 +629,6 @@ func (*Store) listPolicyImplV2(ctx context.Context, tx *Tx, find *FindPolicyMess
if rowStatus == api.Normal {
policyMessage.Enforce = true
}
- policyMessage.UpdatedTime = time.Unix(updatedTs, 0)
policyList = append(policyList, &policyMessage)
}
if err := rows.Err(); err != nil {
diff --git a/backend/store/project.go b/backend/store/project.go
index 017c4bbcd8..5157a2ccbf 100644
--- a/backend/store/project.go
+++ b/backend/store/project.go
@@ -5,7 +5,6 @@ import (
"database/sql"
"fmt"
"strings"
- "time"
"github.com/pkg/errors"
"google.golang.org/genproto/googleapis/type/expr"
@@ -45,7 +44,6 @@ type FindProjectMessage struct {
// UpdateProjectMessage is the message for updating a project.
type UpdateProjectMessage struct {
- UpdaterID int
ResourceID string
Title *string
@@ -149,19 +147,15 @@ func (s *Store) CreateProjectV2(ctx context.Context, create *ProjectMessage, cre
}
if err := tx.QueryRowContext(ctx, `
INSERT INTO project (
- creator_id,
- updater_id,
resource_id,
name,
key,
data_classification_config_id,
setting
)
- VALUES ($1, $2, $3, $4, $5, $6, $7)
+ VALUES ($1, $2, $3, $4, $5)
RETURNING id
`,
- creatorID,
- creatorID,
create.ResourceID,
create.Title,
create.Key,
@@ -199,7 +193,7 @@ func (s *Store) CreateProjectV2(ctx context.Context, create *ProjectMessage, cre
InheritFromParent: false,
// Enforce cannot be false while creating a policy.
Enforce: true,
- }, creatorID); err != nil {
+ }); err != nil {
return nil, err
}
@@ -233,7 +227,7 @@ func (s *Store) UpdateProjectV2(ctx context.Context, patch *UpdateProjectMessage
}
func updateProjectImplV2(ctx context.Context, tx *Tx, patch *UpdateProjectMessage) error {
- set, args := []string{"updater_id = $1", "updated_ts = $2"}, []any{patch.UpdaterID, time.Now().Unix()}
+ set, args := []string{}, []any{}
if v := patch.Title; v != nil {
set, args = append(set, fmt.Sprintf("name = $%d", len(args)+1)), append(args, *v)
}
diff --git a/backend/store/project_webhook.go b/backend/store/project_webhook.go
index 807996106c..fd75d3a314 100644
--- a/backend/store/project_webhook.go
+++ b/backend/store/project_webhook.go
@@ -5,7 +5,6 @@ import (
"database/sql"
"fmt"
"strings"
- "time"
"github.com/jackc/pgtype"
"github.com/pkg/errors"
@@ -55,11 +54,9 @@ type FindProjectWebhookMessage struct {
}
// CreateProjectWebhookV2 creates an instance of ProjectWebhook.
-func (s *Store) CreateProjectWebhookV2(ctx context.Context, principalUID int, projectUID int, projectResourceID string, create *ProjectWebhookMessage) (*ProjectWebhookMessage, error) {
+func (s *Store) CreateProjectWebhookV2(ctx context.Context, projectUID int, projectResourceID string, create *ProjectWebhookMessage) (*ProjectWebhookMessage, error) {
query := `
INSERT INTO project_webhook (
- creator_id,
- updater_id,
project_id,
type,
name,
@@ -67,7 +64,7 @@ func (s *Store) CreateProjectWebhookV2(ctx context.Context, principalUID int, pr
activity_list,
payload
)
- VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
+ VALUES ($1, $2, $3, $4, $5, $6)
RETURNING id
`
payload := []byte("{}")
@@ -94,8 +91,6 @@ func (s *Store) CreateProjectWebhookV2(ctx context.Context, principalUID int, pr
}
if err := tx.QueryRowContext(ctx, query,
- principalUID,
- principalUID,
projectUID,
create.Type,
create.Title,
@@ -163,12 +158,12 @@ func (s *Store) GetProjectWebhookV2(ctx context.Context, find *FindProjectWebhoo
}
// UpdateProjectWebhookV2 updates an instance of ProjectWebhook.
-func (s *Store) UpdateProjectWebhookV2(ctx context.Context, principalUID int, projectResourceID string, projectWebhookID int, update *UpdateProjectWebhookMessage) (*ProjectWebhookMessage, error) {
+func (s *Store) UpdateProjectWebhookV2(ctx context.Context, projectResourceID string, projectWebhookID int, update *UpdateProjectWebhookMessage) (*ProjectWebhookMessage, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
return nil, errors.Wrapf(err, "failed to begin transaction")
}
- set, args := []string{"updater_id = $1", "updated_ts = $2"}, []any{principalUID, time.Now().Unix()}
+ set, args := []string{}, []any{}
if v := update.Title; v != nil {
set, args = append(set, fmt.Sprintf("name = $%d", len(args)+1)), append(args, *v)
}
diff --git a/backend/store/review_config.go b/backend/store/review_config.go
index af573a2c2a..a7cec7bbf9 100644
--- a/backend/store/review_config.go
+++ b/backend/store/review_config.go
@@ -5,7 +5,6 @@ import (
"database/sql"
"fmt"
"strings"
- "time"
"github.com/pkg/errors"
"google.golang.org/protobuf/encoding/protojson"
@@ -17,16 +16,10 @@ import (
// ReviewConfigMessage is the API message for sql review.
type ReviewConfigMessage struct {
- ID string
- CreatorUID int
- UpdaterUID int
- Enforce bool
- Name string
- Payload *storepb.ReviewConfigPayload
-
- // Output only fields
- CreatedTime time.Time
- UpdatedTime time.Time
+ ID string
+ Enforce bool
+ Name string
+ Payload *storepb.ReviewConfigPayload
}
// FindReviewConfigMessage is the API message for finding sql review.
@@ -36,11 +29,10 @@ type FindReviewConfigMessage struct {
// PatchReviewConfigMessage is the message to patch a sql review.
type PatchReviewConfigMessage struct {
- ID string
- UpdaterID int
- Name *string
- Enforce *bool
- Payload *storepb.ReviewConfigPayload
+ ID string
+ Name *string
+ Enforce *bool
+ Payload *storepb.ReviewConfigPayload
}
// GetReviewConfig gets sql review by id.
@@ -77,10 +69,6 @@ func (s *Store) ListReviewConfigs(ctx context.Context, find *FindReviewConfigMes
SELECT
id,
row_status,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
name,
payload
FROM review_config
@@ -95,18 +83,12 @@ func (s *Store) ListReviewConfigs(ctx context.Context, find *FindReviewConfigMes
var sqlReviewList []*ReviewConfigMessage
for rows.Next() {
var sqlReview ReviewConfigMessage
- var createdTs int64
- var updatedTs int64
var payload []byte
var rowStatus string
if err := rows.Scan(
&sqlReview.ID,
&rowStatus,
- &sqlReview.CreatorUID,
- &createdTs,
- &sqlReview.UpdaterUID,
- &updatedTs,
&sqlReview.Name,
&payload,
); err != nil {
@@ -120,8 +102,6 @@ func (s *Store) ListReviewConfigs(ctx context.Context, find *FindReviewConfigMes
sqlReview.Enforce = rowStatus == string(api.Normal)
sqlReview.Payload = reviewConfigPyload
- sqlReview.CreatedTime = time.Unix(createdTs, 0)
- sqlReview.UpdatedTime = time.Unix(updatedTs, 0)
sqlReviewList = append(sqlReviewList, &sqlReview)
}
if err := rows.Err(); err != nil {
@@ -147,13 +127,10 @@ func (s *Store) CreateReviewConfig(ctx context.Context, create *ReviewConfigMess
query := `
INSERT INTO review_config (
id,
- creator_id,
- updater_id,
name,
payload
)
- VALUES ($1, $2, $3, $4, $5)
- RETURNING created_ts, updated_ts
+ VALUES ($1, $2, $3)
`
tx, err := s.db.BeginTx(ctx, nil)
@@ -161,19 +138,11 @@ func (s *Store) CreateReviewConfig(ctx context.Context, create *ReviewConfigMess
return nil, err
}
defer tx.Rollback()
- create.UpdaterUID = create.CreatorUID
- var createdTs int64
- var updatedTs int64
- if err := tx.QueryRowContext(ctx, query,
+ if _, err := tx.ExecContext(ctx, query,
create.ID,
- create.CreatorUID,
- create.CreatorUID,
create.Name,
payload,
- ).Scan(
- &createdTs,
- &updatedTs,
); err != nil {
if err == sql.ErrNoRows {
return nil, common.FormatDBErrorEmptyRowWithQuery(query)
@@ -185,8 +154,6 @@ func (s *Store) CreateReviewConfig(ctx context.Context, create *ReviewConfigMess
}
create.Enforce = true
- create.CreatedTime = time.Unix(createdTs, 0)
- create.UpdatedTime = time.Unix(updatedTs, 0)
return create, nil
}
@@ -208,7 +175,7 @@ func (s *Store) DeleteReviewConfig(ctx context.Context, id string) error {
// UpdateReviewConfig updates the sql review.
func (s *Store) UpdateReviewConfig(ctx context.Context, patch *PatchReviewConfigMessage) (*ReviewConfigMessage, error) {
- set, args := []string{"updater_id = $1", "updated_ts = $2"}, []any{patch.UpdaterID, time.Now().Unix()}
+ set, args := []string{}, []any{}
if v := patch.Enforce; v != nil {
rowStatus := api.Normal
if !*patch.Enforce {
@@ -241,27 +208,17 @@ func (s *Store) UpdateReviewConfig(ctx context.Context, patch *PatchReviewConfig
RETURNING
id,
row_status,
- creator_id,
- created_ts,
- updater_id,
- updated_ts,
name,
payload
`, len(args))
var sqlReview ReviewConfigMessage
- var createdTs int64
- var updatedTs int64
var payload []byte
var rowStatus string
if err := tx.QueryRowContext(ctx, query, args...).Scan(
&sqlReview.ID,
&rowStatus,
- &sqlReview.CreatorUID,
- &createdTs,
- &sqlReview.UpdaterUID,
- &updatedTs,
&sqlReview.Name,
&payload,
); err != nil {
@@ -278,8 +235,6 @@ func (s *Store) UpdateReviewConfig(ctx context.Context, patch *PatchReviewConfig
sqlReview.Enforce = rowStatus == string(api.Normal)
sqlReview.Payload = reviewConfigPyload
- sqlReview.CreatedTime = time.Unix(createdTs, 0)
- sqlReview.UpdatedTime = time.Unix(updatedTs, 0)
if err := tx.Commit(); err != nil {
return nil, err
diff --git a/backend/store/risk.go b/backend/store/risk.go
index cfed2766b9..42bab241ca 100644
--- a/backend/store/risk.go
+++ b/backend/store/risk.go
@@ -5,14 +5,12 @@ import (
"database/sql"
"fmt"
"strings"
- "time"
"github.com/pkg/errors"
"google.golang.org/genproto/googleapis/type/expr"
"google.golang.org/protobuf/encoding/protojson"
"github.com/bytebase/bytebase/backend/common"
- api "github.com/bytebase/bytebase/backend/legacyapi"
)
// RiskSource is the source of the risk.
@@ -44,8 +42,7 @@ type RiskMessage struct {
Expression *expr.Expr // *v1alpha1.ParsedExpr
// Output only
- ID int64
- Deleted bool
+ ID int64
}
// UpdateRiskMessage is the message for updating a risk.
@@ -54,7 +51,6 @@ type UpdateRiskMessage struct {
Active *bool
Level *int32
Expression *expr.Expr
- RowStatus *api.RowStatus
}
// GetRisk gets a risk.
@@ -66,8 +62,7 @@ func (s *Store) GetRisk(ctx context.Context, id int64) (*RiskMessage, error) {
level,
name,
active,
- expression,
- row_status
+ expression
FROM risk
WHERE id = $1`
@@ -79,7 +74,6 @@ func (s *Store) GetRisk(ctx context.Context, id int64) (*RiskMessage, error) {
var risk RiskMessage
var expressionBytes []byte
- var rowStatus api.RowStatus
if err := tx.QueryRowContext(ctx, query, id).Scan(
&risk.ID,
&risk.Source,
@@ -87,7 +81,6 @@ func (s *Store) GetRisk(ctx context.Context, id int64) (*RiskMessage, error) {
&risk.Name,
&risk.Active,
&expressionBytes,
- &rowStatus,
); err != nil {
if err == sql.ErrNoRows {
return nil, nil
@@ -95,8 +88,6 @@ func (s *Store) GetRisk(ctx context.Context, id int64) (*RiskMessage, error) {
return nil, errors.Wrap(err, "failed to scan")
}
- risk.Deleted = convertRowStatusToDeleted(string(rowStatus))
-
var expression expr.Expr // v1alpha1.ParsedExpr
if err := common.ProtojsonUnmarshaler.Unmarshal(expressionBytes, &expression); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal")
@@ -126,7 +117,6 @@ func (s *Store) ListRisks(ctx context.Context) ([]*RiskMessage, error) {
active,
expression
FROM risk
- WHERE row_status = 'NORMAL'
ORDER BY source, level DESC, id
`
@@ -178,17 +168,15 @@ func (s *Store) ListRisks(ctx context.Context) ([]*RiskMessage, error) {
}
// CreateRisk creates a risk.
-func (s *Store) CreateRisk(ctx context.Context, risk *RiskMessage, creatorID int) (*RiskMessage, error) {
+func (s *Store) CreateRisk(ctx context.Context, risk *RiskMessage) (*RiskMessage, error) {
query := `
INSERT INTO risk (
- creator_id,
- updater_id,
source,
level,
name,
active,
expression
- ) VALUES ($1, $2, $3, $4, $5, $6, $7)
+ ) VALUES ($1, $2, $3, $4, $5)
RETURNING id
`
expressionBytes, err := protojson.Marshal(risk.Expression)
@@ -203,7 +191,7 @@ func (s *Store) CreateRisk(ctx context.Context, risk *RiskMessage, creatorID int
defer tx.Rollback()
var id int64
- if err := tx.QueryRowContext(ctx, query, creatorID, creatorID, risk.Source, risk.Level, risk.Name, risk.Active, string(expressionBytes)).Scan(&id); err != nil {
+ if err := tx.QueryRowContext(ctx, query, risk.Source, risk.Level, risk.Name, risk.Active, string(expressionBytes)).Scan(&id); err != nil {
return nil, err
}
@@ -223,8 +211,8 @@ func (s *Store) CreateRisk(ctx context.Context, risk *RiskMessage, creatorID int
}
// UpdateRisk updates a risk.
-func (s *Store) UpdateRisk(ctx context.Context, patch *UpdateRiskMessage, id int64, updaterID int) (*RiskMessage, error) {
- set, args := []string{"updater_id = $1", "updated_ts = $2"}, []any{updaterID, time.Now().Unix()}
+func (s *Store) UpdateRisk(ctx context.Context, patch *UpdateRiskMessage, id int64) (*RiskMessage, error) {
+ set, args := []string{}, []any{}
if v := patch.Name; v != nil {
set, args = append(set, fmt.Sprintf("name = $%d", len(args)+1)), append(args, *v)
}
@@ -241,9 +229,6 @@ func (s *Store) UpdateRisk(ctx context.Context, patch *UpdateRiskMessage, id int
}
set, args = append(set, fmt.Sprintf("expression = $%d", len(args)+1)), append(args, string(expressionBytes))
}
- if v := patch.RowStatus; v != nil {
- set, args = append(set, fmt.Sprintf("row_status = $%d", len(args)+1)), append(args, *v)
- }
args = append(args, id)
tx, err := s.db.BeginTx(ctx, nil)
@@ -268,3 +253,22 @@ func (s *Store) UpdateRisk(ctx context.Context, patch *UpdateRiskMessage, id int
s.risksCache.Remove(0)
return s.GetRisk(ctx, id)
}
+
+func (s *Store) DeleteRisk(ctx context.Context, id int64) error {
+ tx, err := s.db.BeginTx(ctx, nil)
+ if err != nil {
+ return errors.Wrap(err, "failed to begin tx")
+ }
+ defer tx.Rollback()
+
+ if _, err := tx.ExecContext(ctx, `DELETE FROM risk WHERE id = $1`, id); err != nil {
+ return err
+ }
+
+ if err := tx.Commit(); err != nil {
+ return errors.Wrap(err, "failed to commit")
+ }
+
+ s.risksCache.Remove(0)
+ return nil
+}
diff --git a/backend/store/role.go b/backend/store/role.go
index 6121f12424..3606e2104b 100644
--- a/backend/store/role.go
+++ b/backend/store/role.go
@@ -5,7 +5,6 @@ import (
"database/sql"
"fmt"
"strings"
- "time"
"google.golang.org/protobuf/encoding/protojson"
@@ -19,14 +18,10 @@ type RoleMessage struct {
Name string
Description string
Permissions map[string]bool
-
- // Output only
- CreatorID int
}
// UpdateRoleMessage is the message for updating roles.
type UpdateRoleMessage struct {
- UpdaterID int
ResourceID string
Name *string
@@ -50,11 +45,11 @@ func (s *Store) CheckRoleInUse(ctx context.Context, role string) (bool, error) {
}
// CreateRole creates a new role.
-func (s *Store) CreateRole(ctx context.Context, create *RoleMessage, creatorID int) (*RoleMessage, error) {
+func (s *Store) CreateRole(ctx context.Context, create *RoleMessage) (*RoleMessage, error) {
query := `
INSERT INTO
- role (creator_id, updater_id, resource_id, name, description, permissions)
- VALUES ($1, $2, $3, $4, $5, $6)
+ role (resource_id, name, description, permissions)
+ VALUES ($1, $2, $3, $4)
`
p := &storepb.RolePermissions{}
for k := range create.Permissions {
@@ -64,7 +59,7 @@ func (s *Store) CreateRole(ctx context.Context, create *RoleMessage, creatorID i
if err != nil {
return nil, err
}
- if _, err := s.db.db.ExecContext(ctx, query, creatorID, creatorID, create.ResourceID, create.Name, create.Description, permissionBytes); err != nil {
+ if _, err := s.db.db.ExecContext(ctx, query, create.ResourceID, create.Name, create.Description, permissionBytes); err != nil {
return nil, err
}
s.rolesCache.Add(create.ResourceID, create)
@@ -78,7 +73,7 @@ func (s *Store) GetRole(ctx context.Context, resourceID string) (*RoleMessage, e
}
query := `
SELECT
- creator_id, name, description, permissions
+ name, description, permissions
FROM role
WHERE resource_id = $1
`
@@ -86,7 +81,7 @@ func (s *Store) GetRole(ctx context.Context, resourceID string) (*RoleMessage, e
Permissions: map[string]bool{},
}
var permissions []byte
- if err := s.db.db.QueryRowContext(ctx, query, resourceID).Scan(&role.CreatorID, &role.Name, &role.Description, &permissions); err != nil {
+ if err := s.db.db.QueryRowContext(ctx, query, resourceID).Scan(&role.Name, &role.Description, &permissions); err != nil {
if err == sql.ErrNoRows {
return nil, nil
}
@@ -108,7 +103,7 @@ func (s *Store) GetRole(ctx context.Context, resourceID string) (*RoleMessage, e
func (s *Store) ListRoles(ctx context.Context) ([]*RoleMessage, error) {
query := `
SELECT
- creator_id, resource_id, name, description, permissions
+ resource_id, name, description, permissions
FROM role
`
rows, err := s.db.db.QueryContext(ctx, query)
@@ -123,7 +118,7 @@ func (s *Store) ListRoles(ctx context.Context) ([]*RoleMessage, error) {
Permissions: map[string]bool{},
}
var permissionBytes []byte
- if err := rows.Scan(&role.CreatorID, &role.ResourceID, &role.Name, &role.Description, &permissionBytes); err != nil {
+ if err := rows.Scan(&role.ResourceID, &role.Name, &role.Description, &permissionBytes); err != nil {
return nil, err
}
var rolePermissions storepb.RolePermissions
@@ -146,7 +141,7 @@ func (s *Store) ListRoles(ctx context.Context) ([]*RoleMessage, error) {
// UpdateRole updates an existing role.
func (s *Store) UpdateRole(ctx context.Context, patch *UpdateRoleMessage) (*RoleMessage, error) {
- set, args := []string{"updater_id = $1", "updated_ts = $2"}, []any{patch.UpdaterID, time.Now().Unix()}
+ set, args := []string{}, []any{}
if v := patch.Name; v != nil {
set, args = append(set, fmt.Sprintf("name = $%d", len(args)+1)), append(args, *v)
}
@@ -170,7 +165,7 @@ func (s *Store) UpdateRole(ctx context.Context, patch *UpdateRoleMessage) (*Role
UPDATE role
SET `+strings.Join(set, ", ")+`
WHERE resource_id = $%d
- RETURNING creator_id, name, description, permissions
+ RETURNING name, description, permissions
`, len(args))
role := &RoleMessage{
@@ -178,7 +173,7 @@ func (s *Store) UpdateRole(ctx context.Context, patch *UpdateRoleMessage) (*Role
Permissions: map[string]bool{},
}
var permissionBytes []byte
- if err := s.db.db.QueryRowContext(ctx, query, args...).Scan(&role.CreatorID, &role.Name, &role.Description, &permissionBytes); err != nil {
+ if err := s.db.db.QueryRowContext(ctx, query, args...).Scan(&role.Name, &role.Description, &permissionBytes); err != nil {
return nil, err
}
s.rolesCache.Remove(patch.ResourceID)
diff --git a/backend/store/setting.go b/backend/store/setting.go
index e28ebd5a43..b333d530db 100644
--- a/backend/store/setting.go
+++ b/backend/store/setting.go
@@ -6,7 +6,6 @@ import (
"fmt"
"log/slog"
"strings"
- "time"
"github.com/pkg/errors"
@@ -23,17 +22,14 @@ type FindSettingMessage struct {
// SetSettingMessage is the message for updating setting.
type SetSettingMessage struct {
- Name api.SettingName
- Value string
- Description *string
+ Name api.SettingName
+ Value string
}
// SettingMessage is the message of setting.
type SettingMessage struct {
- Name api.SettingName
- Value string
- Description string
- CreatedTs int64
+ Name api.SettingName
+ Value string
}
func (s *Store) GetPasswordRestrictionSetting(ctx context.Context) (*storepb.PasswordRestrictionSetting, error) {
@@ -263,21 +259,15 @@ func (s *Store) ListSettingV2(ctx context.Context, find *FindSettingMessage) ([]
}
// UpsertSettingV2 upserts the setting by name.
-func (s *Store) UpsertSettingV2(ctx context.Context, update *SetSettingMessage, principalUID int) (*SettingMessage, error) {
- fields := []string{"creator_id", "updater_id", "updated_ts", "name", "value"}
- updateFields := []string{"value = EXCLUDED.value", "updater_id = EXCLUDED.updater_id", "updated_ts = EXCLUDED.updated_ts"}
- valuePlaceholders, args := []string{"$1", "$2", "$3", "$4", "$5"}, []any{principalUID, principalUID, time.Now().Unix(), update.Name, update.Value}
+func (s *Store) UpsertSettingV2(ctx context.Context, update *SetSettingMessage) (*SettingMessage, error) {
+ fields := []string{"name", "value"}
+ updateFields := []string{"value = EXCLUDED.value"}
+ valuePlaceholders, args := []string{"$1", "$2"}, []any{update.Name, update.Value}
- if v := update.Description; v != nil {
- fields = append(fields, "description")
- valuePlaceholders = append(valuePlaceholders, fmt.Sprintf("$%d", len(args)+1))
- updateFields = append(updateFields, "description = EXCLUDED.description")
- args = append(args, *v)
- }
query := `INSERT INTO setting (` + strings.Join(fields, ", ") + `)
VALUES (` + strings.Join(valuePlaceholders, ", ") + `)
ON CONFLICT (name) DO UPDATE SET ` + strings.Join(updateFields, ", ") + `
- RETURNING name, value, description, created_ts`
+ RETURNING name, value`
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
@@ -289,8 +279,6 @@ func (s *Store) UpsertSettingV2(ctx context.Context, update *SetSettingMessage,
if err := tx.QueryRowContext(ctx, query, args...).Scan(
&setting.Name,
&setting.Value,
- &setting.Description,
- &setting.CreatedTs,
); err != nil {
if err == sql.ErrNoRows {
return nil, &common.Error{Code: common.NotFound, Err: errors.Errorf("setting not found: %s", update.Name)}
@@ -306,7 +294,7 @@ func (s *Store) UpsertSettingV2(ctx context.Context, update *SetSettingMessage,
}
// CreateSettingIfNotExistV2 creates a new setting only if the named setting doesn't exist.
-func (s *Store) CreateSettingIfNotExistV2(ctx context.Context, create *SettingMessage, principalUID int) (*SettingMessage, bool, error) {
+func (s *Store) CreateSettingIfNotExistV2(ctx context.Context, create *SettingMessage) (*SettingMessage, bool, error) {
if v, ok := s.settingCache.Get(create.Name); ok {
return v, false, nil
}
@@ -328,18 +316,16 @@ func (s *Store) CreateSettingIfNotExistV2(ctx context.Context, create *SettingMe
return settings[0], false, nil
}
- fields := []string{"creator_id", "updater_id", "name", "value", "description"}
- valuesPlaceholders, args := []string{"$1", "$2", "$3", "$4", "$5"}, []any{principalUID, principalUID, create.Name, create.Value, create.Description}
+ fields := []string{"name", "value"}
+ valuesPlaceholders, args := []string{"$1", "$2"}, []any{create.Name, create.Value}
query := `INSERT INTO setting (` + strings.Join(fields, ",") + `)
VALUES (` + strings.Join(valuesPlaceholders, ",") + `)
- RETURNING name, value, description, created_ts`
+ RETURNING name, value`
var setting SettingMessage
if err := tx.QueryRowContext(ctx, query, args...).Scan(
&setting.Name,
&setting.Value,
- &setting.Description,
- &setting.CreatedTs,
); err != nil {
return nil, false, err
}
@@ -379,9 +365,7 @@ func listSettingV2Impl(ctx context.Context, tx *Tx, find *FindSettingMessage) ([
rows, err := tx.QueryContext(ctx, `
SELECT
name,
- value,
- description,
- created_ts
+ value
FROM setting
WHERE `+strings.Join(where, " AND "), args...)
if err != nil {
@@ -395,8 +379,6 @@ func listSettingV2Impl(ctx context.Context, tx *Tx, find *FindSettingMessage) ([
if err := rows.Scan(
&settingMessage.Name,
&settingMessage.Value,
- &settingMessage.Description,
- &settingMessage.CreatedTs,
); err != nil {
return nil, err
}
diff --git a/backend/store/slow_query.go b/backend/store/slow_query.go
index 53c401a41f..e961b848b6 100644
--- a/backend/store/slow_query.go
+++ b/backend/store/slow_query.go
@@ -198,8 +198,6 @@ type UpsertSlowLogMessage struct {
InstanceUID int
LogDate time.Time
SlowLog *storepb.SlowQueryStatistics
-
- UpdaterID int
}
// UpsertSlowLog upserts slow query logs.
@@ -236,16 +234,12 @@ func (s *Store) UpsertSlowLog(ctx context.Context, upsert *UpsertSlowLogMessage)
query := `
INSERT INTO slow_query (
- creator_id,
- updater_id,
instance_id,
database_id,
log_date_ts,
slow_query_statistics
- ) VALUES ( $1, $2, $3, $4, $5, $6 )
+ ) VALUES ($1, $2, $3, $4)
ON CONFLICT (database_id, log_date_ts) DO UPDATE SET
- updater_id = EXCLUDED.updater_id,
- updated_ts = extract(epoch from now()),
slow_query_statistics = EXCLUDED.slow_query_statistics
`
@@ -256,8 +250,6 @@ func (s *Store) UpsertSlowLog(ctx context.Context, upsert *UpsertSlowLogMessage)
defer tx.Rollback()
if _, err := tx.ExecContext(ctx, query,
- upsert.UpdaterID,
- upsert.UpdaterID,
upsert.InstanceUID,
databaseUID,
logDate,
diff --git a/backend/store/sync_history.go b/backend/store/sync_history.go
index 5af001d3ce..24ae0d1684 100644
--- a/backend/store/sync_history.go
+++ b/backend/store/sync_history.go
@@ -18,7 +18,6 @@ type SyncHistory struct {
Schema string
Metadata *storepb.DatabaseSchemaMetadata
- CreatorUID int
CreateTime time.Time
}
@@ -26,7 +25,6 @@ func (s *Store) GetSyncHistoryByUID(ctx context.Context, uid int64) (*SyncHistor
query := `
SELECT
id,
- creator_id,
created_ts,
database_id,
metadata,
@@ -41,7 +39,6 @@ func (s *Store) GetSyncHistoryByUID(ctx context.Context, uid int64) (*SyncHistor
var m []byte
if err := s.db.db.QueryRowContext(ctx, query, uid).Scan(
&h.UID,
- &h.CreatorUID,
&h.CreateTime,
&h.DatabaseUID,
&m,
@@ -58,7 +55,7 @@ func (s *Store) GetSyncHistoryByUID(ctx context.Context, uid int64) (*SyncHistor
}
// UpsertDBSchema upserts a database schema.
-func (s *Store) CreateSyncHistory(ctx context.Context, databaseID int, metadata *storepb.DatabaseSchemaMetadata, schema string, updaterID int) (int64, error) {
+func (s *Store) CreateSyncHistory(ctx context.Context, databaseID int, metadata *storepb.DatabaseSchemaMetadata, schema string) (int64, error) {
metadataBytes, err := protojson.Marshal(metadata)
if err != nil {
return 0, errors.Wrapf(err, "failed to marshal")
@@ -66,12 +63,11 @@ func (s *Store) CreateSyncHistory(ctx context.Context, databaseID int, metadata
query := `
INSERT INTO sync_history (
- creator_id,
database_id,
metadata,
raw_dump
)
- VALUES ($1, $2, $3, $4)
+ VALUES ($1, $2, $3)
RETURNING id
`
tx, err := s.db.BeginTx(ctx, nil)
@@ -82,7 +78,6 @@ func (s *Store) CreateSyncHistory(ctx context.Context, databaseID int, metadata
var id int64
if err := tx.QueryRowContext(ctx, query,
- updaterID,
databaseID,
metadataBytes,
schema,
diff --git a/backend/store/task_dag.go b/backend/store/task_dag.go
index 93bb06960c..40189fad38 100644
--- a/backend/store/task_dag.go
+++ b/backend/store/task_dag.go
@@ -54,17 +54,15 @@ func (*Store) createTaskDAG(ctx context.Context, tx *Tx, create *TaskDAGMessage)
query := `
INSERT INTO task_dag (
from_task_id,
- to_task_id,
- payload
+ to_task_id
)
- VALUES ($1, $2, $3)
+ VALUES ($1, $2)
RETURNING from_task_id, to_task_id
`
var taskDAG TaskDAGMessage
if err := tx.QueryRowContext(ctx, query,
create.FromTaskID,
create.ToTaskID,
- "{}", /* payload */
).Scan(
&taskDAG.FromTaskID,
&taskDAG.ToTaskID,
diff --git a/backend/store/vcs_connector.go b/backend/store/vcs_connector.go
index e8ef8bd085..a086fdfd18 100644
--- a/backend/store/vcs_connector.go
+++ b/backend/store/vcs_connector.go
@@ -5,7 +5,6 @@ import (
"database/sql"
"fmt"
"strings"
- "time"
"github.com/pkg/errors"
"google.golang.org/protobuf/encoding/protojson"
@@ -25,11 +24,7 @@ type VCSConnectorMessage struct {
Payload *storepb.VCSConnector
// Output only fields
- UID int
- CreatorID int
- UpdaterID int
- CreatedTs int64
- UpdatedTs int64
+ UID int
}
// FindVCSConnectorMessage is the API message for finding VCS connectors.
@@ -42,7 +37,6 @@ type FindVCSConnectorMessage struct {
// UpdateVCSConnectorMessage is the message to update a VCS connector.
type UpdateVCSConnectorMessage struct {
ProjectID string
- UpdaterID int
UID int
// Domain specific fields
@@ -93,11 +87,7 @@ func (s *Store) ListVCSConnectors(ctx context.Context, find *FindVCSConnectorMes
vcs.resource_id,
project.resource_id AS project_resource_id,
vcs_connector.resource_id,
- vcs_connector.creator_id,
- vcs_connector.updater_id,
- vcs_connector.payload,
- vcs_connector.created_ts,
- vcs_connector.updated_ts
+ vcs_connector.payload
FROM vcs_connector
LEFT JOIN project ON project.id = vcs_connector.project_id
LEFT JOIN vcs ON vcs.id = vcs_connector.vcs_id
@@ -119,11 +109,7 @@ func (s *Store) ListVCSConnectors(ctx context.Context, find *FindVCSConnectorMes
&vcsConnector.VCSResourceID,
&vcsConnector.ProjectID,
&vcsConnector.ResourceID,
- &vcsConnector.CreatorID,
- &vcsConnector.UpdaterID,
&payloadStr,
- &vcsConnector.CreatedTs,
- &vcsConnector.UpdatedTs,
); err != nil {
return nil, err
}
@@ -150,7 +136,6 @@ func (s *Store) CreateVCSConnector(ctx context.Context, create *VCSConnectorMess
if err != nil {
return nil, err
}
- create.UpdaterID = create.CreatorID
payload, err := protojson.Marshal(create.Payload)
if err != nil {
@@ -165,27 +150,21 @@ func (s *Store) CreateVCSConnector(ctx context.Context, create *VCSConnectorMess
query := `
INSERT INTO vcs_connector (
- creator_id,
- updater_id,
vcs_id,
project_id,
resource_id,
payload
)
- VALUES ($1, $2, $3, $4, $5, $6)
- RETURNING id, created_ts, updated_ts
+ VALUES ($1, $2, $3, $4)
+ RETURNING id
`
if err := tx.QueryRowContext(ctx, query,
- create.CreatorID,
- create.UpdaterID,
create.VCSUID,
project.UID,
create.ResourceID,
payload,
).Scan(
&create.UID,
- &create.CreatedTs,
- &create.UpdatedTs,
); err != nil {
return nil, err
}
@@ -200,7 +179,7 @@ func (s *Store) CreateVCSConnector(ctx context.Context, create *VCSConnectorMess
// UpdateVCSConnector updates a VCS connector.
func (s *Store) UpdateVCSConnector(ctx context.Context, update *UpdateVCSConnectorMessage) error {
- set, args := []string{"updater_id = $1", "updated_ts = $2"}, []any{update.UpdaterID, time.Now().Unix()}
+ set, args := []string{}, []any{}
var payloadSet []string
if v := update.Branch; v != nil {
diff --git a/backend/store/vcs_provider.go b/backend/store/vcs_provider.go
index 7088fe36c2..a36ab65145 100644
--- a/backend/store/vcs_provider.go
+++ b/backend/store/vcs_provider.go
@@ -5,7 +5,6 @@ import (
"database/sql"
"fmt"
"strings"
- "time"
"github.com/pkg/errors"
@@ -101,7 +100,7 @@ func (s *Store) ListVCSProviders(ctx context.Context) ([]*VCSProviderMessage, er
}
// CreateVCSProvider creates an VCS provider.
-func (s *Store) CreateVCSProvider(ctx context.Context, principalUID int, create *VCSProviderMessage) (*VCSProviderMessage, error) {
+func (s *Store) CreateVCSProvider(ctx context.Context, create *VCSProviderMessage) (*VCSProviderMessage, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
return nil, errors.Wrapf(err, "failed to begin transaction")
@@ -110,20 +109,16 @@ func (s *Store) CreateVCSProvider(ctx context.Context, principalUID int, create
query := `
INSERT INTO vcs (
- creator_id,
- updater_id,
resource_id,
name,
type,
instance_url,
access_token
)
- VALUES ($1, $2, $3, $4, $5, $6, $7)
+ VALUES ($1, $2, $3, $4, $5)
RETURNING id
`
if err := tx.QueryRowContext(ctx, query,
- principalUID,
- principalUID,
create.ResourceID,
create.Title,
create.Type.String(),
@@ -147,8 +142,8 @@ func (s *Store) CreateVCSProvider(ctx context.Context, principalUID int, create
}
// UpdateVCSProvider updates an VCS provider.
-func (s *Store) UpdateVCSProvider(ctx context.Context, principalUID int, vcsProviderUID int, update *UpdateVCSProviderMessage) (*VCSProviderMessage, error) {
- set, args := []string{"updater_id = $1", "updated_ts = $2"}, []any{principalUID, time.Now().Unix()}
+func (s *Store) UpdateVCSProvider(ctx context.Context, vcsProviderUID int, update *UpdateVCSProviderMessage) (*VCSProviderMessage, error) {
+ set, args := []string{}, []any{}
if v := update.Name; v != nil {
set, args = append(set, fmt.Sprintf("name = $%d", len(args)+1)), append(args, *v)
}
diff --git a/backend/utils/utils.go b/backend/utils/utils.go
index 6a57561685..6e85891b11 100644
--- a/backend/utils/utils.go
+++ b/backend/utils/utils.go
@@ -433,7 +433,7 @@ func UpdateProjectPolicyFromGrantIssue(ctx context.Context, stores *store.Store,
InheritFromParent: false,
// Enforce cannot be false while creating a policy.
Enforce: true,
- }, api.SystemBotID); err != nil {
+ }); err != nil {
return err
}