Skip to content

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

chore: timestamptz for storage time (#15170)

Danny Xu727d9cf91a64
diff --git a/backend/api/v1/anomaly_service.go b/backend/api/v1/anomaly_service.go
index eab7807f72..d77aa6ea72 100644
--- a/backend/api/v1/anomaly_service.go
+++ b/backend/api/v1/anomaly_service.go
@@ -2,7 +2,6 @@ package v1
import (
"context"
- "time"
"github.com/pkg/errors"
"google.golang.org/grpc/codes"
@@ -112,7 +111,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.UpdatedTs, 0)),
+ CreateTime: timestamppb.New(anomaly.UpdatedAt),
}
database, err := s.store.GetDatabaseV2(ctx, &store.FindDatabaseMessage{
diff --git a/backend/api/v1/audit_log_service.go b/backend/api/v1/audit_log_service.go
index 5b269ef91f..29568fb472 100644
--- a/backend/api/v1/audit_log_service.go
+++ b/backend/api/v1/audit_log_service.go
@@ -182,7 +182,7 @@ func convertToAuditLog(ctx context.Context, stores *store.Store, l *store.AuditL
}
return &v1pb.AuditLog{
Name: fmt.Sprintf("%s/%s%d", l.Payload.Parent, common.AuditLogPrefix, l.ID),
- CreateTime: timestamppb.New(time.Unix(l.CreatedTs, 0)),
+ CreateTime: timestamppb.New(l.CreatedAt),
User: user,
Method: l.Payload.Method,
Severity: convertToAuditLogSeverity(l.Payload.Severity),
@@ -316,12 +316,11 @@ func (s *AuditLogService) getSearchAuditLogsFilter(ctx context.Context, filter s
if err != nil {
return "", errors.Errorf("failed to parse time %v, error: %v", value, err)
}
- ts := t.Unix()
- positionalArgs = append(positionalArgs, ts)
+ positionalArgs = append(positionalArgs, t)
if functionName == "_>=_" {
- return fmt.Sprintf("created_ts >= $%d", len(positionalArgs)), nil
+ return fmt.Sprintf("created_at >= $%d", len(positionalArgs)), nil
}
- return fmt.Sprintf("created_ts <= $%d", len(positionalArgs)), nil
+ return fmt.Sprintf("created_at <= $%d", len(positionalArgs)), nil
default:
return "", errors.Errorf("unexpected function %v", functionName)
@@ -353,7 +352,7 @@ func getSearchAuditLogsOrderByKeys(orderBy string) ([]store.OrderByKey, error) {
for _, orderByKey := range keys {
key := ""
if orderByKey.key == "create_time" {
- key = "created_ts"
+ key = "created_at"
}
if key == "" {
return nil, status.Errorf(codes.InvalidArgument, "invalid order by key %v", orderByKey.key)
diff --git a/backend/api/v1/auth_service.go b/backend/api/v1/auth_service.go
index 973acc438a..93232803f9 100644
--- a/backend/api/v1/auth_service.go
+++ b/backend/api/v1/auth_service.go
@@ -634,7 +634,7 @@ func (s *AuthService) needResetPassword(ctx context.Context, user *store.UserMes
}
if passwordRestriction.PasswordRotation != nil && passwordRestriction.PasswordRotation.GetNanos() > 0 {
- lastChangePasswordTime := user.CreatedTime
+ lastChangePasswordTime := user.CreatedAt
if user.Profile.LastChangePasswordTime != nil {
lastChangePasswordTime = user.Profile.LastChangePasswordTime.AsTime()
}
diff --git a/backend/api/v1/changelist_service.go b/backend/api/v1/changelist_service.go
index 312049008a..745f874ccc 100644
--- a/backend/api/v1/changelist_service.go
+++ b/backend/api/v1/changelist_service.go
@@ -275,7 +275,7 @@ func (s *ChangelistService) convertStoreChangelist(ctx context.Context, changeli
v1Changelist := &v1pb.Changelist{
Name: fmt.Sprintf("projects/%s/changelists/%s", changelist.ProjectID, changelist.ResourceID),
Description: changelist.Payload.Description,
- UpdateTime: timestamppb.New(changelist.UpdatedTime),
+ UpdateTime: timestamppb.New(changelist.UpdatedAt),
Creator: fmt.Sprintf("users/%s", creator.Email),
}
for _, change := range changelist.Payload.Changes {
diff --git a/backend/api/v1/database_service.go b/backend/api/v1/database_service.go
index f01299bd1f..f98fac9f2d 100644
--- a/backend/api/v1/database_service.go
+++ b/backend/api/v1/database_service.go
@@ -1240,7 +1240,7 @@ func (s *DatabaseService) convertToDatabase(ctx context.Context, database *store
return &v1pb.Database{
Name: common.FormatDatabase(database.InstanceID, database.DatabaseName),
SyncState: syncState,
- SuccessfulSyncTime: timestamppb.New(time.Unix(database.SuccessfulSyncTimeTs, 0)),
+ SuccessfulSyncTime: timestamppb.New(database.SyncAt),
Project: common.FormatProject(database.ProjectID),
Environment: environment,
EffectiveEnvironment: effectiveEnvironment,
diff --git a/backend/api/v1/database_service_changelog.go b/backend/api/v1/database_service_changelog.go
index 203e8b9c99..9e3efd871e 100644
--- a/backend/api/v1/database_service_changelog.go
+++ b/backend/api/v1/database_service_changelog.go
@@ -187,7 +187,7 @@ func (s *DatabaseService) convertToChangelogs(d *store.DatabaseMessage, cs []*st
func (*DatabaseService) convertToChangelog(d *store.DatabaseMessage, c *store.ChangelogMessage) (*v1pb.Changelog, error) {
cl := &v1pb.Changelog{
Name: common.FormatChangelog(d.InstanceID, d.DatabaseName, c.UID),
- CreateTime: timestamppb.New(c.CreatedTime),
+ CreateTime: timestamppb.New(c.CreatedAt),
Status: convertToChangelogStatus(c.Status),
Statement: "",
StatementSize: 0,
diff --git a/backend/api/v1/database_service_revision.go b/backend/api/v1/database_service_revision.go
index 7cbff737ea..2643e5818f 100644
--- a/backend/api/v1/database_service_revision.go
+++ b/backend/api/v1/database_service_revision.go
@@ -262,7 +262,7 @@ func convertToRevision(ctx context.Context, s *store.Store, parent string, revis
r := &v1pb.Revision{
Name: fmt.Sprintf("%s/%s%d", parent, common.RevisionNamePrefix, revision.UID),
Release: revision.Payload.Release,
- CreateTime: timestamppb.New(revision.CreateTime),
+ CreateTime: timestamppb.New(revision.CreatedAt),
Sheet: revision.Payload.Sheet,
SheetSha256: revision.Payload.SheetSha256,
Statement: sheet.Statement,
@@ -283,8 +283,8 @@ func convertToRevision(ctx context.Context, s *store.Store, parent string, revis
}
r.Deleter = common.FormatUserEmail(deleter.Email)
}
- if revision.DeleteTime != nil {
- r.DeleteTime = timestamppb.New(*revision.DeleteTime)
+ if revision.DeletedAt != nil {
+ r.DeleteTime = timestamppb.New(*revision.DeletedAt)
}
return r, nil
diff --git a/backend/api/v1/issue_service.go b/backend/api/v1/issue_service.go
index 12dd349985..81fe02400f 100644
--- a/backend/api/v1/issue_service.go
+++ b/backend/api/v1/issue_service.go
@@ -162,19 +162,17 @@ func (s *IssueService) getIssueFind(ctx context.Context, filter string, query st
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "failed to parse create_time %s, err: %v", spec.Value, err)
}
- ts := t.Unix()
if spec.Operator == ComparatorTypeGreaterEqual {
- issueFind.CreatedTsAfter = &ts
+ issueFind.CreatedAtAfter = &t
} else {
- issueFind.CreatedTsBefore = &ts
+ issueFind.CreatedAtBefore = &t
}
case "create_time_after":
t, err := time.Parse(time.RFC3339, spec.Value)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "failed to parse create_time_after %s, err: %v", spec.Value, err)
}
- ts := t.Unix()
- issueFind.CreatedTsAfter = &ts
+ issueFind.CreatedAtAfter = &t
case "type":
if spec.Operator != ComparatorTypeEqual {
return nil, status.Errorf(codes.InvalidArgument, `only support "=" operation for "type" filter`)
diff --git a/backend/api/v1/issue_service_convert.go b/backend/api/v1/issue_service_convert.go
index f46a9aed9d..eb696ebffd 100644
--- a/backend/api/v1/issue_service_convert.go
+++ b/backend/api/v1/issue_service_convert.go
@@ -3,7 +3,6 @@ package v1
import (
"context"
"fmt"
- "time"
"github.com/pkg/errors"
"google.golang.org/protobuf/types/known/timestamppb"
@@ -52,8 +51,8 @@ func (s *IssueService) convertToIssue(ctx context.Context, issue *store.IssueMes
ApprovalFindingError: "",
Subscribers: nil,
Creator: common.FormatUserEmail(issue.Creator.Email),
- CreateTime: timestamppb.New(issue.CreatedTime),
- UpdateTime: timestamppb.New(issue.UpdatedTime),
+ CreateTime: timestamppb.New(issue.CreatedAt),
+ UpdateTime: timestamppb.New(issue.UpdatedAt),
Plan: "",
Rollout: "",
GrantRequest: convertedGrantRequest,
@@ -340,8 +339,8 @@ func convertToIssueComments(issueName string, issueComments []*store.IssueCommen
func convertToIssueComment(issueName string, ic *store.IssueCommentMessage) *v1pb.IssueComment {
r := &v1pb.IssueComment{
Comment: ic.Payload.Comment,
- CreateTime: timestamppb.New(time.Unix(ic.CreatedTs, 0)),
- UpdateTime: timestamppb.New(time.Unix(ic.UpdatedTs, 0)),
+ CreateTime: timestamppb.New(ic.CreatedAt),
+ UpdateTime: timestamppb.New(ic.UpdatedAt),
Name: fmt.Sprintf("%s/%s%d", issueName, common.IssueCommentNamePrefix, ic.UID),
Creator: common.FormatUserEmail(ic.Creator.Email),
}
diff --git a/backend/api/v1/plan_service.go b/backend/api/v1/plan_service.go
index 2af9f0af5c..8065a905fa 100644
--- a/backend/api/v1/plan_service.go
+++ b/backend/api/v1/plan_service.go
@@ -457,17 +457,27 @@ func (s *PlanService) UpdatePlan(ctx context.Context, request *v1pb.UpdatePlanRe
}
// EarliestAllowedTs
- if spec.EarliestAllowedTime.GetSeconds() != task.EarliestAllowedTs {
- seconds := spec.EarliestAllowedTime.GetSeconds()
- taskPatch.EarliestAllowedTs = &seconds
+ taskEarliest := int64(0)
+ if task.EarliestAllowedAt != nil {
+ taskEarliest = task.EarliestAllowedAt.Unix()
+ }
+ specEarliest := spec.EarliestAllowedTime.GetSeconds()
+ if specEarliest != taskEarliest {
+ taskPatch.UpdateEarliestAllowedTs = true
+ if specEarliest == 0 {
+ taskPatch.EarliestAllowedTs = nil
+ } else {
+ v := spec.EarliestAllowedTime.AsTime()
+ taskPatch.EarliestAllowedTs = &v
+ }
doUpdate = true
var fromEarliestAllowedTime, toEarliestAllowedTime *timestamppb.Timestamp
- if task.EarliestAllowedTs != 0 {
- fromEarliestAllowedTime = timestamppb.New(time.Unix(task.EarliestAllowedTs, 0))
+ if task.EarliestAllowedAt != nil {
+ fromEarliestAllowedTime = timestamppb.New(*task.EarliestAllowedAt)
}
- if seconds != 0 {
- toEarliestAllowedTime = timestamppb.New(time.Unix(seconds, 0))
+ if specEarliest != 0 {
+ toEarliestAllowedTime = spec.EarliestAllowedTime
}
issueCommentCreates = append(issueCommentCreates, &store.IssueCommentMessage{
IssueUID: issue.UID,
@@ -982,11 +992,10 @@ func (s *PlanService) buildPlanFindWithFilter(ctx context.Context, planFind *sto
if err != nil {
return errors.Wrap(err, "failed to parse create_time value")
}
- ts := t.Unix()
if spec.Operator == ComparatorTypeGreaterEqual {
- planFind.CreatedTsAfter = &ts
+ planFind.CreatedAtAfter = &t
} else {
- planFind.CreatedTsBefore = &ts
+ planFind.CreatedAtBefore = &t
}
case "has_pipeline":
if spec.Operator != ComparatorTypeEqual {
diff --git a/backend/api/v1/release_service.go b/backend/api/v1/release_service.go
index a171e0b45d..143d0e006f 100644
--- a/backend/api/v1/release_service.go
+++ b/backend/api/v1/release_service.go
@@ -516,7 +516,7 @@ func convertToReleases(ctx context.Context, s *store.Store, releases []*store.Re
func convertToRelease(ctx context.Context, s *store.Store, release *store.ReleaseMessage) (*v1pb.Release, error) {
r := &v1pb.Release{
Title: release.Payload.Title,
- CreateTime: timestamppb.New(release.CreatedTime),
+ CreateTime: timestamppb.New(release.At),
VcsSource: convertToReleaseVcsSource(release.Payload.VcsSource),
State: convertDeletedToState(release.Deleted),
}
diff --git a/backend/api/v1/rollout_service_converter.go b/backend/api/v1/rollout_service_converter.go
index cf707a50cb..c1b3b2de19 100644
--- a/backend/api/v1/rollout_service_converter.go
+++ b/backend/api/v1/rollout_service_converter.go
@@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"slices"
- "time"
"github.com/pkg/errors"
"google.golang.org/grpc/codes"
@@ -47,8 +46,8 @@ func convertToPlan(ctx context.Context, s *store.Store, plan *store.PlanMessage)
ReleaseSource: &v1pb.Plan_ReleaseSource{
Release: plan.Config.GetReleaseSource().GetRelease(),
},
- CreateTime: timestamppb.New(time.Unix(plan.CreatedTs, 0)),
- UpdateTime: timestamppb.New(time.Unix(plan.UpdatedTs, 0)),
+ CreateTime: timestamppb.New(plan.CreatedAt),
+ UpdateTime: timestamppb.New(plan.UpdatedAt),
PlanCheckRunStatusCount: plan.PlanCheckRunStatusCount,
DeploymentConfigSnapshot: convertToDeploymentConfigSnapshot(plan.Config.GetDeploymentSnapshot().GetDeploymentConfigSnapshot()),
}
@@ -355,7 +354,7 @@ func convertToPlanCheckRuns(ctx context.Context, s *store.Store, projectID strin
func convertToPlanCheckRun(ctx context.Context, s *store.Store, projectID string, planUID int64, run *store.PlanCheckRunMessage) (*v1pb.PlanCheckRun, error) {
converted := &v1pb.PlanCheckRun{
Name: common.FormatPlanCheckRun(projectID, planUID, int64(run.UID)),
- CreateTime: timestamppb.New(time.Unix(run.CreatedTs, 0)),
+ CreateTime: timestamppb.New(run.CreatedAt),
Type: convertToPlanCheckRunType(run.Type),
Status: convertToPlanCheckRunStatus(run.Status),
Target: "",
@@ -484,9 +483,8 @@ func convertToTaskRun(ctx context.Context, s *store.Store, stateCfg *state.State
t := &v1pb.TaskRun{
Name: common.FormatTaskRun(taskRun.ProjectID, taskRun.PipelineUID, taskRun.StageUID, taskRun.TaskUID, taskRun.ID),
Creator: common.FormatUserEmail(taskRun.Creator.Email),
- CreateTime: timestamppb.New(time.Unix(taskRun.CreatedTs, 0)),
- UpdateTime: timestamppb.New(time.Unix(taskRun.UpdatedTs, 0)),
- StartTime: timestamppb.New(time.Unix(taskRun.StartedTs, 0)),
+ CreateTime: timestamppb.New(taskRun.CreatedAt),
+ UpdateTime: timestamppb.New(taskRun.UpdatedAt),
Title: taskRun.Name,
Status: convertToTaskRunStatus(taskRun.Status),
Detail: taskRun.ResultProto.Detail,
@@ -494,6 +492,9 @@ func convertToTaskRun(ctx context.Context, s *store.Store, stateCfg *state.State
SchemaVersion: taskRun.ResultProto.Version,
Sheet: "",
}
+ if taskRun.StartedAt != nil {
+ t.StartTime = timestamppb.New(*taskRun.StartedAt)
+ }
if taskRun.SheetUID != nil && *taskRun.SheetUID != 0 {
sheet, err := s.GetSheet(ctx, &store.FindSheetMessage{UID: taskRun.SheetUID})
@@ -650,7 +651,7 @@ func convertToRollout(ctx context.Context, s *store.Store, project *store.Projec
Plan: "",
Title: rollout.Name,
Stages: nil,
- CreateTime: timestamppb.New(time.Unix(rollout.CreatedTs, 0)),
+ CreateTime: timestamppb.New(rollout.CreatedAt),
}
creator, err := s.GetUserByID(ctx, rollout.CreatorUID)
diff --git a/backend/api/v1/rollout_service_task.go b/backend/api/v1/rollout_service_task.go
index 2b9508b842..4b1220a349 100644
--- a/backend/api/v1/rollout_service_task.go
+++ b/backend/api/v1/rollout_service_task.go
@@ -253,16 +253,20 @@ func getTaskCreatesFromCreateDatabaseConfig(ctx context.Context, s *store.Store,
return nil, errors.Wrap(err, "failed to create database creation task, unable to marshal payload")
}
+ v := &store.TaskMessage{
+ InstanceID: instance.UID,
+ DatabaseID: nil,
+ Name: fmt.Sprintf("Create database %v", payload.DatabaseName),
+ Type: api.TaskDatabaseCreate,
+ DatabaseName: payload.DatabaseName,
+ Payload: string(bytes),
+ }
+ if spec.EarliestAllowedTime.GetSeconds() > 0 {
+ t := spec.EarliestAllowedTime.AsTime()
+ v.EarliestAllowedAt = &t
+ }
return []*store.TaskMessage{
- {
- InstanceID: instance.UID,
- DatabaseID: nil,
- Name: fmt.Sprintf("Create database %v", payload.DatabaseName),
- Type: api.TaskDatabaseCreate,
- DatabaseName: payload.DatabaseName,
- Payload: string(bytes),
- EarliestAllowedTs: spec.EarliestAllowedTime.GetSeconds(),
- },
+ v,
}, nil
}()
if err != nil {
@@ -335,12 +339,15 @@ func getTaskCreatesFromExportDataConfig(ctx context.Context, s *store.Store, spe
}
payloadString := string(bytes)
taskCreate := &store.TaskMessage{
- Name: fmt.Sprintf("Export data from database %q", database.DatabaseName),
- InstanceID: instance.UID,
- DatabaseID: &database.UID,
- Type: api.TaskDatabaseDataExport,
- EarliestAllowedTs: spec.EarliestAllowedTime.GetSeconds(),
- Payload: payloadString,
+ Name: fmt.Sprintf("Export data from database %q", database.DatabaseName),
+ InstanceID: instance.UID,
+ DatabaseID: &database.UID,
+ Type: api.TaskDatabaseDataExport,
+ Payload: payloadString,
+ }
+ if spec.EarliestAllowedTime.GetSeconds() > 0 {
+ t := spec.EarliestAllowedTime.AsTime()
+ taskCreate.EarliestAllowedAt = &t
}
return []*store.TaskMessage{taskCreate}, nil, nil
}
@@ -391,12 +398,15 @@ func getTaskCreatesFromChangeDatabaseConfigDatabaseTarget(ctx context.Context, s
}
payloadString := string(bytes)
taskCreate := &store.TaskMessage{
- Name: fmt.Sprintf("Establish baseline for database %q", database.DatabaseName),
- InstanceID: instance.UID,
- DatabaseID: &database.UID,
- Type: api.TaskDatabaseSchemaBaseline,
- EarliestAllowedTs: spec.EarliestAllowedTime.GetSeconds(),
- Payload: payloadString,
+ Name: fmt.Sprintf("Establish baseline for database %q", database.DatabaseName),
+ InstanceID: instance.UID,
+ DatabaseID: &database.UID,
+ Type: api.TaskDatabaseSchemaBaseline,
+ Payload: payloadString,
+ }
+ if spec.EarliestAllowedTime.GetSeconds() > 0 {
+ t := spec.EarliestAllowedTime.AsTime()
+ taskCreate.EarliestAllowedAt = &t
}
return []*store.TaskMessage{taskCreate}, nil, nil
@@ -419,12 +429,15 @@ func getTaskCreatesFromChangeDatabaseConfigDatabaseTarget(ctx context.Context, s
}
payloadString := string(bytes)
taskCreate := &store.TaskMessage{
- Name: fmt.Sprintf("DDL(schema) for database %q", database.DatabaseName),
- InstanceID: instance.UID,
- DatabaseID: &database.UID,
- Type: api.TaskDatabaseSchemaUpdate,
- EarliestAllowedTs: spec.EarliestAllowedTime.GetSeconds(),
- Payload: payloadString,
+ Name: fmt.Sprintf("DDL(schema) for database %q", database.DatabaseName),
+ InstanceID: instance.UID,
+ DatabaseID: &database.UID,
+ Type: api.TaskDatabaseSchemaUpdate,
+ Payload: payloadString,
+ }
+ if spec.EarliestAllowedTime.GetSeconds() > 0 {
+ t := spec.EarliestAllowedTime.AsTime()
+ taskCreate.EarliestAllowedAt = &t
}
return []*store.TaskMessage{taskCreate}, nil, nil
@@ -447,12 +460,15 @@ func getTaskCreatesFromChangeDatabaseConfigDatabaseTarget(ctx context.Context, s
}
payloadString := string(bytes)
taskCreate := &store.TaskMessage{
- Name: fmt.Sprintf("SDL for database %q", database.DatabaseName),
- InstanceID: instance.UID,
- DatabaseID: &database.UID,
- Type: api.TaskDatabaseSchemaUpdateSDL,
- EarliestAllowedTs: spec.EarliestAllowedTime.GetSeconds(),
- Payload: payloadString,
+ Name: fmt.Sprintf("SDL for database %q", database.DatabaseName),
+ InstanceID: instance.UID,
+ DatabaseID: &database.UID,
+ Type: api.TaskDatabaseSchemaUpdateSDL,
+ Payload: payloadString,
+ }
+ if spec.EarliestAllowedTime.GetSeconds() > 0 {
+ t := spec.EarliestAllowedTime.AsTime()
+ taskCreate.EarliestAllowedAt = &t
}
return []*store.TaskMessage{taskCreate}, nil, nil
@@ -479,14 +495,18 @@ func getTaskCreatesFromChangeDatabaseConfigDatabaseTarget(ctx context.Context, s
if err != nil {
return nil, nil, errors.Wrapf(err, "failed to marshal database schema update gh-ost sync payload")
}
- taskCreateList = append(taskCreateList, &store.TaskMessage{
- Name: fmt.Sprintf("Update schema gh-ost sync for database %q", database.DatabaseName),
- InstanceID: instance.UID,
- DatabaseID: &database.UID,
- Type: api.TaskDatabaseSchemaUpdateGhostSync,
- EarliestAllowedTs: spec.EarliestAllowedTime.GetSeconds(),
- Payload: string(bytesSync),
- })
+ v := &store.TaskMessage{
+ Name: fmt.Sprintf("Update schema gh-ost sync for database %q", database.DatabaseName),
+ InstanceID: instance.UID,
+ DatabaseID: &database.UID,
+ Type: api.TaskDatabaseSchemaUpdateGhostSync,
+ Payload: string(bytesSync),
+ }
+ if spec.EarliestAllowedTime.GetSeconds() > 0 {
+ t := spec.EarliestAllowedTime.AsTime()
+ v.EarliestAllowedAt = &t
+ }
+ taskCreateList = append(taskCreateList, v)
// task "cutover"
payloadCutover := &storepb.TaskDatabaseUpdatePayload{
@@ -496,14 +516,18 @@ func getTaskCreatesFromChangeDatabaseConfigDatabaseTarget(ctx context.Context, s
if err != nil {
return nil, nil, errors.Wrapf(err, "failed to marshal database schema update ghost cutover payload")
}
- taskCreateList = append(taskCreateList, &store.TaskMessage{
- Name: fmt.Sprintf("Update schema gh-ost cutover for database %q", database.DatabaseName),
- InstanceID: instance.UID,
- DatabaseID: &database.UID,
- Type: api.TaskDatabaseSchemaUpdateGhostCutover,
- EarliestAllowedTs: spec.EarliestAllowedTime.GetSeconds(),
- Payload: string(bytesCutover),
- })
+ cutoverV := &store.TaskMessage{
+ Name: fmt.Sprintf("Update schema gh-ost cutover for database %q", database.DatabaseName),
+ InstanceID: instance.UID,
+ DatabaseID: &database.UID,
+ Type: api.TaskDatabaseSchemaUpdateGhostCutover,
+ Payload: string(bytesCutover),
+ }
+ if spec.EarliestAllowedTime.GetSeconds() > 0 {
+ t := spec.EarliestAllowedTime.AsTime()
+ cutoverV.EarliestAllowedAt = &t
+ }
+ taskCreateList = append(taskCreateList, cutoverV)
// The below list means that taskCreateList[0] blocks taskCreateList[1].
// In other words, task "sync" blocks task "cutover".
@@ -536,12 +560,15 @@ func getTaskCreatesFromChangeDatabaseConfigDatabaseTarget(ctx context.Context, s
}
payloadString := string(bytes)
taskCreate := &store.TaskMessage{
- Name: fmt.Sprintf("DML(data) for database %q", database.DatabaseName),
- InstanceID: instance.UID,
- DatabaseID: &database.UID,
- Type: api.TaskDatabaseDataUpdate,
- EarliestAllowedTs: spec.EarliestAllowedTime.GetSeconds(),
- Payload: payloadString,
+ Name: fmt.Sprintf("DML(data) for database %q", database.DatabaseName),
+ InstanceID: instance.UID,
+ DatabaseID: &database.UID,
+ Type: api.TaskDatabaseDataUpdate,
+ Payload: payloadString,
+ }
+ if spec.EarliestAllowedTime.GetSeconds() > 0 {
+ t := spec.EarliestAllowedTime.AsTime()
+ taskCreate.EarliestAllowedAt = &t
}
return []*store.TaskMessage{taskCreate}, nil, nil
default:
diff --git a/backend/api/v1/sheet_service.go b/backend/api/v1/sheet_service.go
index abf9556931..659de803bb 100644
--- a/backend/api/v1/sheet_service.go
+++ b/backend/api/v1/sheet_service.go
@@ -289,7 +289,7 @@ func (s *SheetService) convertToAPISheetMessage(ctx context.Context, sheet *stor
Name: common.FormatSheet(project.ResourceID, sheet.UID),
Title: sheet.Title,
Creator: fmt.Sprintf("users/%s", creator.Email),
- CreateTime: timestamppb.New(sheet.CreatedTime),
+ CreateTime: timestamppb.New(sheet.CreatedAt),
Content: []byte(sheet.Statement),
ContentSize: sheet.Size,
Payload: v1SheetPayload,
diff --git a/backend/api/v1/sql_service.go b/backend/api/v1/sql_service.go
index 304b929b9f..5d8a6b11cb 100644
--- a/backend/api/v1/sql_service.go
+++ b/backend/api/v1/sql_service.go
@@ -937,7 +937,7 @@ func (s *SQLService) convertToV1QueryHistory(ctx context.Context, history *store
Error: history.Payload.Error,
Database: history.Database,
Creator: common.FormatUserEmail(user.Email),
- CreateTime: timestamppb.New(history.CreatedTime),
+ CreateTime: timestamppb.New(history.CreatedAt),
Duration: history.Payload.Duration,
Type: historyType,
}, nil
diff --git a/backend/api/v1/worksheet_service.go b/backend/api/v1/worksheet_service.go
index 92c6ea2f9a..4730fabb96 100644
--- a/backend/api/v1/worksheet_service.go
+++ b/backend/api/v1/worksheet_service.go
@@ -576,8 +576,8 @@ func (s *WorksheetService) convertToAPIWorksheetMessage(ctx context.Context, wor
Database: databaseParent,
Title: worksheet.Title,
Creator: fmt.Sprintf("users/%s", creator.Email),
- CreateTime: timestamppb.New(worksheet.CreatedTime),
- UpdateTime: timestamppb.New(worksheet.UpdatedTime),
+ CreateTime: timestamppb.New(worksheet.CreatedAt),
+ UpdateTime: timestamppb.New(worksheet.UpdatedAt),
Content: []byte(worksheet.Statement),
ContentSize: worksheet.Size,
Visibility: visibility,
diff --git a/backend/enterprise/api/subscription.go b/backend/enterprise/api/subscription.go
index 5cdb936826..c3a081f671 100644
--- a/backend/enterprise/api/subscription.go
+++ b/backend/enterprise/api/subscription.go
@@ -9,7 +9,7 @@ import (
// SubscriptionPatch is the API message for update the subscription.
type SubscriptionPatch struct {
UpdaterID int
- License string `jsonapi:"attr,license"`
+ License string
}
// Subscription is the API message for subscription.
diff --git a/backend/legacyapi/task.go b/backend/legacyapi/task.go
index 79dbbfb744..7463d5f646 100644
--- a/backend/legacyapi/task.go
+++ b/backend/legacyapi/task.go
@@ -2,6 +2,7 @@ package api
import (
"encoding/json"
+ "time"
"github.com/pkg/errors"
@@ -137,13 +138,14 @@ type TaskPatch struct {
UpdaterID int
// Domain specific fields
- DatabaseID *int
- EarliestAllowedTs *int64 `jsonapi:"attr,earliestAllowedTs"`
+ DatabaseID *int
+ EarliestAllowedTs *time.Time
+ UpdateEarliestAllowedTs bool
// Payload and others cannot be set at the same time.
Payload *string
- SheetID *int `jsonapi:"attr,sheetId"`
+ SheetID *int
SchemaVersion *string
ExportFormat *storepb.ExportFormat
ExportPassword *string
diff --git a/backend/migrator/migration/3.4/0006##created_at2.sql b/backend/migrator/migration/3.4/0006##created_at2.sql
new file mode 100644
index 0000000000..91ac8a7fb7
--- /dev/null
+++ b/backend/migrator/migration/3.4/0006##created_at2.sql
@@ -0,0 +1,93 @@
+ALTER TABLE principal ADD COLUMN created_at TIMESTAMPTZ NOT NULL DEFAULT now();
+UPDATE principal SET created_at = to_timestamp(created_ts);
+ALTER TABLE principal DROP COLUMN created_ts;
+
+ALTER TABLE db ADD COLUMN sync_at TIMESTAMPTZ NOT NULL DEFAULT now();
+UPDATE db SET sync_at = to_timestamp(last_successful_sync_ts) WHERE last_successful_sync_ts > 0;
+ALTER TABLE db DROP COLUMN last_successful_sync_ts;
+
+ALTER TABLE sheet ADD COLUMN created_at TIMESTAMPTZ NOT NULL DEFAULT now();
+UPDATE sheet SET created_at = to_timestamp(created_ts);
+ALTER TABLE sheet DROP COLUMN created_ts;
+
+ALTER TABLE pipeline ADD COLUMN created_at TIMESTAMPTZ NOT NULL DEFAULT now();
+UPDATE pipeline SET created_at = to_timestamp(created_ts);
+ALTER TABLE pipeline DROP COLUMN created_ts;
+
+ALTER TABLE task ADD COLUMN earliest_allowed_at TIMESTAMPTZ NULL;
+UPDATE task SET earliest_allowed_at = to_timestamp(earliest_allowed_ts) WHERE earliest_allowed_ts > 0;
+ALTER TABLE task DROP COLUMN earliest_allowed_ts;
+
+ALTER TABLE task_run ADD COLUMN created_at TIMESTAMPTZ NOT NULL DEFAULT now();
+UPDATE task_run SET created_at = to_timestamp(created_ts);
+ALTER TABLE task_run DROP COLUMN created_ts;
+
+ALTER TABLE task_run ADD COLUMN updated_at TIMESTAMPTZ NOT NULL DEFAULT now();
+UPDATE task_run SET updated_at = to_timestamp(updated_ts);
+ALTER TABLE task_run DROP COLUMN updated_ts;
+
+ALTER TABLE task_run ADD COLUMN started_at TIMESTAMPTZ NULL;
+UPDATE task_run SET started_at = to_timestamp(started_ts) WHERE started_ts > 0;
+ALTER TABLE task_run DROP COLUMN started_ts;
+
+ALTER TABLE plan ADD COLUMN created_at TIMESTAMPTZ NOT NULL DEFAULT now();
+UPDATE plan SET created_at = to_timestamp(created_ts);
+ALTER TABLE plan DROP COLUMN created_ts;
+
+ALTER TABLE plan ADD COLUMN updated_at TIMESTAMPTZ NOT NULL DEFAULT now();
+UPDATE plan SET updated_at = to_timestamp(updated_ts);
+ALTER TABLE plan DROP COLUMN updated_ts;
+
+ALTER TABLE plan_check_run ADD COLUMN created_at TIMESTAMPTZ NOT NULL DEFAULT now();
+UPDATE plan_check_run SET created_at = to_timestamp(created_ts);
+ALTER TABLE plan_check_run DROP COLUMN created_ts;
+
+ALTER TABLE plan_check_run ADD COLUMN updated_at TIMESTAMPTZ NOT NULL DEFAULT now();
+UPDATE plan_check_run SET updated_at = to_timestamp(updated_ts);
+ALTER TABLE plan_check_run DROP COLUMN updated_ts;
+
+ALTER TABLE issue ADD COLUMN created_at TIMESTAMPTZ NOT NULL DEFAULT now();
+UPDATE issue SET created_at = to_timestamp(created_ts);
+ALTER TABLE issue DROP COLUMN created_ts;
+
+ALTER TABLE issue ADD COLUMN updated_at TIMESTAMPTZ NOT NULL DEFAULT now();
+UPDATE issue SET updated_at = to_timestamp(updated_ts);
+ALTER TABLE issue DROP COLUMN updated_ts;
+
+ALTER TABLE audit_log ADD COLUMN created_at TIMESTAMPTZ NOT NULL DEFAULT now();
+UPDATE audit_log SET created_at = to_timestamp(created_ts);
+ALTER TABLE audit_log DROP COLUMN created_ts;
+CREATE INDEX idx_audit_log_created_at ON audit_log(created_at);
+
+ALTER TABLE issue_comment ADD COLUMN created_at TIMESTAMPTZ NOT NULL DEFAULT now();
+UPDATE issue_comment SET created_at = to_timestamp(created_ts);
+ALTER TABLE issue_comment DROP COLUMN created_ts;
+
+ALTER TABLE issue_comment ADD COLUMN updated_at TIMESTAMPTZ NOT NULL DEFAULT now();
+UPDATE issue_comment SET updated_at = to_timestamp(updated_ts);
+ALTER TABLE issue_comment DROP COLUMN updated_ts;
+
+ALTER TABLE query_history ADD COLUMN created_at TIMESTAMPTZ NOT NULL DEFAULT now();
+UPDATE query_history SET created_at = to_timestamp(created_ts);
+ALTER TABLE query_history DROP COLUMN created_ts;
+CREATE INDEX idx_query_history_creator_id_created_at_project_id ON query_history(creator_id, created_at, project_id DESC);
+
+ALTER TABLE anomaly ADD COLUMN updated_at TIMESTAMPTZ NOT NULL DEFAULT now();
+UPDATE anomaly SET updated_at = to_timestamp(updated_ts);
+ALTER TABLE anomaly DROP COLUMN updated_ts;
+
+ALTER TABLE worksheet ADD COLUMN created_at TIMESTAMPTZ NOT NULL DEFAULT now();
+UPDATE worksheet SET created_at = to_timestamp(created_ts);
+ALTER TABLE worksheet DROP COLUMN created_ts;
+
+ALTER TABLE worksheet ADD COLUMN updated_at TIMESTAMPTZ NOT NULL DEFAULT now();
+UPDATE worksheet SET updated_at = to_timestamp(updated_ts);
+ALTER TABLE worksheet DROP COLUMN updated_ts;
+
+ALTER TABLE changelist ADD COLUMN updated_at TIMESTAMPTZ NOT NULL DEFAULT now();
+UPDATE changelist SET updated_at = to_timestamp(updated_ts);
+ALTER TABLE changelist DROP COLUMN updated_ts;
+
+ALTER TABLE export_archive ADD COLUMN created_at TIMESTAMPTZ NOT NULL DEFAULT now();
+UPDATE export_archive SET created_at = to_timestamp(created_ts);
+ALTER TABLE export_archive DROP COLUMN created_ts;
diff --git a/backend/migrator/migration/LATEST.sql b/backend/migrator/migration/LATEST.sql
index a77aa04b19..02f955c45c 100644
--- a/backend/migrator/migration/LATEST.sql
+++ b/backend/migrator/migration/LATEST.sql
@@ -21,7 +21,7 @@ ALTER SEQUENCE idp_id_seq RESTART WITH 101;
CREATE TABLE principal (
id SERIAL PRIMARY KEY,
row_status row_status NOT NULL DEFAULT 'NORMAL',
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
type TEXT NOT NULL CHECK (type IN ('END_USER', 'SYSTEM_BOT', 'SERVICE_ACCOUNT')),
name TEXT NOT NULL,
email TEXT NOT NULL,
@@ -146,7 +146,7 @@ CREATE TABLE db (
project_id INTEGER NOT NULL REFERENCES project (id),
environment TEXT REFERENCES environment (resource_id),
sync_status TEXT NOT NULL CHECK (sync_status IN ('OK', 'NOT_FOUND')),
- last_successful_sync_ts BIGINT NOT NULL,
+ sync_at TIMESTAMPTZ NOT NULL DEFAULT now(),
schema_version TEXT NOT NULL,
name TEXT NOT NULL,
secrets JSONB NOT NULL DEFAULT '{}',
@@ -207,7 +207,7 @@ CREATE TABLE sheet_blob (
CREATE TABLE sheet (
id SERIAL PRIMARY KEY,
creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
project_id INTEGER NOT NULL REFERENCES project (id),
name TEXT NOT NULL,
sha256 BYTEA NOT NULL,
@@ -225,7 +225,7 @@ ALTER SEQUENCE sheet_id_seq RESTART WITH 101;
CREATE TABLE pipeline (
id SERIAL PRIMARY KEY,
creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
project_id INTEGER NOT NULL REFERENCES project (id),
name TEXT NOT NULL
);
@@ -257,15 +257,13 @@ CREATE TABLE task (
status TEXT NOT NULL CHECK (status IN ('PENDING', 'PENDING_APPROVAL', 'RUNNING', 'DONE', 'FAILED', 'CANCELED')),
type TEXT NOT NULL CHECK (type LIKE 'bb.task.%'),
payload JSONB NOT NULL DEFAULT '{}',
- earliest_allowed_ts BIGINT NOT NULL DEFAULT 0
+ earliest_allowed_at TIMESTAMPTZ NULL
);
CREATE INDEX idx_task_pipeline_id_stage_id ON task(pipeline_id, stage_id);
CREATE INDEX idx_task_status ON task(status);
-CREATE INDEX idx_task_earliest_allowed_ts ON task(earliest_allowed_ts);
-
ALTER SEQUENCE task_id_seq RESTART WITH 101;
-- task_dag describes task dependency relationship
@@ -286,14 +284,14 @@ ALTER SEQUENCE task_dag_id_seq RESTART WITH 101;
CREATE TABLE task_run (
id SERIAL PRIMARY KEY,
creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
task_id INTEGER NOT NULL REFERENCES task (id),
sheet_id INTEGER REFERENCES sheet (id),
attempt INTEGER NOT NULL,
name TEXT NOT NULL,
status TEXT NOT NULL CHECK (status IN ('PENDING', 'RUNNING', 'DONE', 'FAILED', 'CANCELED')),
- started_ts BIGINT NOT NULL DEFAULT 0,
+ started_at TIMESTAMPTZ NULL,
code INTEGER NOT NULL DEFAULT 0,
-- result saves the task run result in json format
result JSONB NOT NULL DEFAULT '{}'
@@ -323,8 +321,8 @@ CREATE TABLE plan (
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()),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
project_id INTEGER NOT NULL REFERENCES project (id),
pipeline_id INTEGER REFERENCES pipeline (id),
name TEXT NOT NULL,
@@ -340,8 +338,8 @@ ALTER SEQUENCE plan_id_seq RESTART WITH 101;
CREATE TABLE plan_check_run (
id SERIAL PRIMARY KEY,
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
plan_id BIGINT NOT NULL REFERENCES plan (id),
status TEXT NOT NULL CHECK (status IN ('RUNNING', 'DONE', 'FAILED', 'CANCELED')),
type TEXT NOT NULL CHECK (type LIKE 'bb.plan-check.%'),
@@ -361,8 +359,8 @@ CREATE TABLE issue (
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()),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
project_id INTEGER NOT NULL REFERENCES project (id),
plan_id BIGINT REFERENCES plan (id),
pipeline_id INTEGER REFERENCES pipeline (id),
@@ -386,15 +384,11 @@ CREATE INDEX idx_issue_creator_id ON issue(creator_id);
CREATE INDEX idx_issue_assignee_id ON issue(assignee_id);
-CREATE INDEX idx_issue_created_ts ON issue(created_ts);
-
CREATE INDEX idx_issue_ts_vector ON issue USING GIN(ts_vector);
ALTER SEQUENCE issue_id_seq RESTART WITH 101;
--- stores the issue subscribers. Unlike other tables, it doesn't have row_status/creator_id/created_ts/updater_id/updated_ts.
--- We use a separate table mainly because we can't leverage indexed query if the subscriber id is stored
--- as a comma separated id list in the issue table.
+-- stores the issue subscribers.
CREATE TABLE issue_subscriber (
issue_id INTEGER NOT NULL REFERENCES issue (id),
subscriber_id INTEGER NOT NULL REFERENCES principal (id),
@@ -417,11 +411,11 @@ ALTER SEQUENCE instance_change_history_id_seq RESTART WITH 101;
CREATE TABLE audit_log (
id BIGSERIAL PRIMARY KEY,
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
payload JSONB NOT NULL DEFAULT '{}'
);
-CREATE INDEX idx_audit_log_created_ts ON audit_log(created_ts);
+CREATE INDEX idx_audit_log_created_at ON audit_log(created_at);
CREATE INDEX idx_audit_log_payload_parent ON audit_log((payload->>'parent'));
@@ -436,8 +430,8 @@ ALTER SEQUENCE audit_log_id_seq RESTART WITH 101;
CREATE TABLE issue_comment (
id BIGSERIAL PRIMARY KEY,
creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
issue_id INTEGER NOT NULL REFERENCES issue (id),
payload JSONB NOT NULL DEFAULT '{}'
);
@@ -449,7 +443,7 @@ ALTER SEQUENCE issue_comment_id_seq RESTART WITH 101;
CREATE TABLE query_history (
id BIGSERIAL PRIMARY KEY,
creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
project_id TEXT NOT NULL, -- the project resource id
database TEXT NOT NULL, -- the database resource name, for example, instances/{instance}/databases/{database}
statement TEXT NOT NULL,
@@ -457,7 +451,7 @@ CREATE TABLE query_history (
payload JSONB NOT NULL DEFAULT '{}' -- saved for details, like error, duration, etc.
);
-CREATE INDEX idx_query_history_creator_id_created_ts_project_id ON query_history(creator_id, created_ts, project_id DESC);
+CREATE INDEX idx_query_history_creator_id_created_at_project_id ON query_history(creator_id, created_at, project_id DESC);
ALTER SEQUENCE query_history_id_seq RESTART WITH 101;
@@ -493,7 +487,7 @@ 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,
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
project TEXT NOT NULL,
instance_id INTEGER NOT NULL REFERENCES instance (id),
database_id INTEGER NULL REFERENCES db (id),
@@ -522,8 +516,8 @@ ALTER SEQUENCE deployment_config_id_seq RESTART WITH 101;
CREATE TABLE worksheet (
id SERIAL PRIMARY KEY,
creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
project_id INTEGER NOT NULL REFERENCES project (id),
database_id INTEGER NULL REFERENCES db (id),
name TEXT NOT NULL,
@@ -614,7 +608,7 @@ ALTER SEQUENCE db_group_id_seq RESTART WITH 101;
CREATE TABLE changelist (
id SERIAL PRIMARY KEY,
creator_id INTEGER NOT NULL REFERENCES principal (id),
- updated_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
project_id INTEGER NOT NULL REFERENCES project (id),
name TEXT NOT NULL,
payload JSONB NOT NULL DEFAULT '{}'
@@ -626,7 +620,7 @@ ALTER SEQUENCE changelist_id_seq RESTART WITH 101;
CREATE TABLE export_archive (
id SERIAL PRIMARY KEY,
- created_ts BIGINT NOT NULL DEFAULT extract(epoch from now()),
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
bytes BYTEA,
payload JSONB NOT NULL DEFAULT '{}'
);
diff --git a/backend/migrator/migrator_test.go b/backend/migrator/migrator_test.go
index 5ac987b1ad..1fb46a31cd 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.5"), releaseVersion)
+ require.Equal(t, semver.MustParse("3.4.6"), releaseVersion)
}
diff --git a/backend/runner/schemasync/syncer.go b/backend/runner/schemasync/syncer.go
index e4984fe518..49c43c5ee5 100644
--- a/backend/runner/schemasync/syncer.go
+++ b/backend/runner/schemasync/syncer.go
@@ -409,14 +409,14 @@ func (s *Syncer) SyncDatabaseSchemaToHistory(ctx context.Context, database *stor
}
syncStatus := api.OK
- ts := time.Now().Unix()
+ ts := time.Now()
if _, err := s.store.UpdateDatabase(ctx, &store.UpdateDatabaseMessage{
- InstanceID: database.InstanceID,
- DatabaseName: database.DatabaseName,
- SyncState: &syncStatus,
- SuccessfulSyncTimeTs: &ts,
+ InstanceID: database.InstanceID,
+ DatabaseName: database.DatabaseName,
+ SyncState: &syncStatus,
+ SyncAt: &ts,
MetadataUpsert: &storepb.DatabaseMetadata{
- LastSyncTime: timestamppb.New(time.Unix(ts, 0)),
+ LastSyncTime: timestamppb.New(ts),
BackupAvailable: s.hasBackupSchema(ctx, instance, databaseMetadata),
},
}); err != nil {
@@ -527,14 +527,14 @@ func (s *Syncer) SyncDatabaseSchema(ctx context.Context, database *store.Databas
}
syncStatus := api.OK
- ts := time.Now().Unix()
+ ts := time.Now()
if _, err := s.store.UpdateDatabase(ctx, &store.UpdateDatabaseMessage{
- InstanceID: database.InstanceID,
- DatabaseName: database.DatabaseName,
- SyncState: &syncStatus,
- SuccessfulSyncTimeTs: &ts,
+ InstanceID: database.InstanceID,
+ DatabaseName: database.DatabaseName,
+ SyncState: &syncStatus,
+ SyncAt: &ts,
MetadataUpsert: &storepb.DatabaseMetadata{
- LastSyncTime: timestamppb.New(time.Unix(ts, 0)),
+ LastSyncTime: timestamppb.New(ts),
BackupAvailable: s.hasBackupSchema(ctx, instance, databaseMetadata),
},
}); err != nil {
diff --git a/backend/runner/taskrun/database_create_executor.go b/backend/runner/taskrun/database_create_executor.go
index c3b8341951..9e5900a38f 100644
--- a/backend/runner/taskrun/database_create_executor.go
+++ b/backend/runner/taskrun/database_create_executor.go
@@ -113,12 +113,12 @@ func (exec *DatabaseCreateExecutor) RunOnce(ctx context.Context, driverCtx conte
}
}
database, err := exec.store.UpsertDatabase(ctx, &store.DatabaseMessage{
- ProjectID: project.ResourceID,
- InstanceID: instance.ResourceID,
- DatabaseName: payload.DatabaseName,
- EnvironmentID: payload.EnvironmentId,
- SyncState: api.NotFound,
- SuccessfulSyncTimeTs: time.Now().Unix(),
+ ProjectID: project.ResourceID,
+ InstanceID: instance.ResourceID,
+ DatabaseName: payload.DatabaseName,
+ EnvironmentID: payload.EnvironmentId,
+ SyncState: api.NotFound,
+ SyncAt: time.Now(),
Metadata: &storepb.DatabaseMetadata{
Labels: labels,
},
@@ -320,7 +320,7 @@ func (exec *DatabaseCreateExecutor) reconcilePlan(ctx context.Context, project *
InstanceID: task.InstanceID,
DatabaseID: &createdDatabase.UID,
Type: task.Type,
- EarliestAllowedTs: task.EarliestAllowedTs,
+ EarliestAllowedAt: task.EarliestAllowedAt,
Payload: task.Payload,
}
creates = append(creates, taskCreate)
diff --git a/backend/runner/taskrun/schedulerv2.go b/backend/runner/taskrun/schedulerv2.go
index a8bb096cc0..de6bf6947d 100644
--- a/backend/runner/taskrun/schedulerv2.go
+++ b/backend/runner/taskrun/schedulerv2.go
@@ -306,7 +306,7 @@ func (s *SchedulerV2) schedulePendingTaskRun(ctx context.Context, taskRun *store
if err != nil {
return errors.Wrapf(err, "failed to get task")
}
- if task.EarliestAllowedTs != 0 && time.Now().Before(time.Unix(task.EarliestAllowedTs, 0)) {
+ if task.EarliestAllowedAt != nil && time.Now().Before(*task.EarliestAllowedAt) {
return nil
}
for _, blockingTaskUID := range task.DependsOn {
diff --git a/backend/store/anomaly.go b/backend/store/anomaly.go
index 027f4338c5..6fe72a7e5f 100644
--- a/backend/store/anomaly.go
+++ b/backend/store/anomaly.go
@@ -25,8 +25,8 @@ type AnomalyMessage struct {
//
// UID is the unique identifier of the anomaly.
UID int
- // UpdatedTs is the timestamp when the anomaly is updated.
- UpdatedTs int64
+ // UpdatedAt is the timestamp when the anomaly is updated.
+ UpdatedAt time.Time
}
// ListAnomalyMessage is the message to list anomalies.
@@ -52,11 +52,10 @@ func (s *Store) UpsertActiveAnomalyV2(ctx context.Context, upsert *AnomalyMessag
}
defer tx.Rollback()
- t := time.Now().Unix()
- upsert.UpdatedTs = t
+ upsert.UpdatedAt = time.Now()
query := `
INSERT INTO anomaly (
- updated_ts,
+ updated_at,
project,
instance_id,
database_id,
@@ -64,10 +63,10 @@ func (s *Store) UpsertActiveAnomalyV2(ctx context.Context, upsert *AnomalyMessag
)
VALUES ($1, $2, $3, $4, $5)
ON CONFLICT (project, database_id, type) DO UPDATE SET
- updated_ts = EXCLUDED.updated_ts
+ updated_at = EXCLUDED.updated_at
`
if _, err := tx.ExecContext(ctx, query,
- t,
+ upsert.UpdatedAt,
upsert.ProjectID,
upsert.InstanceUID,
upsert.DatabaseUID,
@@ -142,7 +141,7 @@ func (*Store) listAnomalyImplV2(ctx context.Context, tx *Tx, list *ListAnomalyMe
query := fmt.Sprintf(`
SELECT
anomaly.id,
- anomaly.updated_ts,
+ anomaly.updated_at,
anomaly.instance_id,
anomaly.database_id,
anomaly.type
@@ -170,7 +169,7 @@ func (*Store) listAnomalyImplV2(ctx context.Context, tx *Tx, list *ListAnomalyMe
var databaseID sql.NullInt32
if err := rows.Scan(
&anomaly.UID,
- &anomaly.UpdatedTs,
+ &anomaly.UpdatedAt,
&anomaly.InstanceUID,
&databaseID,
&anomaly.Type,
diff --git a/backend/store/audit_log.go b/backend/store/audit_log.go
index ab82f6a88c..3d793bb868 100644
--- a/backend/store/audit_log.go
+++ b/backend/store/audit_log.go
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"strings"
+ "time"
"google.golang.org/protobuf/encoding/protojson"
@@ -24,7 +25,7 @@ func (m AuditLogMethod) String() string {
type AuditLog struct {
ID int
- CreatedTs int64
+ CreatedAt time.Time
Payload *storepb.AuditLog
}
@@ -71,7 +72,7 @@ func (s *Store) SearchAuditLogs(ctx context.Context, find *AuditLogFind) ([]*Aud
query := fmt.Sprintf(`
SELECT
id,
- created_ts,
+ created_at,
payload
FROM audit_log
WHERE %s`, strings.Join(where, " AND "))
@@ -83,7 +84,7 @@ func (s *Store) SearchAuditLogs(ctx context.Context, find *AuditLogFind) ([]*Aud
}
query += fmt.Sprintf(" ORDER BY %s", strings.Join(orderBy, ", "))
} else {
- query += " ORDER BY created_ts DESC"
+ query += " ORDER BY id DESC"
}
if v := find.Limit; v != nil {
query += fmt.Sprintf(" LIMIT %d", *v)
@@ -107,7 +108,7 @@ func (s *Store) SearchAuditLogs(ctx context.Context, find *AuditLogFind) ([]*Aud
if err := rows.Scan(
&l.ID,
- &l.CreatedTs,
+ &l.CreatedAt,
&payload,
); err != nil {
return nil, errors.Wrapf(err, "failed to scan")
diff --git a/backend/store/changelist.go b/backend/store/changelist.go
index 731e9088c6..9b181fc7db 100644
--- a/backend/store/changelist.go
+++ b/backend/store/changelist.go
@@ -22,9 +22,9 @@ type ChangelistMessage struct {
Payload *storepb.Changelist
// Output only fields
- UID int
- CreatorID int
- UpdatedTime time.Time
+ UID int
+ CreatorID int
+ UpdatedAt time.Time
}
// FindChangelistMessage is the API message for finding changelists.
@@ -77,7 +77,7 @@ func (s *Store) ListChangelists(ctx context.Context, find *FindChangelistMessage
SELECT
changelist.id,
changelist.creator_id,
- changelist.updated_ts,
+ changelist.updated_at,
project.resource_id AS project_id,
changelist.name,
changelist.payload
@@ -94,12 +94,11 @@ func (s *Store) ListChangelists(ctx context.Context, find *FindChangelistMessage
var changelists []*ChangelistMessage
for rows.Next() {
var changelist ChangelistMessage
- var updatedTs int64
var payload []byte
if err := rows.Scan(
&changelist.UID,
&changelist.CreatorID,
- &updatedTs,
+ &changelist.UpdatedAt,
&changelist.ProjectID,
&changelist.ResourceID,
&payload,
@@ -111,7 +110,6 @@ func (s *Store) ListChangelists(ctx context.Context, find *FindChangelistMessage
return nil, err
}
changelist.Payload = changelistPayload
- changelist.UpdatedTime = time.Unix(updatedTs, 0)
changelists = append(changelists, &changelist)
}
@@ -147,7 +145,7 @@ func (s *Store) CreateChangelist(ctx context.Context, create *ChangelistMessage)
payload
)
VALUES ($1, $2, $3, $4)
- RETURNING id, updated_ts;
+ RETURNING id, updated_at;
`
tx, err := s.db.BeginTx(ctx, nil)
@@ -155,7 +153,6 @@ func (s *Store) CreateChangelist(ctx context.Context, create *ChangelistMessage)
return nil, err
}
defer tx.Rollback()
- var updatedTs int64
if err := tx.QueryRowContext(ctx, query,
create.CreatorID,
project.UID,
@@ -163,11 +160,10 @@ func (s *Store) CreateChangelist(ctx context.Context, create *ChangelistMessage)
payload,
).Scan(
&create.UID,
- &updatedTs,
+ &create.UpdatedAt,
); err != nil {
return nil, err
}
- create.UpdatedTime = time.Unix(updatedTs, 0)
if err := tx.Commit(); err != nil {
return nil, err
}
@@ -187,7 +183,7 @@ func (s *Store) UpdateChangelist(ctx context.Context, update *UpdateChangelistMe
return errors.Wrapf(err, "failed to begin transaction")
}
- set, args := []string{"updated_ts = $1"}, []any{time.Now().Unix()}
+ set, args := []string{"updated_at = $1"}, []any{time.Now()}
if v := update.Payload; v != nil {
payload, err := protojson.Marshal(update.Payload)
if err != nil {
diff --git a/backend/store/changelog.go b/backend/store/changelog.go
index 32c69bc9eb..729e962366 100644
--- a/backend/store/changelog.go
+++ b/backend/store/changelog.go
@@ -36,8 +36,8 @@ type ChangelogMessage struct {
Status ChangelogStatus
// output only
- UID int64
- CreatedTime time.Time
+ UID int64
+ CreatedAt time.Time
PrevSchema string
Schema string
@@ -245,7 +245,7 @@ func (s *Store) ListChangelogs(ctx context.Context, find *FindChangelogMessage)
if err := rows.Scan(
&c.UID,
- &c.CreatedTime,
+ &c.CreatedAt,
&c.DatabaseUID,
&c.Status,
&c.PrevSyncHistoryUID,
diff --git a/backend/store/database.go b/backend/store/database.go
index fe60bf2cb7..a1ceb58658 100644
--- a/backend/store/database.go
+++ b/backend/store/database.go
@@ -5,6 +5,7 @@ import (
"database/sql"
"fmt"
"strings"
+ "time"
"github.com/pkg/errors"
"google.golang.org/protobuf/encoding/protojson"
@@ -22,11 +23,11 @@ type DatabaseMessage struct {
EnvironmentID string
EffectiveEnvironmentID string
- DatabaseName string
- SyncState api.SyncStatus
- SuccessfulSyncTimeTs int64
- Secrets *storepb.Secrets
- DataShare bool
+ DatabaseName string
+ SyncState api.SyncStatus
+ SyncAt time.Time
+ Secrets *storepb.Secrets
+ DataShare bool
// ServiceName is the Oracle specific field.
ServiceName string
Metadata *storepb.DatabaseMetadata
@@ -39,15 +40,15 @@ type UpdateDatabaseMessage struct {
InstanceID string
DatabaseName string
- ProjectID *string
- SyncState *api.SyncStatus
- SuccessfulSyncTimeTs *int64
- SourceBackupID *int
- Secrets *storepb.Secrets
- DataShare *bool
- ServiceName *string
- UpdateEnvironmentID bool
- EnvironmentID string
+ ProjectID *string
+ SyncState *api.SyncStatus
+ SyncAt *time.Time
+ SourceBackupID *int
+ Secrets *storepb.Secrets
+ DataShare *bool
+ ServiceName *string
+ UpdateEnvironmentID bool
+ EnvironmentID string
// MetadataUpsert upserts the top-level messages.
MetadataUpsert *storepb.DatabaseMetadata
@@ -187,7 +188,6 @@ func (*Store) createDatabaseDefaultImpl(ctx context.Context, tx *Tx, projectUID,
project_id,
name,
sync_status,
- last_successful_sync_ts,
schema_version,
secrets,
datashare,
@@ -197,7 +197,6 @@ func (*Store) createDatabaseDefaultImpl(ctx context.Context, tx *Tx, projectUID,
ON CONFLICT (instance_id, name) DO UPDATE SET
project_id = EXCLUDED.project_id,
sync_status = EXCLUDED.sync_status,
- last_successful_sync_ts = EXCLUDED.last_successful_sync_ts,
datashare = EXCLUDED.datashare,
service_name = EXCLUDED.service_name
RETURNING id`
@@ -207,7 +206,7 @@ func (*Store) createDatabaseDefaultImpl(ctx context.Context, tx *Tx, projectUID,
projectUID,
create.DatabaseName,
api.OK,
- 0, /* last_successful_sync_ts */
+ nil, /* sync_at */
"", /* schema_version */
secretsString, /* secrets */
create.DataShare,
@@ -263,7 +262,7 @@ func (s *Store) UpsertDatabase(ctx context.Context, create *DatabaseMessage) (*D
environment,
name,
sync_status,
- last_successful_sync_ts,
+ sync_at,
schema_version,
secrets,
datashare,
@@ -285,7 +284,7 @@ func (s *Store) UpsertDatabase(ctx context.Context, create *DatabaseMessage) (*D
environment,
create.DatabaseName,
create.SyncState,
- create.SuccessfulSyncTimeTs,
+ create.SyncAt,
secretsString,
create.DataShare,
create.ServiceName,
@@ -330,8 +329,8 @@ func (s *Store) UpdateDatabase(ctx context.Context, patch *UpdateDatabaseMessage
if v := patch.SyncState; v != nil {
set, args = append(set, fmt.Sprintf("sync_status = $%d", len(args)+1)), append(args, *v)
}
- if v := patch.SuccessfulSyncTimeTs; v != nil {
- set, args = append(set, fmt.Sprintf("last_successful_sync_ts = $%d", len(args)+1)), append(args, *v)
+ if v := patch.SyncAt; v != nil {
+ set, args = append(set, fmt.Sprintf("sync_at = $%d", len(args)+1)), append(args, *v)
}
if v := patch.Secrets; v != nil {
secretsString, err := protojson.Marshal(v)
@@ -495,7 +494,7 @@ func (*Store) listDatabaseImplV2(ctx context.Context, tx *Tx, find *FindDatabase
instance.resource_id AS instance_id,
db.name,
db.sync_status,
- db.last_successful_sync_ts,
+ db.sync_at,
COALESCE(
(
SELECT revision.version
@@ -543,7 +542,7 @@ func (*Store) listDatabaseImplV2(ctx context.Context, tx *Tx, find *FindDatabase
&databaseMessage.InstanceID,
&databaseMessage.DatabaseName,
&databaseMessage.SyncState,
- &databaseMessage.SuccessfulSyncTimeTs,
+ &databaseMessage.SyncAt,
&databaseMessage.SchemaVersion,
&secretsString,
&databaseMessage.DataShare,
diff --git a/backend/store/export_archive.go b/backend/store/export_archive.go
index 2f1416b6d5..fd081cd659 100644
--- a/backend/store/export_archive.go
+++ b/backend/store/export_archive.go
@@ -5,7 +5,6 @@ import (
"database/sql"
"fmt"
"strings"
- "time"
"github.com/pkg/errors"
"google.golang.org/protobuf/encoding/protojson"
@@ -15,10 +14,9 @@ import (
)
type ExportArchiveMessage struct {
- UID int
- CreatedTime time.Time
- Bytes []byte
- Payload *storepb.ExportArchivePayload
+ UID int
+ Bytes []byte
+ Payload *storepb.ExportArchivePayload
}
// FindExportArchiveMessage is the API message for finding export archives.
@@ -58,7 +56,6 @@ func (s *Store) ListExportArchives(ctx context.Context, find *FindExportArchiveM
query := fmt.Sprintf(`
SELECT
id,
- created_ts,
bytes,
payload
FROM export_archive
@@ -74,11 +71,9 @@ func (s *Store) ListExportArchives(ctx context.Context, find *FindExportArchiveM
var exportArchives []*ExportArchiveMessage
for rows.Next() {
var exportArchive ExportArchiveMessage
- var createdTs int64
var bytes, payload []byte
if err := rows.Scan(
&exportArchive.UID,
- &createdTs,
&bytes,
&payload,
); err != nil {
@@ -115,7 +110,7 @@ func (s *Store) CreateExportArchive(ctx context.Context, create *ExportArchiveMe
payload
)
VALUES ($1, $2)
- RETURNING id, created_ts;
+ RETURNING id;
`
tx, err := s.db.BeginTx(ctx, nil)
@@ -123,17 +118,14 @@ func (s *Store) CreateExportArchive(ctx context.Context, create *ExportArchiveMe
return nil, err
}
defer tx.Rollback()
- var createdTs int64
if err := tx.QueryRowContext(ctx, query,
create.Bytes,
payload,
).Scan(
&create.UID,
- &createdTs,
); err != nil {
return nil, err
}
- create.CreatedTime = time.Unix(createdTs, 0)
if err := tx.Commit(); err != nil {
return nil, err
}
diff --git a/backend/store/issue.go b/backend/store/issue.go
index e8afbd555f..9a79a4134f 100644
--- a/backend/store/issue.go
+++ b/backend/store/issue.go
@@ -46,17 +46,15 @@ type IssueMessage struct {
TaskStatusCount map[string]int32
// The following fields are output only and not used for create().
- UID int
- Creator *UserMessage
- CreatedTime time.Time
- UpdatedTime time.Time
+ UID int
+ Creator *UserMessage
+ CreatedAt time.Time
+ UpdatedAt time.Time
// Internal fields.
projectUID int
subscriberUIDs []int
creatorUID int
- createdTs int64
- updatedTs int64
}
// UpdateIssueMessage is the message for updating an issue.
@@ -83,8 +81,8 @@ type FindIssueMessage struct {
// Only principleID or one of the following three fields can be set.
CreatorID *int
SubscriberID *int
- CreatedTsBefore *int64
- CreatedTsAfter *int64
+ CreatedAtBefore *time.Time
+ CreatedAtAfter *time.Time
Types *[]api.IssueType
StatusList []api.IssueStatus
@@ -164,7 +162,7 @@ func (s *Store) CreateIssueV2(ctx context.Context, create *IssueMessage, creator
ts_vector
)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
- RETURNING id, created_ts, updated_ts
+ RETURNING id, created_at, updated_at
`
tx, err := s.db.BeginTx(ctx, nil)
@@ -186,16 +184,14 @@ func (s *Store) CreateIssueV2(ctx context.Context, create *IssueMessage, creator
tsVector,
).Scan(
&create.UID,
- &create.createdTs,
- &create.updatedTs,
+ &create.CreatedAt,
+ &create.UpdatedAt,
); err != nil {
if err == sql.ErrNoRows {
return nil, common.FormatDBErrorEmptyRowWithQuery(query)
}
return nil, err
}
- create.CreatedTime = time.Unix(create.createdTs, 0)
- create.UpdatedTime = time.Unix(create.updatedTs, 0)
create.Creator = creator
if err := tx.Commit(); err != nil {
@@ -216,7 +212,7 @@ func (s *Store) UpdateIssueV2(ctx context.Context, uid int, patch *UpdateIssueMe
return nil, err
}
- set, args := []string{"updated_ts = $1"}, []any{time.Now().Unix()}
+ set, args := []string{"updated_at = $1"}, []any{time.Now()}
if v := patch.PipelineUID; v != nil {
set, args = append(set, fmt.Sprintf("pipeline_id = $%d", len(args)+1)), append(args, *v)
}
@@ -389,11 +385,11 @@ func (s *Store) ListIssueV2(ctx context.Context, find *FindIssueMessage) ([]*Iss
if v := find.CreatorID; v != nil {
where, args = append(where, fmt.Sprintf("issue.creator_id = $%d", len(args)+1)), append(args, *v)
}
- if v := find.CreatedTsBefore; v != nil {
- where, args = append(where, fmt.Sprintf("issue.created_ts < $%d", len(args)+1)), append(args, *v)
+ if v := find.CreatedAtBefore; v != nil {
+ where, args = append(where, fmt.Sprintf("issue.created_at < $%d", len(args)+1)), append(args, *v)
}
- if v := find.CreatedTsAfter; v != nil {
- where, args = append(where, fmt.Sprintf("issue.created_ts > $%d", len(args)+1)), append(args, *v)
+ if v := find.CreatedAtAfter; v != nil {
+ where, args = append(where, fmt.Sprintf("issue.created_at > $%d", len(args)+1)), append(args, *v)
}
if v := find.SubscriberID; v != nil {
where, args = append(where, fmt.Sprintf("EXISTS (SELECT 1 FROM issue_subscriber WHERE issue_subscriber.issue_id = issue.id AND issue_subscriber.subscriber_id = $%d)", len(args)+1)), append(args, *v)
@@ -448,8 +444,8 @@ func (s *Store) ListIssueV2(ctx context.Context, find *FindIssueMessage) ([]*Iss
SELECT
issue.id,
issue.creator_id,
- issue.created_ts,
- issue.updated_ts,
+ issue.created_at,
+ issue.updated_at,
issue.project_id,
issue.pipeline_id,
issue.plan_id,
@@ -505,8 +501,8 @@ func (s *Store) ListIssueV2(ctx context.Context, find *FindIssueMessage) ([]*Iss
if err := rows.Scan(
&issue.UID,
&issue.creatorUID,
- &issue.createdTs,
- &issue.updatedTs,
+ &issue.CreatedAt,
+ &issue.UpdatedAt,
&issue.projectUID,
&issue.PipelineUID,
&issue.PlanUID,
@@ -558,8 +554,6 @@ func (s *Store) ListIssueV2(ctx context.Context, find *FindIssueMessage) ([]*Iss
}
issue.Subscribers = append(issue.Subscribers, subscriber)
}
- issue.CreatedTime = time.Unix(issue.createdTs, 0)
- issue.UpdatedTime = time.Unix(issue.updatedTs, 0)
s.issueCache.Add(issue.UID, issue)
if issue.PipelineUID != nil {
diff --git a/backend/store/issue_comment.go b/backend/store/issue_comment.go
index 1992268936..830b347901 100644
--- a/backend/store/issue_comment.go
+++ b/backend/store/issue_comment.go
@@ -15,8 +15,8 @@ import (
type IssueCommentMessage struct {
UID int
- CreatedTs int64
- UpdatedTs int64
+ CreatedAt time.Time
+ UpdatedAt time.Time
IssueUID int
Payload *storepb.IssueCommentPayload
Creator *UserMessage
@@ -76,8 +76,8 @@ func (s *Store) ListIssueComment(ctx context.Context, find *FindIssueCommentMess
SELECT
id,
creator_id,
- created_ts,
- updated_ts,
+ created_at,
+ updated_at,
issue_id,
payload
FROM
@@ -100,8 +100,8 @@ func (s *Store) ListIssueComment(ctx context.Context, find *FindIssueCommentMess
if err := rows.Scan(
&ic.UID,
&ic.creatorUID,
- &ic.CreatedTs,
- &ic.UpdatedTs,
+ &ic.CreatedAt,
+ &ic.UpdatedAt,
&ic.IssueUID,
&p,
); err != nil {
@@ -156,7 +156,7 @@ func (s *Store) CreateIssueComment(ctx context.Context, create *IssueCommentMess
$1,
$2,
$3
- ) RETURNING id, created_ts, updated_ts
+ ) RETURNING id, created_at, updated_at
`
payload, err := protojson.Marshal(create.Payload)
@@ -164,32 +164,21 @@ func (s *Store) CreateIssueComment(ctx context.Context, create *IssueCommentMess
return nil, errors.Wrapf(err, "failed to marshal payload")
}
- var id int
- var createdTs, updatedTs int64
- if err := s.db.db.QueryRowContext(ctx, query, creatorUID, create.IssueUID, payload).Scan(&id, &createdTs, &updatedTs); err != nil {
+ if err := s.db.db.QueryRowContext(ctx, query, creatorUID, create.IssueUID, payload).Scan(&create.UID, &create.CreatedAt, &create.UpdatedAt); err != nil {
return nil, errors.Wrapf(err, "failed to insert")
}
- ic := &IssueCommentMessage{
- UID: id,
- CreatedTs: createdTs,
- UpdatedTs: updatedTs,
- IssueUID: create.IssueUID,
- Payload: create.Payload,
- creatorUID: creatorUID,
- }
-
- creator, err := s.GetUserByID(ctx, ic.creatorUID)
+ creator, err := s.GetUserByID(ctx, create.creatorUID)
if err != nil {
return nil, errors.Wrapf(err, "failed to get creator")
}
- ic.Creator = creator
+ create.Creator = creator
- return ic, nil
+ return create, nil
}
func (s *Store) UpdateIssueComment(ctx context.Context, patch *UpdateIssueCommentMessage) error {
- set, args := []string{"updated_ts = $2"}, []any{time.Now().Unix()}
+ set, args := []string{"updated_at = $2"}, []any{time.Now()}
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/pipeline.go b/backend/store/pipeline.go
index c7f361c2c7..93297da5d1 100644
--- a/backend/store/pipeline.go
+++ b/backend/store/pipeline.go
@@ -5,6 +5,7 @@ import (
"database/sql"
"fmt"
"strings"
+ "time"
"github.com/pkg/errors"
@@ -19,7 +20,7 @@ type PipelineMessage struct {
// Output only.
ID int
CreatorUID int
- CreatedTs int64
+ CreatedAt time.Time
IssueID *int
}
@@ -173,7 +174,7 @@ func (*Store) createPipeline(ctx context.Context, tx *Tx, create *PipelineMessag
$2,
$3
)
- RETURNING id, created_ts
+ RETURNING id, created_at
`
pipeline := &PipelineMessage{
ProjectID: create.ProjectID,
@@ -186,7 +187,7 @@ func (*Store) createPipeline(ctx context.Context, tx *Tx, create *PipelineMessag
create.Name,
).Scan(
&pipeline.ID,
- &pipeline.CreatedTs,
+ &pipeline.CreatedAt,
); err != nil {
if err == sql.ErrNoRows {
return nil, common.FormatDBErrorEmptyRowWithQuery(query)
@@ -229,7 +230,7 @@ func (s *Store) ListPipelineV2(ctx context.Context, find *PipelineFind) ([]*Pipe
SELECT
pipeline.id,
pipeline.creator_id,
- pipeline.created_ts,
+ pipeline.created_at,
project.resource_id,
pipeline.name,
issue.id
@@ -263,7 +264,7 @@ func (s *Store) ListPipelineV2(ctx context.Context, find *PipelineFind) ([]*Pipe
if err := rows.Scan(
&pipeline.ID,
&pipeline.CreatorUID,
- &pipeline.CreatedTs,
+ &pipeline.CreatedAt,
&pipeline.ProjectID,
&pipeline.Name,
&pipeline.IssueID,
diff --git a/backend/store/plan.go b/backend/store/plan.go
index 7e9505a238..e5886fd3c0 100644
--- a/backend/store/plan.go
+++ b/backend/store/plan.go
@@ -25,8 +25,8 @@ type PlanMessage struct {
// output only
UID int64
CreatorUID int
- CreatedTs int64
- UpdatedTs int64
+ CreatedAt time.Time
+ UpdatedAt time.Time
PlanCheckRunStatusCount map[string]int32
}
@@ -38,8 +38,8 @@ type FindPlanMessage struct {
ProjectIDs *[]string
CreatorID *int
PipelineID *int
- CreatedTsBefore *int64
- CreatedTsAfter *int64
+ CreatedAtBefore *time.Time
+ CreatedAtAfter *time.Time
Limit *int
Offset *int
@@ -74,7 +74,7 @@ func (s *Store) CreatePlan(ctx context.Context, plan *PlanMessage, creatorUID in
$4,
$5,
$6
- ) RETURNING id, created_ts
+ ) RETURNING id, created_at, updated_at
`
config, err := protojson.Marshal(plan.Config)
@@ -87,7 +87,7 @@ func (s *Store) CreatePlan(ctx context.Context, plan *PlanMessage, creatorUID in
}
defer tx.Rollback()
- var id, createdTs int64
+ var id int64
if err := tx.QueryRowContext(ctx, query,
creatorUID,
plan.ProjectID,
@@ -95,7 +95,7 @@ func (s *Store) CreatePlan(ctx context.Context, plan *PlanMessage, creatorUID in
plan.Name,
plan.Description,
config,
- ).Scan(&id, &createdTs); err != nil {
+ ).Scan(&id, &plan.CreatedAt, &plan.UpdatedAt); err != nil {
return nil, errors.Wrap(err, "failed to insert plan")
}
@@ -105,8 +105,6 @@ func (s *Store) CreatePlan(ctx context.Context, plan *PlanMessage, creatorUID in
plan.UID = id
plan.CreatorUID = creatorUID
- plan.CreatedTs = createdTs
- plan.UpdatedTs = createdTs
return plan, nil
}
@@ -143,11 +141,11 @@ func (s *Store) ListPlans(ctx context.Context, find *FindPlanMessage) ([]*PlanMe
if v := find.CreatorID; v != nil {
where, args = append(where, fmt.Sprintf("plan.creator_id = $%d", len(args)+1)), append(args, *v)
}
- if v := find.CreatedTsBefore; v != nil {
- where, args = append(where, fmt.Sprintf("plan.created_ts < $%d", len(args)+1)), append(args, *v)
+ if v := find.CreatedAtBefore; v != nil {
+ where, args = append(where, fmt.Sprintf("plan.created_at < $%d", len(args)+1)), append(args, *v)
}
- if v := find.CreatedTsAfter; v != nil {
- where, args = append(where, fmt.Sprintf("plan.created_ts > $%d", len(args)+1)), append(args, *v)
+ if v := find.CreatedAtAfter; v != nil {
+ where, args = append(where, fmt.Sprintf("plan.created_at > $%d", len(args)+1)), append(args, *v)
}
if v := find.NoIssue; v {
where = append(where, "issue.id IS NULL")
@@ -160,8 +158,8 @@ func (s *Store) ListPlans(ctx context.Context, find *FindPlanMessage) ([]*PlanMe
SELECT
plan.id,
plan.creator_id,
- plan.created_ts,
- plan.updated_ts,
+ plan.created_at,
+ plan.updated_at,
project.resource_id,
plan.pipeline_id,
plan.name,
@@ -219,8 +217,8 @@ func (s *Store) ListPlans(ctx context.Context, find *FindPlanMessage) ([]*PlanMe
if err := rows.Scan(
&plan.UID,
&plan.CreatorUID,
- &plan.CreatedTs,
- &plan.UpdatedTs,
+ &plan.CreatedAt,
+ &plan.UpdatedAt,
&plan.ProjectID,
&plan.PipelineUID,
&plan.Name,
@@ -251,7 +249,7 @@ func (s *Store) ListPlans(ctx context.Context, find *FindPlanMessage) ([]*PlanMe
// UpdatePlan updates an existing plan.
func (s *Store) UpdatePlan(ctx context.Context, patch *UpdatePlanMessage) error {
- set, args := []string{"updated_ts = $1"}, []any{time.Now().Unix()}
+ set, args := []string{"updated_at = $1"}, []any{time.Now()}
if v := patch.Name; v != nil {
set, args = append(set, fmt.Sprintf("name = $%d", len(args)+1)), append(args, *v)
}
diff --git a/backend/store/plan_check_run.go b/backend/store/plan_check_run.go
index cea4a20747..33be67b779 100644
--- a/backend/store/plan_check_run.go
+++ b/backend/store/plan_check_run.go
@@ -48,8 +48,8 @@ const (
// PlanCheckRunMessage is the message for a plan check run.
type PlanCheckRunMessage struct {
UID int
- CreatedTs int64
- UpdatedTs int64
+ CreatedAt time.Time
+ UpdatedAt time.Time
PlanUID int64
@@ -147,8 +147,8 @@ func (s *Store) ListPlanCheckRuns(ctx context.Context, find *FindPlanCheckRunMes
SELECT
%s
plan_check_run.id,
- plan_check_run.created_ts,
- plan_check_run.updated_ts,
+ plan_check_run.created_at,
+ plan_check_run.updated_at,
plan_check_run.plan_id,
plan_check_run.status,
plan_check_run.type,
@@ -172,8 +172,8 @@ WHERE %s
var config, result string
if err := rows.Scan(
&planCheckRun.UID,
- &planCheckRun.CreatedTs,
- &planCheckRun.UpdatedTs,
+ &planCheckRun.CreatedAt,
+ &planCheckRun.UpdatedAt,
&planCheckRun.PlanUID,
&planCheckRun.Status,
&planCheckRun.Type,
@@ -207,11 +207,11 @@ func (s *Store) UpdatePlanCheckRun(ctx context.Context, status PlanCheckRunStatu
query := `
UPDATE plan_check_run
SET
- updated_ts = $1,
+ updated_at = $1,
status = $2,
result = $3
WHERE id = $4`
- if _, err := s.db.db.ExecContext(ctx, query, time.Now().Unix(), status, resultBytes, uid); err != nil {
+ if _, err := s.db.db.ExecContext(ctx, query, time.Now(), status, resultBytes, uid); err != nil {
return errors.Wrapf(err, "failed to update plan check run")
}
return nil
@@ -223,9 +223,9 @@ func (s *Store) BatchCancelPlanCheckRuns(ctx context.Context, planCheckRunUIDs [
UPDATE plan_check_run
SET
status = $1,
- updated_ts = $2
+ updated_at = $2
WHERE id = ANY($3)`
- if _, err := s.db.db.ExecContext(ctx, query, PlanCheckRunStatusCanceled, time.Now().Unix(), planCheckRunUIDs); err != nil {
+ if _, err := s.db.db.ExecContext(ctx, query, PlanCheckRunStatusCanceled, time.Now(), planCheckRunUIDs); err != nil {
return err
}
return nil
diff --git a/backend/store/policy.go b/backend/store/policy.go
index c11f08a5e6..a4d2d2c71e 100644
--- a/backend/store/policy.go
+++ b/backend/store/policy.go
@@ -123,7 +123,7 @@ func (s *Store) getIamPolicy(ctx context.Context, find *FindPolicyMessage) (*Iam
return &IamPolicyMessage{
Policy: p,
- Etag: generateEtag(policy.UpdatedTime),
+ Etag: generateEtag(policy.UpdatedAt),
}, nil
}
@@ -334,8 +334,8 @@ type PolicyMessage struct {
Enforce bool
// Output only.
- UID int
- UpdatedTime time.Time
+ UID int
+ UpdatedAt time.Time
}
// FindPolicyMessage is the message for finding policies.
@@ -489,7 +489,7 @@ func (s *Store) UpdatePolicyV2(ctx context.Context, patch *UpdatePolicyMessage)
&policy.Payload,
&policy.InheritFromParent,
&rowStatus,
- &policy.UpdatedTime,
+ &policy.UpdatedAt,
); err != nil {
if err == sql.ErrNoRows {
return nil, nil
@@ -567,7 +567,7 @@ func upsertPolicyV2Impl(ctx context.Context, tx *Tx, create *PolicyMessage) (*Po
rowStatus,
).Scan(
&uid,
- &create.UpdatedTime,
+ &create.UpdatedAt,
); err != nil {
return nil, err
}
@@ -616,7 +616,7 @@ func (*Store) listPolicyImplV2(ctx context.Context, tx *Tx, find *FindPolicyMess
if err := rows.Scan(
&policyMessage.UID,
- &policyMessage.UpdatedTime,
+ &policyMessage.UpdatedAt,
&policyMessage.ResourceType,
&policyMessage.ResourceUID,
&policyMessage.InheritFromParent,
diff --git a/backend/store/principal.go b/backend/store/principal.go
index d814976d11..505115cc15 100644
--- a/backend/store/principal.go
+++ b/backend/store/principal.go
@@ -58,7 +58,7 @@ type UserMessage struct {
// Phone conforms E.164 format.
Phone string
// output only
- CreatedTime time.Time
+ CreatedAt time.Time
}
// GetSystemBotUser gets the system bot.
@@ -180,7 +180,7 @@ func listUserImpl(ctx context.Context, tx *Tx, find *FindUserMessage) ([]*UserMe
principal.mfa_config,
principal.phone,
principal.profile,
- principal.created_ts
+ principal.created_at
FROM principal
WHERE ` + strings.Join(where, " AND ")
@@ -199,7 +199,6 @@ func listUserImpl(ctx context.Context, tx *Tx, find *FindUserMessage) ([]*UserMe
var rowStatus string
var mfaConfigBytes []byte
var profileBytes []byte
- var createdTs int64
if err := rows.Scan(
&userMessage.ID,
&rowStatus,
@@ -210,7 +209,7 @@ func listUserImpl(ctx context.Context, tx *Tx, find *FindUserMessage) ([]*UserMe
&mfaConfigBytes,
&userMessage.Phone,
&profileBytes,
- &createdTs,
+ &userMessage.CreatedAt,
); err != nil {
return nil, err
}
@@ -226,7 +225,6 @@ func listUserImpl(ctx context.Context, tx *Tx, find *FindUserMessage) ([]*UserMe
return nil, err
}
userMessage.Profile = &profile
- userMessage.CreatedTime = time.Unix(createdTs, 0)
userMessages = append(userMessages, &userMessage)
}
@@ -267,16 +265,15 @@ func (s *Store) CreateUser(ctx context.Context, create *UserMessage) (*UserMessa
}
var userID int
- var createdTs int64
if err := tx.QueryRowContext(ctx, fmt.Sprintf(`
INSERT INTO principal (
%s
)
VALUES (%s)
- RETURNING id, created_ts
+ RETURNING id, created_at
`, strings.Join(set, ","), strings.Join(placeholder, ",")),
args...,
- ).Scan(&userID, &createdTs); err != nil {
+ ).Scan(&userID, &create.CreatedAt); err != nil {
return nil, err
}
@@ -291,7 +288,7 @@ func (s *Store) CreateUser(ctx context.Context, create *UserMessage) (*UserMessa
Type: create.Type,
PasswordHash: create.PasswordHash,
Phone: create.Phone,
- CreatedTime: time.Unix(createdTs, 0),
+ CreatedAt: create.CreatedAt,
Profile: create.Profile,
MFAConfig: &storepb.MFAConfig{},
}
diff --git a/backend/store/query_history.go b/backend/store/query_history.go
index d8ff3b345d..8bc535ee60 100644
--- a/backend/store/query_history.go
+++ b/backend/store/query_history.go
@@ -26,8 +26,8 @@ const (
// QueryHistoryMessage is the API message for query history.
type QueryHistoryMessage struct {
// Output only fields
- UID int
- CreatedTime time.Time
+ UID int
+ CreatedAt time.Time
// Related fields
CreatorUID int
@@ -40,8 +40,6 @@ type QueryHistoryMessage struct {
Payload *storepb.QueryHistoryPayload
// Database is the database resource name, like instances/{instance}/databases/{database}
Database string
-
- createdTs int64
}
// FindQueryHistoryMessage is the API message for finding query histories.
@@ -83,7 +81,7 @@ func (s *Store) CreateQueryHistory(ctx context.Context, create *QueryHistoryMess
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING
id,
- created_ts
+ created_at
`,
create.CreatorUID,
create.ProjectID,
@@ -93,7 +91,7 @@ func (s *Store) CreateQueryHistory(ctx context.Context, create *QueryHistoryMess
payload,
).Scan(
&create.UID,
- &create.createdTs,
+ &create.CreatedAt,
); err != nil {
return nil, err
}
@@ -101,8 +99,6 @@ func (s *Store) CreateQueryHistory(ctx context.Context, create *QueryHistoryMess
return nil, errors.Wrapf(err, "failed to commit transaction")
}
- create.CreatedTime = time.Unix(create.createdTs, 0)
-
return create, nil
}
@@ -135,7 +131,7 @@ func (s *Store) ListQueryHistories(ctx context.Context, find *FindQueryHistoryMe
SELECT
query_history.id,
query_history.creator_id,
- query_history.created_ts,
+ query_history.created_at,
query_history.project_id,
query_history.database,
query_history.statement,
@@ -143,7 +139,7 @@ func (s *Store) ListQueryHistories(ctx context.Context, find *FindQueryHistoryMe
query_history.payload
FROM query_history
WHERE %s
- ORDER BY created_ts DESC
+ ORDER BY id DESC
`, strings.Join(where, " AND "))
if v := find.Limit; v != nil {
query += fmt.Sprintf(" LIMIT %d", *v)
@@ -165,7 +161,7 @@ func (s *Store) ListQueryHistories(ctx context.Context, find *FindQueryHistoryMe
if err := rows.Scan(
&queryHistory.UID,
&queryHistory.CreatorUID,
- &queryHistory.createdTs,
+ &queryHistory.CreatedAt,
&queryHistory.ProjectID,
&queryHistory.Database,
&queryHistory.Statement,
@@ -180,7 +176,6 @@ func (s *Store) ListQueryHistories(ctx context.Context, find *FindQueryHistoryMe
return nil, err
}
queryHistory.Payload = &payload
- queryHistory.CreatedTime = time.Unix(queryHistory.createdTs, 0)
queryHistories = append(queryHistories, queryHistory)
}
diff --git a/backend/store/release.go b/backend/store/release.go
index 297d76d038..a354b82c7e 100644
--- a/backend/store/release.go
+++ b/backend/store/release.go
@@ -20,10 +20,10 @@ type ReleaseMessage struct {
Payload *storepb.ReleasePayload
// output only
- UID int64
- Deleted bool
- CreatorUID int
- CreatedTime time.Time
+ UID int64
+ Deleted bool
+ CreatorUID int
+ At time.Time
}
type FindReleaseMessage struct {
@@ -81,7 +81,7 @@ func (s *Store) CreateRelease(ctx context.Context, release *ReleaseMessage, crea
release.UID = id
release.CreatorUID = creatorUID
- release.CreatedTime = createdTime
+ release.At = createdTime
return release, nil
}
@@ -159,7 +159,7 @@ func (s *Store) ListReleases(ctx context.Context, find *FindReleaseMessage) ([]*
&rowStatus,
&r.ProjectUID,
&r.CreatorUID,
- &r.CreatedTime,
+ &r.At,
&payload,
); err != nil {
return nil, errors.Wrapf(err, "failed to scan rows")
diff --git a/backend/store/revision.go b/backend/store/revision.go
index 3b6f12636a..6db90081cf 100644
--- a/backend/store/revision.go
+++ b/backend/store/revision.go
@@ -21,9 +21,9 @@ type RevisionMessage struct {
// output only
UID int64
- CreateTime time.Time
+ CreatedAt time.Time
DeleterUID *int
- DeleteTime *time.Time
+ DeletedAt *time.Time
}
type FindRevisionMessage struct {
@@ -101,9 +101,9 @@ func (s *Store) ListRevisions(ctx context.Context, find *FindRevisionMessage) ([
if err := rows.Scan(
&r.UID,
&r.DatabaseUID,
- &r.CreateTime,
+ &r.CreatedAt,
&r.DeleterUID,
- &r.DeleteTime,
+ &r.DeletedAt,
&r.Version,
&p,
); err != nil {
@@ -168,12 +168,11 @@ func (s *Store) CreateRevision(ctx context.Context, revision *RevisionMessage) (
defer tx.Rollback()
var id int64
- var createTime time.Time
if err := tx.QueryRowContext(ctx, query,
revision.DatabaseUID,
revision.Version,
p,
- ).Scan(&id, &createTime); err != nil {
+ ).Scan(&id, &revision.CreatedAt); err != nil {
return nil, errors.Wrapf(err, "failed to query and scan")
}
@@ -182,7 +181,6 @@ func (s *Store) CreateRevision(ctx context.Context, revision *RevisionMessage) (
}
revision.UID = id
- revision.CreateTime = createTime
return revision, nil
}
diff --git a/backend/store/sheet.go b/backend/store/sheet.go
index f2e693a76d..3c439be8be 100644
--- a/backend/store/sheet.go
+++ b/backend/store/sheet.go
@@ -30,12 +30,9 @@ type SheetMessage struct {
Sha256 []byte
// Output only fields
- UID int
- Size int64
- CreatedTime time.Time
-
- // Internal fields
- createdTs int64
+ UID int
+ Size int64
+ CreatedAt time.Time
}
func (s *SheetMessage) GetSha256Hex() string {
@@ -145,7 +142,7 @@ func (s *Store) listSheets(ctx context.Context, find *FindSheetMessage) ([]*Shee
SELECT
sheet.id,
sheet.creator_id,
- sheet.created_ts,
+ sheet.created_at,
sheet.project_id,
sheet.name,
%s,
@@ -169,7 +166,7 @@ func (s *Store) listSheets(ctx context.Context, find *FindSheetMessage) ([]*Shee
if err := rows.Scan(
&sheet.UID,
&sheet.CreatorID,
- &sheet.createdTs,
+ &sheet.CreatedAt,
&sheet.ProjectUID,
&sheet.Title,
&sheet.Statement,
@@ -194,10 +191,6 @@ func (s *Store) listSheets(ctx context.Context, find *FindSheetMessage) ([]*Shee
return nil, err
}
- for _, sheet := range sheets {
- sheet.CreatedTime = time.Unix(sheet.createdTs, 0)
- }
-
return sheets, nil
}
@@ -229,7 +222,7 @@ func (s *Store) CreateSheet(ctx context.Context, create *SheetMessage) (*SheetMe
payload
)
VALUES ($1, $2, $3, $4, $5)
- RETURNING id, created_ts
+ RETURNING id, created_at
`
tx, err := s.db.BeginTx(ctx, nil)
@@ -245,7 +238,7 @@ func (s *Store) CreateSheet(ctx context.Context, create *SheetMessage) (*SheetMe
payload,
).Scan(
&create.UID,
- &create.createdTs,
+ &create.CreatedAt,
); err != nil {
if err == sql.ErrNoRows {
return nil, common.FormatDBErrorEmptyRowWithQuery(query)
@@ -257,7 +250,6 @@ func (s *Store) CreateSheet(ctx context.Context, create *SheetMessage) (*SheetMe
}
create.Size = int64(len(create.Statement))
- create.CreatedTime = time.Unix(create.createdTs, 0)
return create, nil
}
@@ -304,7 +296,7 @@ func (s *Store) BatchCreateSheet(ctx context.Context, projectUID int, creates []
unnest(CAST($3 AS TEXT[])),
unnest(CAST($4 AS BYTEA[])),
unnest(CAST($5 AS JSONB[]))
- RETURNING id, created_ts
+ RETURNING id, created_at
`
tx, err := s.db.BeginTx(ctx, nil)
@@ -324,13 +316,12 @@ func (s *Store) BatchCreateSheet(ctx context.Context, projectUID int, creates []
if err := rows.Scan(
&creates[i].UID,
- &creates[i].createdTs,
+ &creates[i].CreatedAt,
); err != nil {
return nil, errors.Wrapf(err, "failed to scan")
}
creates[i].Size = int64(len(creates[i].Statement))
- creates[i].CreatedTime = time.Unix(creates[i].createdTs, 0)
}
if err := rows.Err(); err != nil {
diff --git a/backend/store/sync_history.go b/backend/store/sync_history.go
index 9892c3235f..161d09a02c 100644
--- a/backend/store/sync_history.go
+++ b/backend/store/sync_history.go
@@ -18,7 +18,7 @@ type SyncHistory struct {
Schema string
Metadata *storepb.DatabaseSchemaMetadata
- CreateTime time.Time
+ CreatedAt time.Time
}
func (s *Store) GetSyncHistoryByUID(ctx context.Context, uid int64) (*SyncHistory, error) {
@@ -39,7 +39,7 @@ 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.CreateTime,
+ &h.CreatedAt,
&h.DatabaseUID,
&m,
&h.Schema,
diff --git a/backend/store/task.go b/backend/store/task.go
index bde4ccc985..f418cb3fc1 100644
--- a/backend/store/task.go
+++ b/backend/store/task.go
@@ -8,6 +8,7 @@ import (
"math"
"sort"
"strings"
+ "time"
"github.com/jackc/pgtype"
"github.com/pkg/errors"
@@ -32,7 +33,7 @@ type TaskMessage struct {
Name string
Type api.TaskType
Payload string
- EarliestAllowedTs int64
+ EarliestAllowedAt *time.Time
DependsOn []int
DatabaseName string
@@ -118,7 +119,7 @@ func (*Store) createTasks(ctx context.Context, tx *Tx, creates ...*TaskMessage)
status,
type,
payload,
- earliest_allowed_ts
+ earliest_allowed_at
)
VALUES
`)
@@ -134,13 +135,13 @@ func (*Store) createTasks(ctx context.Context, tx *Tx, creates ...*TaskMessage)
create.Name,
create.Type,
create.Payload,
- create.EarliestAllowedTs,
+ create.EarliestAllowedAt,
)
const count = 8
queryValues = append(queryValues, fmt.Sprintf("($%d, $%d, $%d, $%d, $%d, 'PENDING_APPROVAL', $%d, $%d, $%d)", i*count+1, i*count+2, i*count+3, i*count+4, i*count+5, i*count+6, i*count+7, i*count+8))
}
_, _ = query.WriteString(strings.Join(queryValues, ","))
- _, _ = query.WriteString(` RETURNING id, pipeline_id, stage_id, instance_id, database_id, name, type, payload, earliest_allowed_ts`)
+ _, _ = query.WriteString(` RETURNING id, pipeline_id, stage_id, instance_id, database_id, name, type, payload, earliest_allowed_at`)
var tasks []*TaskMessage
rows, err := tx.QueryContext(ctx, query.String(), values...)
@@ -151,6 +152,7 @@ func (*Store) createTasks(ctx context.Context, tx *Tx, creates ...*TaskMessage)
for rows.Next() {
task := &TaskMessage{}
var databaseID sql.NullInt32
+ var earliestAllowedAt sql.NullTime
if err := rows.Scan(
&task.ID,
&task.PipelineID,
@@ -160,7 +162,7 @@ func (*Store) createTasks(ctx context.Context, tx *Tx, creates ...*TaskMessage)
&task.Name,
&task.Type,
&task.Payload,
- &task.EarliestAllowedTs,
+ &earliestAllowedAt,
); err != nil {
return nil, errors.Wrapf(err, "failed to scan rows")
}
@@ -168,6 +170,9 @@ func (*Store) createTasks(ctx context.Context, tx *Tx, creates ...*TaskMessage)
val := int(databaseID.Int32)
task.DatabaseID = &val
}
+ if earliestAllowedAt.Valid {
+ task.EarliestAllowedAt = &earliestAllowedAt.Time
+ }
tasks = append(tasks, task)
}
if err := rows.Err(); err != nil {
@@ -254,7 +259,7 @@ func (s *Store) ListTasks(ctx context.Context, find *api.TaskFind) ([]*TaskMessa
latest_task_run.status AS latest_task_run_status,
task.type,
task.payload,
- task.earliest_allowed_ts,
+ task.earliest_allowed_at,
(SELECT ARRAY_AGG (task_dag.from_task_id) FROM task_dag WHERE task_dag.to_task_id = task.id) blocked_by
FROM task
LEFT JOIN LATERAL (
@@ -280,6 +285,7 @@ func (s *Store) ListTasks(ctx context.Context, find *api.TaskFind) ([]*TaskMessa
var tasks []*TaskMessage
for rows.Next() {
task := &TaskMessage{}
+ var earliestAllowedAt sql.NullTime
var dependsOn pgtype.Int4Array
if err := rows.Scan(
&task.ID,
@@ -291,7 +297,7 @@ func (s *Store) ListTasks(ctx context.Context, find *api.TaskFind) ([]*TaskMessa
&task.LatestTaskRunStatus,
&task.Type,
&task.Payload,
- &task.EarliestAllowedTs,
+ &earliestAllowedAt,
&dependsOn,
); err != nil {
return nil, err
@@ -299,6 +305,9 @@ func (s *Store) ListTasks(ctx context.Context, find *api.TaskFind) ([]*TaskMessa
if err := dependsOn.AssignTo(&task.DependsOn); err != nil {
return nil, err
}
+ if earliestAllowedAt.Valid {
+ task.EarliestAllowedAt = &earliestAllowedAt.Time
+ }
tasks = append(tasks, task)
}
if err := rows.Err(); err != nil {
@@ -358,7 +367,7 @@ func (s *Store) UpdateTaskV2(ctx context.Context, patch *api.TaskPatch) (*TaskMe
set, args = append(set, fmt.Sprintf("payload = $%d", len(args)+1)), append(args, payload)
}
if v := patch.EarliestAllowedTs; v != nil {
- set, args = append(set, fmt.Sprintf("earliest_allowed_ts = $%d", len(args)+1)), append(args, *v)
+ set, args = append(set, fmt.Sprintf("earliest_allowed_at = $%d", len(args)+1)), append(args, *v)
}
args = append(args, patch.ID)
@@ -369,12 +378,12 @@ func (s *Store) UpdateTaskV2(ctx context.Context, patch *api.TaskPatch) (*TaskMe
defer tx.Rollback()
task := &TaskMessage{}
- // Execute update query with RETURNING.
+ var earliestAllowedAt sql.NullTime
if err := tx.QueryRowContext(ctx, fmt.Sprintf(`
UPDATE task
SET `+strings.Join(set, ", ")+`
WHERE id = $%d
- RETURNING id, pipeline_id, stage_id, instance_id, database_id, name, type, payload, earliest_allowed_ts
+ RETURNING id, pipeline_id, stage_id, instance_id, database_id, name, type, payload, earliest_allowed_at
`, len(args)),
args...,
).Scan(
@@ -386,7 +395,7 @@ func (s *Store) UpdateTaskV2(ctx context.Context, patch *api.TaskPatch) (*TaskMe
&task.Name,
&task.Type,
&task.Payload,
- &task.EarliestAllowedTs,
+ &earliestAllowedAt,
); err != nil {
if err == sql.ErrNoRows {
return nil, &common.Error{Code: common.NotFound, Err: errors.Errorf("task not found with ID %d", patch.ID)}
@@ -394,6 +403,9 @@ func (s *Store) UpdateTaskV2(ctx context.Context, patch *api.TaskPatch) (*TaskMe
return nil, err
}
+ if earliestAllowedAt.Valid {
+ task.EarliestAllowedAt = &earliestAllowedAt.Time
+ }
if err := tx.Commit(); err != nil {
return nil, err
}
diff --git a/backend/store/task_run.go b/backend/store/task_run.go
index 136aa72800..7db57c5028 100644
--- a/backend/store/task_run.go
+++ b/backend/store/task_run.go
@@ -31,10 +31,10 @@ type TaskRunMessage struct {
ID int
CreatorID int
Creator *UserMessage
- CreatedTs int64
- UpdatedTs int64
+ CreatedAt time.Time
+ UpdatedAt time.Time
ProjectID string
- StartedTs int64
+ StartedAt *time.Time
}
// FindTaskRunMessage is the message for finding task runs.
@@ -102,12 +102,12 @@ func (s *Store) ListTaskRunsV2(ctx context.Context, find *FindTaskRunMessage) ([
SELECT
task_run.id,
task_run.creator_id,
- task_run.created_ts,
- task_run.updated_ts,
+ task_run.created_at,
+ task_run.updated_at,
task_run.task_id,
task_run.name,
task_run.status,
- task_run.started_ts,
+ task_run.started_at,
task_run.code,
task_run.result,
task_run.sheet_id,
@@ -130,15 +130,16 @@ func (s *Store) ListTaskRunsV2(ctx context.Context, find *FindTaskRunMessage) ([
var taskRuns []*TaskRunMessage
for rows.Next() {
var taskRun TaskRunMessage
+ var startedAt sql.NullTime
if err := rows.Scan(
&taskRun.ID,
&taskRun.CreatorID,
- &taskRun.CreatedTs,
- &taskRun.UpdatedTs,
+ &taskRun.CreatedAt,
+ &taskRun.UpdatedAt,
&taskRun.TaskUID,
&taskRun.Name,
&taskRun.Status,
- &taskRun.StartedTs,
+ &startedAt,
&taskRun.Code,
&taskRun.Result,
&taskRun.SheetUID,
@@ -149,6 +150,9 @@ func (s *Store) ListTaskRunsV2(ctx context.Context, find *FindTaskRunMessage) ([
return nil, err
}
+ if startedAt.Valid {
+ taskRun.StartedAt = &startedAt.Time
+ }
var resultProto storepb.TaskRunResult
if err := common.ProtojsonUnmarshaler.Unmarshal([]byte(taskRun.Result), &resultProto); err != nil {
return nil, errors.Wrapf(err, "failed to unmarshal task run result: %s", taskRun.Result)
@@ -340,7 +344,7 @@ func (*Store) createTaskRunImpl(ctx context.Context, tx *Tx, create *TaskRunMess
// patchTaskRunStatusImpl updates a taskRun status. Returns the new state of the taskRun after update.
func (*Store) patchTaskRunStatusImpl(ctx context.Context, tx *Tx, patch *TaskRunStatusPatch) (*TaskRunMessage, error) {
- set, args := []string{"updated_ts = $1", "status = $2"}, []any{time.Now().Unix(), patch.Status}
+ set, args := []string{"updated_at = $1", "status = $2"}, []any{time.Now(), patch.Status}
if v := patch.Code; v != nil {
set, args = append(set, fmt.Sprintf("code = $%d", len(args)+1)), append(args, *v)
}
@@ -352,7 +356,7 @@ func (*Store) patchTaskRunStatusImpl(ctx context.Context, tx *Tx, patch *TaskRun
set, args = append(set, fmt.Sprintf("result = $%d", len(args)+1)), append(args, result)
}
if patch.Status == api.TaskRunRunning {
- set = append(set, "started_ts = extract(epoch from now())")
+ set = append(set, "started_at = now()")
}
// Build WHERE clause.
@@ -364,14 +368,14 @@ func (*Store) patchTaskRunStatusImpl(ctx context.Context, tx *Tx, patch *TaskRun
UPDATE task_run
SET `+strings.Join(set, ", ")+`
WHERE `+strings.Join(where, " AND ")+`
- RETURNING id, creator_id, created_ts, updated_ts, task_id, name, status, code, result
+ RETURNING id, creator_id, created_at, updated_at, task_id, name, status, code, result
`,
args...,
).Scan(
&taskRun.ID,
&taskRun.CreatorID,
- &taskRun.CreatedTs,
- &taskRun.UpdatedTs,
+ &taskRun.CreatedAt,
+ &taskRun.UpdatedAt,
&taskRun.TaskUID,
&taskRun.Name,
&taskRun.Status,
@@ -431,8 +435,8 @@ func (*Store) findTaskRunImpl(ctx context.Context, tx *Tx, find *TaskRunFind) ([
SELECT
task_run.id,
task_run.creator_id,
- task_run.created_ts,
- task_run.updated_ts,
+ task_run.created_at,
+ task_run.updated_at,
task_run.task_id,
task_run.name,
task_run.status,
@@ -457,8 +461,8 @@ func (*Store) findTaskRunImpl(ctx context.Context, tx *Tx, find *TaskRunFind) ([
if err := rows.Scan(
&taskRun.ID,
&taskRun.CreatorID,
- &taskRun.CreatedTs,
- &taskRun.UpdatedTs,
+ &taskRun.CreatedAt,
+ &taskRun.UpdatedAt,
&taskRun.TaskUID,
&taskRun.Name,
&taskRun.Status,
diff --git a/backend/store/worksheet.go b/backend/store/worksheet.go
index 5958931cb3..dc4c21ffb5 100644
--- a/backend/store/worksheet.go
+++ b/backend/store/worksheet.go
@@ -41,15 +41,11 @@ type WorkSheetMessage struct {
Visibility WorkSheetVisibility
// Output only fields
- UID int
- Size int64
- CreatedTime time.Time
- UpdatedTime time.Time
- Starred bool
-
- // Internal fields
- createdTs int64
- updatedTs int64
+ UID int
+ Size int64
+ CreatedAt time.Time
+ UpdatedAt time.Time
+ Starred bool
}
// FindWorkSheetMessage is the API message for finding sheets.
@@ -146,8 +142,8 @@ func (s *Store) ListWorkSheets(ctx context.Context, find *FindWorkSheetMessage,
SELECT
worksheet.id,
worksheet.creator_id,
- worksheet.created_ts,
- worksheet.updated_ts,
+ worksheet.created_at,
+ worksheet.updated_at,
worksheet.project_id,
worksheet.database_id,
worksheet.name,
@@ -171,8 +167,8 @@ func (s *Store) ListWorkSheets(ctx context.Context, find *FindWorkSheetMessage,
if err := rows.Scan(
&sheet.UID,
&sheet.CreatorID,
- &sheet.createdTs,
- &sheet.updatedTs,
+ &sheet.CreatedAt,
+ &sheet.UpdatedAt,
&sheet.ProjectUID,
&sheet.DatabaseUID,
&sheet.Title,
@@ -193,11 +189,6 @@ func (s *Store) ListWorkSheets(ctx context.Context, find *FindWorkSheetMessage,
return nil, err
}
- for _, sheet := range sheets {
- sheet.CreatedTime = time.Unix(sheet.createdTs, 0)
- sheet.UpdatedTime = time.Unix(sheet.updatedTs, 0)
- }
-
return sheets, nil
}
@@ -219,7 +210,7 @@ func (s *Store) CreateWorkSheet(ctx context.Context, create *WorkSheetMessage) (
payload
)
VALUES ($1, $2, $3, $4, $5, $6, $7)
- RETURNING id, created_ts, updated_ts, OCTET_LENGTH(statement)
+ RETURNING id, created_at, updated_at, OCTET_LENGTH(statement)
`
tx, err := s.db.BeginTx(ctx, nil)
@@ -237,8 +228,8 @@ func (s *Store) CreateWorkSheet(ctx context.Context, create *WorkSheetMessage) (
payload,
).Scan(
&create.UID,
- &create.createdTs,
- &create.updatedTs,
+ &create.CreatedAt,
+ &create.UpdatedAt,
&create.Size,
); err != nil {
if err == sql.ErrNoRows {
@@ -250,9 +241,6 @@ func (s *Store) CreateWorkSheet(ctx context.Context, create *WorkSheetMessage) (
return nil, errors.Wrapf(err, "failed to commit transaction")
}
- create.CreatedTime = time.Unix(create.createdTs, 0)
- create.UpdatedTime = time.Unix(create.updatedTs, 0)
-
return create, nil
}
@@ -293,7 +281,7 @@ func (s *Store) DeleteWorkSheet(ctx context.Context, sheetUID int) error {
// patchWorkSheetImpl updates a sheet's name/statement/visibility/database_id/project_id.
func patchWorkSheetImpl(ctx context.Context, tx *Tx, patch *PatchWorkSheetMessage) error {
- set, args := []string{"updated_ts = $1"}, []any{time.Now().Unix()}
+ set, args := []string{"updated_at = $1"}, []any{time.Now()}
if v := patch.Title; 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 6e85891b11..8095389845 100644
--- a/backend/utils/utils.go
+++ b/backend/utils/utils.go
@@ -343,7 +343,7 @@ func handleApprovalNodeExternalNode(ctx context.Context, s *store.Store, relayCl
Title: issue.Title,
Description: issue.Description,
Project: issue.Project.ResourceID,
- CreateTime: issue.CreatedTime,
+ CreateTime: issue.CreatedAt,
Creator: issue.Creator.Email,
})
if err != nil {