Skip to content

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

chore: created_at (#15166)

Danny Xu41ed942d3777
diff --git a/backend/migrator/migration/3.4/0005##created_at.sql b/backend/migrator/migration/3.4/0005##created_at.sql
new file mode 100644
index 0000000000..e16667eaef
--- /dev/null
+++ b/backend/migrator/migration/3.4/0005##created_at.sql
@@ -0,0 +1,10 @@
+ALTER TABLE task_run_log RENAME COLUMN created_ts TO created_at;
+DROP INDEX IF EXISTS idx_revision_unique_database_id_version_deleted_ts_null;
+ALTER TABLE revision RENAME COLUMN created_ts TO created_at;
+ALTER TABLE revision RENAME COLUMN deleted_ts TO deleted_at;
+ALTER INDEX idx_revision_unique_database_id_version_deleted_ts_null RENAME TO idx_revision_unique_database_id_version_deleted_at_null;
+ALTER TABLE sync_history RENAME COLUMN created_ts TO created_at;
+ALTER INDEX idx_sync_history_database_id_created_ts RENAME TO idx_sync_history_database_id_created_at;
+ALTER TABLE changelog RENAME COLUMN created_ts TO created_at;
+ALTER TABLE release RENAME COLUMN created_ts TO created_at;
+ALTER TABLE policy RENAME COLUMN updated_ts TO updated_at;
diff --git a/backend/migrator/migration/LATEST.sql b/backend/migrator/migration/LATEST.sql
index ed2c94c74f..a77aa04b19 100644
--- a/backend/migrator/migration/LATEST.sql
+++ b/backend/migrator/migration/LATEST.sql
@@ -77,7 +77,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',
- updated_ts TIMESTAMPTZ NOT NULL DEFAULT now(),
+ updated_at 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,
@@ -308,7 +308,7 @@ ALTER SEQUENCE task_run_id_seq RESTART WITH 101;
CREATE TABLE task_run_log (
id BIGSERIAL PRIMARY KEY,
task_run_id INTEGER NOT NULL REFERENCES task_run (id),
- created_ts TIMESTAMPTZ NOT NULL DEFAULT now(),
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
payload JSONB NOT NULL DEFAULT '{}'
);
@@ -649,22 +649,22 @@ CREATE TABLE review_config (
CREATE TABLE revision (
id BIGSERIAL PRIMARY KEY,
database_id INTEGER NOT NULL REFERENCES db (id),
- created_ts TIMESTAMPTZ NOT NULL DEFAULT now(),
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
deleter_id INTEGER REFERENCES principal (id),
- deleted_ts TIMESTAMPTZ,
+ deleted_at TIMESTAMPTZ,
version TEXT NOT NULL,
payload JSONB NOT NULL DEFAULT '{}'
);
ALTER SEQUENCE revision_id_seq RESTART WITH 101;
-CREATE UNIQUE INDEX IF NOT EXISTS idx_revision_unique_database_id_version_deleted_ts_null ON revision (database_id, version) WHERE deleted_ts IS NULL;
+CREATE UNIQUE INDEX IF NOT EXISTS idx_revision_unique_database_id_version_deleted_at_null ON revision (database_id, version) WHERE deleted_at IS NULL;
CREATE INDEX IF NOT EXISTS idx_revision_database_id_version ON revision (database_id, version);
CREATE TABLE sync_history (
id BIGSERIAL PRIMARY KEY,
- created_ts TIMESTAMPTZ NOT NULL DEFAULT now(),
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
database_id INTEGER NOT NULL REFERENCES db (id),
metadata JSON NOT NULL DEFAULT '{}',
raw_dump TEXT NOT NULL DEFAULT ''
@@ -672,11 +672,11 @@ CREATE TABLE sync_history (
ALTER SEQUENCE sync_history_id_seq RESTART WITH 101;
-CREATE INDEX IF NOT EXISTS idx_sync_history_database_id_created_ts ON sync_history (database_id, created_ts);
+CREATE INDEX IF NOT EXISTS idx_sync_history_database_id_created_at ON sync_history (database_id, created_at);
CREATE TABLE changelog (
id BIGSERIAL PRIMARY KEY,
- created_ts TIMESTAMPTZ NOT NULL DEFAULT now(),
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
database_id INTEGER NOT NULL REFERENCES db (id),
status TEXT NOT NULL CONSTRAINT changelog_status_check CHECK (status IN ('PENDING', 'DONE', 'FAILED')),
prev_sync_history_id BIGINT REFERENCES sync_history (id),
@@ -693,7 +693,7 @@ CREATE TABLE IF NOT EXISTS release (
row_status row_status NOT NULL DEFAULT 'NORMAL',
project_id INTEGER NOT NULL REFERENCES project (id),
creator_id INTEGER NOT NULL REFERENCES principal (id),
- created_ts TIMESTAMPTZ NOT NULL DEFAULT now(),
+ created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
payload JSONB NOT NULL DEFAULT '{}'
);
diff --git a/backend/migrator/migrator_test.go b/backend/migrator/migrator_test.go
index 1d77c9f72b..5ac987b1ad 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.4"), releaseVersion)
+ require.Equal(t, semver.MustParse("3.4.5"), releaseVersion)
}
diff --git a/backend/store/changelog.go b/backend/store/changelog.go
index 5735a77f03..32c69bc9eb 100644
--- a/backend/store/changelog.go
+++ b/backend/store/changelog.go
@@ -201,7 +201,7 @@ func (s *Store) ListChangelogs(ctx context.Context, find *FindChangelogMessage)
query := fmt.Sprintf(`
SELECT
changelog.id,
- changelog.created_ts,
+ changelog.created_at,
changelog.database_id,
changelog.status,
changelog.prev_sync_history_id,
diff --git a/backend/store/database.go b/backend/store/database.go
index df3f27143f..fe60bf2cb7 100644
--- a/backend/store/database.go
+++ b/backend/store/database.go
@@ -500,7 +500,7 @@ func (*Store) listDatabaseImplV2(ctx context.Context, tx *Tx, find *FindDatabase
(
SELECT revision.version
FROM revision
- WHERE revision.database_id = db.id AND deleted_ts IS NOT NULL
+ WHERE revision.database_id = db.id AND deleted_at IS NOT NULL
ORDER BY revision.version DESC
LIMIT 1
),
diff --git a/backend/store/policy.go b/backend/store/policy.go
index 69a2a0a751..c11f08a5e6 100644
--- a/backend/store/policy.go
+++ b/backend/store/policy.go
@@ -445,7 +445,7 @@ func (s *Store) CreatePolicyV2(ctx context.Context, create *PolicyMessage) (*Pol
// UpdatePolicyV2 updates the policy.
func (s *Store) UpdatePolicyV2(ctx context.Context, patch *UpdatePolicyMessage) (*PolicyMessage, error) {
- set, args := []string{"updated_ts = $1"}, []any{time.Now()}
+ set, args := []string{"updated_at = $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)
}
@@ -482,7 +482,7 @@ func (s *Store) UpdatePolicyV2(ctx context.Context, patch *UpdatePolicyMessage)
payload,
inherit_from_parent,
row_status,
- updated_ts
+ updated_at
`, len(args)-2, len(args)-1, len(args)),
args...,
).Scan(
@@ -557,7 +557,7 @@ func upsertPolicyV2Impl(ctx context.Context, tx *Tx, create *PolicyMessage) (*Po
row_status = EXCLUDED.row_status
RETURNING
id,
- updated_ts
+ updated_at
`,
create.ResourceType,
create.ResourceUID,
@@ -593,7 +593,7 @@ func (*Store) listPolicyImplV2(ctx context.Context, tx *Tx, find *FindPolicyMess
rows, err := tx.QueryContext(ctx, `
SELECT
id,
- updated_ts,
+ updated_at,
resource_type,
resource_id,
inherit_from_parent,
diff --git a/backend/store/release.go b/backend/store/release.go
index 1adb5ef7ab..297d76d038 100644
--- a/backend/store/release.go
+++ b/backend/store/release.go
@@ -51,7 +51,7 @@ func (s *Store) CreateRelease(ctx context.Context, release *ReleaseMessage, crea
$1,
$2,
$3
- ) RETURNING id, created_ts
+ ) RETURNING id, created_at
`
p, err := protojson.Marshal(release.Payload)
@@ -120,7 +120,7 @@ func (s *Store) ListReleases(ctx context.Context, find *FindReleaseMessage) ([]*
row_status,
project_id,
creator_id,
- created_ts,
+ created_at,
payload
FROM release
WHERE %s
diff --git a/backend/store/revision.go b/backend/store/revision.go
index 079bafff12..3b6f12636a 100644
--- a/backend/store/revision.go
+++ b/backend/store/revision.go
@@ -54,7 +54,7 @@ func (s *Store) ListRevisions(ctx context.Context, find *FindRevisionMessage) ([
args = append(args, *v)
}
if !find.ShowDeleted {
- where = append(where, "deleted_ts IS NULL")
+ where = append(where, "deleted_at IS NULL")
}
limitOffsetClause := ""
@@ -69,9 +69,9 @@ func (s *Store) ListRevisions(ctx context.Context, find *FindRevisionMessage) ([
SELECT
id,
database_id,
- created_ts,
+ created_at,
deleter_id,
- deleted_ts,
+ deleted_at,
version,
payload
FROM revision
@@ -153,7 +153,7 @@ func (s *Store) CreateRevision(ctx context.Context, revision *RevisionMessage) (
$2,
$3
)
- RETURNING id, created_ts
+ RETURNING id, created_at
`
p, err := protojson.Marshal(revision.Payload)
@@ -190,7 +190,7 @@ func (s *Store) CreateRevision(ctx context.Context, revision *RevisionMessage) (
func (s *Store) DeleteRevision(ctx context.Context, uid int64, deleterUID int) error {
query :=
`UPDATE revision
- SET deleter_id = $1, deleted_ts = now()
+ SET deleter_id = $1, deleted_at = now()
WHERE id = $2`
tx, err := s.db.BeginTx(ctx, nil)
diff --git a/backend/store/sync_history.go b/backend/store/sync_history.go
index 24ae0d1684..9892c3235f 100644
--- a/backend/store/sync_history.go
+++ b/backend/store/sync_history.go
@@ -25,7 +25,7 @@ func (s *Store) GetSyncHistoryByUID(ctx context.Context, uid int64) (*SyncHistor
query := `
SELECT
id,
- created_ts,
+ created_at,
database_id,
metadata,
raw_dump
diff --git a/backend/store/task_run_log.go b/backend/store/task_run_log.go
index f244a86416..5423eeae62 100644
--- a/backend/store/task_run_log.go
+++ b/backend/store/task_run_log.go
@@ -28,7 +28,7 @@ func (s *Store) CreateTaskRunLog(ctx context.Context, taskRunUID int, t time.Tim
query := `
INSERT INTO task_run_log (
task_run_id,
- created_ts,
+ created_at,
payload
) VALUES (
$1,
@@ -50,7 +50,7 @@ func (s *Store) CreateTaskRunLog(ctx context.Context, taskRunUID int, t time.Tim
func (s *Store) ListTaskRunLogs(ctx context.Context, taskRunUID int) ([]*TaskRunLog, error) {
query := `
SELECT
- created_ts,
+ created_at,
payload
FROM task_run_log
WHERE task_run_log.task_run_id = $1