Skip to content

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

feat: changelog service (#14197)

p0nyae8f38993195
diff --git a/backend/api/v1/database_service_changelog.go b/backend/api/v1/database_service_changelog.go
index cf98b9eb4c..39c49137c9 100644
--- a/backend/api/v1/database_service_changelog.go
+++ b/backend/api/v1/database_service_changelog.go
@@ -91,14 +91,13 @@ func (s *DatabaseService) convertToChangelogs(ctx context.Context, d *store.Data
}
func (s *DatabaseService) convertToChangelog(ctx context.Context, d *store.DatabaseMessage, c *store.ChangelogMessage) (*v1pb.Changelog, error) {
- // TODO(p0ny): convert other fields
cl := &v1pb.Changelog{
Name: common.FormatChangelog(d.InstanceID, d.DatabaseName, c.UID),
Creator: "",
CreateTime: timestamppb.New(c.CreatedTime),
Status: v1pb.Changelog_Status(c.Payload.GetTask().GetStatus()),
- Statement: "TODO(p0ny): convert statement",
- StatementSize: 100,
+ Statement: "",
+ StatementSize: 0,
StatementSheet: "",
Schema: "",
SchemaSize: 0,
@@ -106,11 +105,29 @@ func (s *DatabaseService) convertToChangelog(ctx context.Context, d *store.Datab
PrevSchemaSize: 0,
Issue: c.Payload.GetTask().GetIssue(),
TaskRun: c.Payload.GetTask().GetTaskRun(),
- Version: "",
+ Version: c.Payload.GetTask().GetVersion(),
Revision: "",
ChangedResources: convertToChangedResources(c.Payload.GetTask().GetChangedResources()),
}
+ if sheet := c.Payload.GetTask().GetSheet(); sheet != "" {
+ _, sheetUID, err := common.GetProjectResourceIDSheetUID(sheet)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to get sheetUID from %q", sheet)
+ }
+ sheetM, err := s.store.GetSheet(ctx, &store.FindSheetMessage{UID: &sheetUID})
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to get sheet %q", sheet)
+ }
+ if sheetM == nil {
+ return nil, errors.Errorf("sheet %q not found", sheet)
+ }
+
+ cl.StatementSheet = sheet
+ cl.Statement = sheetM.Statement
+ cl.StatementSize = sheetM.Size
+ }
+
if id := c.Payload.GetTask().GetRevision(); id != 0 {
cl.Revision = common.FormatRevision(d.InstanceID, d.DatabaseName, id)
}
diff --git a/backend/runner/taskrun/executor.go b/backend/runner/taskrun/executor.go
index e364699909..a6e538717b 100644
--- a/backend/runner/taskrun/executor.go
+++ b/backend/runner/taskrun/executor.go
@@ -550,6 +550,8 @@ func beginMigration(ctx context.Context, stores *store.Store, mi *db.MigrationIn
Status: storepb.ChangelogTask_PENDING,
PrevSyncHistoryId: syncHistoryPrev,
SyncHistoryId: 0,
+ Sheet: mc.sheetName,
+ Version: mc.version,
},
}}, api.SystemBotID)
if err != nil {
@@ -613,19 +615,25 @@ func endMigration(ctx context.Context, storeInstance *store.Store, startedNs int
if isDone {
// if isDone, record in revision
if mc.version != "" {
- revision, err := storeInstance.CreateRevision(ctx, &store.RevisionMessage{
+ r := &store.RevisionMessage{
DatabaseUID: mc.database.UID,
Payload: &storepb.RevisionPayload{
Release: mc.release.release,
File: mc.release.file,
- Sheet: mc.sheetName,
- SheetSha256: mc.sheet.Sha256,
+ Sheet: "",
+ SheetSha256: "",
TaskRun: mc.taskRunName,
Version: mc.version,
// TODO(p0ny): maybe remove this field.
Type: storepb.ReleaseFileType_TYPE_UNSPECIFIED,
},
- }, mc.task.CreatorID)
+ }
+ if mc.sheet != nil {
+ r.Payload.Sheet = mc.sheetName
+ r.Payload.SheetSha256 = mc.sheet.Sha256
+ }
+
+ revision, err := storeInstance.CreateRevision(ctx, r, mc.task.CreatorID)
if err != nil {
return errors.Wrapf(err, "failed to create revision")
}
diff --git a/frontend/src/types/proto/store/changelog.ts b/frontend/src/types/proto/store/changelog.ts
index 2acde93e20..6946d370a9 100644
--- a/frontend/src/types/proto/store/changelog.ts
+++ b/frontend/src/types/proto/store/changelog.ts
@@ -30,6 +30,7 @@ export interface ChangelogTask {
* Format: projects/{project}/sheets/{sheet}
*/
sheet: string;
+ version: string;
}
export enum ChangelogTask_Status {
@@ -240,6 +241,7 @@ function createBaseChangelogTask(): ChangelogTask {
prevSyncHistoryId: Long.ZERO,
syncHistoryId: Long.ZERO,
sheet: "",
+ version: "",
};
}
@@ -269,6 +271,9 @@ export const ChangelogTask: MessageFns<ChangelogTask> = {
if (message.sheet !== "") {
writer.uint32(66).string(message.sheet);
}
+ if (message.version !== "") {
+ writer.uint32(74).string(message.version);
+ }
return writer;
},
@@ -335,6 +340,13 @@ export const ChangelogTask: MessageFns<ChangelogTask> = {
message.sheet = reader.string();
continue;
+ case 9:
+ if (tag !== 74) {
+ break;
+ }
+
+ message.version = reader.string();
+ continue;
}
if ((tag & 7) === 4 || tag === 0) {
break;
@@ -356,6 +368,7 @@ export const ChangelogTask: MessageFns<ChangelogTask> = {
prevSyncHistoryId: isSet(object.prevSyncHistoryId) ? Long.fromValue(object.prevSyncHistoryId) : Long.ZERO,
syncHistoryId: isSet(object.syncHistoryId) ? Long.fromValue(object.syncHistoryId) : Long.ZERO,
sheet: isSet(object.sheet) ? globalThis.String(object.sheet) : "",
+ version: isSet(object.version) ? globalThis.String(object.version) : "",
};
},
@@ -385,6 +398,9 @@ export const ChangelogTask: MessageFns<ChangelogTask> = {
if (message.sheet !== "") {
obj.sheet = message.sheet;
}
+ if (message.version !== "") {
+ obj.version = message.version;
+ }
return obj;
},
@@ -409,6 +425,7 @@ export const ChangelogTask: MessageFns<ChangelogTask> = {
? Long.fromValue(object.syncHistoryId)
: Long.ZERO;
message.sheet = object.sheet ?? "";
+ message.version = object.version ?? "";
return message;
},
};
diff --git a/proto/gen/grpc-doc/store/README.md b/proto/gen/grpc-doc/store/README.md
index 6fe7d01f85..459c9be14f 100644
--- a/proto/gen/grpc-doc/store/README.md
+++ b/proto/gen/grpc-doc/store/README.md
@@ -1908,6 +1908,7 @@ PostgreSQL: RANGE, LIST, HASH (https://www.postgresql.org/docs/current/ddl-parti
| prev_sync_history_id | [int64](#int64) | | |
| sync_history_id | [int64](#int64) | | |
| sheet | [string](#string) | | The sheet that holds the content. Format: projects/{project}/sheets/{sheet} |
+| version | [string](#string) | | |
diff --git a/proto/gen/grpc-doc/store/index.html b/proto/gen/grpc-doc/store/index.html
index 2ac55a75a8..fcfd20bed4 100644
--- a/proto/gen/grpc-doc/store/index.html
+++ b/proto/gen/grpc-doc/store/index.html
@@ -5357,6 +5357,13 @@ Example: projects/project-id/branches/branch-id. </p></td>
Format: projects/{project}/sheets/{sheet} </p></td>
</tr>
+ <tr>
+ <td>version</td>
+ <td><a href="#string">string</a></td>
+ <td></td>
+ <td><p> </p></td>
+ </tr>
+
</tbody>
</table>
diff --git a/proto/generated-go/store/changelog.pb.go b/proto/generated-go/store/changelog.pb.go
index d5010b8a65..92e7b1ef79 100644
--- a/proto/generated-go/store/changelog.pb.go
+++ b/proto/generated-go/store/changelog.pb.go
@@ -189,7 +189,8 @@ type ChangelogTask struct {
SyncHistoryId int64 `protobuf:"varint,7,opt,name=sync_history_id,json=syncHistoryId,proto3" json:"sync_history_id,omitempty"`
// The sheet that holds the content.
// Format: projects/{project}/sheets/{sheet}
- Sheet string `protobuf:"bytes,8,opt,name=sheet,proto3" json:"sheet,omitempty"`
+ Sheet string `protobuf:"bytes,8,opt,name=sheet,proto3" json:"sheet,omitempty"`
+ Version string `protobuf:"bytes,9,opt,name=version,proto3" json:"version,omitempty"`
}
func (x *ChangelogTask) Reset() {
@@ -278,6 +279,13 @@ func (x *ChangelogTask) GetSheet() string {
return ""
}
+func (x *ChangelogTask) GetVersion() string {
+ if x != nil {
+ return x.Version
+ }
+ return ""
+}
+
type ChangelogRevision struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@@ -348,7 +356,7 @@ var file_store_changelog_proto_rawDesc = []byte{
0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x21, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73,
0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x6c, 0x6f,
0x67, 0x52, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x52, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73,
- 0x69, 0x6f, 0x6e, 0x22, 0x9d, 0x03, 0x0a, 0x0d, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x6c, 0x6f,
+ 0x69, 0x6f, 0x6e, 0x22, 0xb7, 0x03, 0x0a, 0x0d, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x6c, 0x6f,
0x67, 0x54, 0x61, 0x73, 0x6b, 0x12, 0x19, 0x0a, 0x08, 0x74, 0x61, 0x73, 0x6b, 0x5f, 0x72, 0x75,
0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x74, 0x61, 0x73, 0x6b, 0x52, 0x75, 0x6e,
0x12, 0x14, 0x0a, 0x05, 0x69, 0x73, 0x73, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
@@ -369,24 +377,26 @@ var file_store_changelog_proto_rawDesc = []byte{
0x12, 0x26, 0x0a, 0x0f, 0x73, 0x79, 0x6e, 0x63, 0x5f, 0x68, 0x69, 0x73, 0x74, 0x6f, 0x72, 0x79,
0x5f, 0x69, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0d, 0x73, 0x79, 0x6e, 0x63, 0x48,
0x69, 0x73, 0x74, 0x6f, 0x72, 0x79, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x68, 0x65, 0x65,
- 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x73, 0x68, 0x65, 0x65, 0x74, 0x22, 0x43,
- 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x12, 0x53, 0x54, 0x41, 0x54,
- 0x55, 0x53, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00,
- 0x12, 0x0b, 0x0a, 0x07, 0x50, 0x45, 0x4e, 0x44, 0x49, 0x4e, 0x47, 0x10, 0x01, 0x12, 0x08, 0x0a,
- 0x04, 0x44, 0x4f, 0x4e, 0x45, 0x10, 0x02, 0x12, 0x0a, 0x0a, 0x06, 0x46, 0x41, 0x49, 0x4c, 0x45,
- 0x44, 0x10, 0x03, 0x22, 0xa5, 0x01, 0x0a, 0x11, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x6c, 0x6f,
- 0x67, 0x52, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x76,
- 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x72, 0x65, 0x76,
- 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x42, 0x0a, 0x09, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69,
- 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x24, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62,
- 0x61, 0x73, 0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65,
- 0x6c, 0x6f, 0x67, 0x52, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x2e, 0x4f, 0x70, 0x52, 0x09,
- 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x30, 0x0a, 0x02, 0x4f, 0x70, 0x12,
- 0x12, 0x0a, 0x0e, 0x4f, 0x50, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45,
- 0x44, 0x10, 0x00, 0x12, 0x0a, 0x0a, 0x06, 0x43, 0x52, 0x45, 0x41, 0x54, 0x45, 0x10, 0x01, 0x12,
- 0x0a, 0x0a, 0x06, 0x44, 0x45, 0x4c, 0x45, 0x54, 0x45, 0x10, 0x02, 0x42, 0x14, 0x5a, 0x12, 0x67,
- 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x2d, 0x67, 0x6f, 0x2f, 0x73, 0x74, 0x6f, 0x72,
- 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+ 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x73, 0x68, 0x65, 0x65, 0x74, 0x12, 0x18,
+ 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52,
+ 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x43, 0x0a, 0x06, 0x53, 0x74, 0x61, 0x74,
+ 0x75, 0x73, 0x12, 0x16, 0x0a, 0x12, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x5f, 0x55, 0x4e, 0x53,
+ 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0b, 0x0a, 0x07, 0x50, 0x45,
+ 0x4e, 0x44, 0x49, 0x4e, 0x47, 0x10, 0x01, 0x12, 0x08, 0x0a, 0x04, 0x44, 0x4f, 0x4e, 0x45, 0x10,
+ 0x02, 0x12, 0x0a, 0x0a, 0x06, 0x46, 0x41, 0x49, 0x4c, 0x45, 0x44, 0x10, 0x03, 0x22, 0xa5, 0x01,
+ 0x0a, 0x11, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x6c, 0x6f, 0x67, 0x52, 0x65, 0x76, 0x69, 0x73,
+ 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18,
+ 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12,
+ 0x42, 0x0a, 0x09, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01,
+ 0x28, 0x0e, 0x32, 0x24, 0x2e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x73, 0x74,
+ 0x6f, 0x72, 0x65, 0x2e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x6c, 0x6f, 0x67, 0x52, 0x65, 0x76,
+ 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x2e, 0x4f, 0x70, 0x52, 0x09, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74,
+ 0x69, 0x6f, 0x6e, 0x22, 0x30, 0x0a, 0x02, 0x4f, 0x70, 0x12, 0x12, 0x0a, 0x0e, 0x4f, 0x50, 0x5f,
+ 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0a, 0x0a,
+ 0x06, 0x43, 0x52, 0x45, 0x41, 0x54, 0x45, 0x10, 0x01, 0x12, 0x0a, 0x0a, 0x06, 0x44, 0x45, 0x4c,
+ 0x45, 0x54, 0x45, 0x10, 0x02, 0x42, 0x14, 0x5a, 0x12, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74,
+ 0x65, 0x64, 0x2d, 0x67, 0x6f, 0x2f, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f,
+ 0x74, 0x6f, 0x33,
}
var (
diff --git a/proto/store/changelog.proto b/proto/store/changelog.proto
index 10ea9d2fb2..df990b6c8d 100644
--- a/proto/store/changelog.proto
+++ b/proto/store/changelog.proto
@@ -35,6 +35,8 @@ message ChangelogTask {
// The sheet that holds the content.
// Format: projects/{project}/sheets/{sheet}
string sheet = 8;
+
+ string version = 9;
}
message ChangelogRevision {