Skip to content

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

chore: change statement type of release file to bytes (#15725)

boojackea994816f735
diff --git a/action/file.go b/action/file.go
index 32dd6fd87d..72ef356a80 100644
--- a/action/file.go
+++ b/action/file.go
@@ -37,7 +37,7 @@ func getReleaseFiles(pattern string) ([]*v1pb.Release_File, error) {
Path: m,
Version: version,
ChangeType: t,
- Statement: string(content),
+ Statement: content,
})
}
diff --git a/backend/api/v1/release_service.go b/backend/api/v1/release_service.go
index b73cb36b4d..9275050949 100644
--- a/backend/api/v1/release_service.go
+++ b/backend/api/v1/release_service.go
@@ -316,7 +316,7 @@ func convertToReleaseFiles(ctx context.Context, s *store.Store, files []*storepb
SheetSha256: f.SheetSha256,
Type: v1pb.ReleaseFileType(f.Type),
Version: f.Version,
- Statement: sheet.Statement,
+ Statement: []byte(sheet.Statement),
StatementSize: sheet.Size,
ChangeType: v1pb.Release_File_ChangeType(f.ChangeType),
})
diff --git a/backend/api/v1/release_service_check.go b/backend/api/v1/release_service_check.go
index 35e6e8c845..22f80a539d 100644
--- a/backend/api/v1/release_service_check.go
+++ b/backend/api/v1/release_service_check.go
@@ -151,9 +151,10 @@ func (s *ReleaseService) CheckRelease(ctx context.Context, request *v1pb.CheckRe
File: file.Path,
Target: fmt.Sprintf("instances/%s/databases/%s", instance.ResourceID, database.DatabaseName),
}
+ statement := string(file.Statement)
// Check if any syntax error in the statement.
- _, syntaxAdvices := s.sheetManager.GetASTsForChecks(instance.Metadata.GetEngine(), file.Statement)
+ _, syntaxAdvices := s.sheetManager.GetASTsForChecks(instance.Metadata.GetEngine(), statement)
if len(syntaxAdvices) > 0 {
for _, advice := range syntaxAdvices {
checkResult.Advices = append(checkResult.Advices, convertToV1Advice(advice))
@@ -169,7 +170,7 @@ func (s *ReleaseService) CheckRelease(ctx context.Context, request *v1pb.CheckRe
// Get SQL summary report for the statement and target database.
// Including affected rows.
- summaryReport, err := plancheck.GetSQLSummaryReport(ctx, s.store, s.sheetManager, s.dbFactory, database, file.Statement)
+ summaryReport, err := plancheck.GetSQLSummaryReport(ctx, s.store, s.sheetManager, s.dbFactory, database, statement)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get SQL summary report, error: %v", err)
}
@@ -183,7 +184,7 @@ func (s *ReleaseService) CheckRelease(ctx context.Context, request *v1pb.CheckRe
database,
changeType,
summaryReport,
- file.Statement,
+ statement,
)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to calculate risk level, error: %v", err)
@@ -197,7 +198,7 @@ func (s *ReleaseService) CheckRelease(ctx context.Context, request *v1pb.CheckRe
}
checkResult.RiskLevel = riskLevelEnum
}
- adviceStatus, sqlReviewAdvices, err := s.runSQLReviewCheckForFile(ctx, catalog, instance, database, changeType, file.Statement)
+ adviceStatus, sqlReviewAdvices, err := s.runSQLReviewCheckForFile(ctx, catalog, instance, database, changeType, statement)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to check SQL review: %v", err)
}
diff --git a/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue b/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue
index 01009bc3a0..75ff2409f2 100644
--- a/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue
+++ b/frontend/src/components/IssueV1/components/HeaderSection/Actions/create/CreateButton.vue
@@ -359,7 +359,7 @@ const runSQLCheckForIssue = async () => {
// Use a random uuid to avoid duplication.
version: uuidv4(),
type: ReleaseFileType.VERSIONED,
- statement: statement,
+ statement: new TextEncoder().encode(statement),
changeType: getTaskChangeType(issue.value, flattenTasks[0]),
},
],
diff --git a/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckButton.vue b/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckButton.vue
index b0f674ec5b..98abecd360 100644
--- a/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckButton.vue
+++ b/frontend/src/components/IssueV1/components/SQLCheckSection/SQLCheckButton.vue
@@ -124,7 +124,7 @@ const runCheckInternal = async (statement: string) => {
// Use a random uuid to avoid duplication.
version: uuidv4(),
type: ReleaseFileType.VERSIONED,
- statement: statement,
+ statement: new TextEncoder().encode(statement),
changeType: changeType.value,
},
],
diff --git a/frontend/src/components/Release/ReleaseDataTable.vue b/frontend/src/components/Release/ReleaseDataTable.vue
index e4288a6bf6..20db130429 100644
--- a/frontend/src/components/Release/ReleaseDataTable.vue
+++ b/frontend/src/components/Release/ReleaseDataTable.vue
@@ -22,7 +22,7 @@ import { useRouter } from "vue-router";
import { BBAvatar } from "@/bbkit";
import { getTimeForPbTimestamp, type ComposedRelease } from "@/types";
import { State } from "@/types/proto/v1/common";
-import { humanizeTs } from "@/utils";
+import { getReleaseFileStatement, humanizeTs } from "@/utils";
interface LocalState {
selectedReleaseNameList: Set<string>;
@@ -84,7 +84,7 @@ const columnList = computed(
<NTag class="mr-2" v-if="schemaVersion" size="small" round>
{file.version}
</NTag>
- {file.statement}
+ {getReleaseFileStatement(file)}
</p>
))}
{release.files.length > MAX_SHOW_FILES_COUNT && (
diff --git a/frontend/src/components/Release/ReleaseDetail/NavBar/PreviewPlanDetail.vue b/frontend/src/components/Release/ReleaseDetail/NavBar/PreviewPlanDetail.vue
index 5d58662830..61583268c9 100644
--- a/frontend/src/components/Release/ReleaseDetail/NavBar/PreviewPlanDetail.vue
+++ b/frontend/src/components/Release/ReleaseDetail/NavBar/PreviewPlanDetail.vue
@@ -25,7 +25,11 @@
</NTag>
<span class="text-sm">
{{
- getFileByName(spec.specReleaseSource?.file || "")?.statement || "-"
+ spec.specReleaseSource?.file
+ ? getReleaseFileStatement(
+ getFileByName(spec.specReleaseSource.file)!
+ )
+ : "-"
}}
</span>
</div>
@@ -131,6 +135,7 @@ import type {
Plan_Spec,
PreviewPlanResponse,
} from "@/types/proto/v1/plan_service";
+import { getReleaseFileStatement } from "@/utils";
const props = defineProps<{
release: ComposedRelease;
diff --git a/frontend/src/components/Release/ReleaseDetail/ReleaseFileTable/ReleaseFileDetailPanel.vue b/frontend/src/components/Release/ReleaseDetail/ReleaseFileTable/ReleaseFileDetailPanel.vue
index 69fc33930f..ca83b08475 100644
--- a/frontend/src/components/Release/ReleaseDetail/ReleaseFileTable/ReleaseFileDetailPanel.vue
+++ b/frontend/src/components/Release/ReleaseDetail/ReleaseFileTable/ReleaseFileDetailPanel.vue
@@ -29,7 +29,7 @@
</p>
<MonacoEditor
class="h-auto max-h-[480px] min-h-[120px] border rounded-[3px] text-sm overflow-clip relative"
- :content="releaseFile.statement"
+ :content="statement"
:readonly="true"
:auto-height="{ min: 120, max: 480 }"
/>
@@ -39,19 +39,22 @@
<script lang="ts" setup>
import { ClipboardIcon } from "lucide-vue-next";
import { NDivider } from "naive-ui";
+import { computed } from "vue";
import { MonacoEditor } from "@/components/MonacoEditor";
import { pushNotification } from "@/store";
import { type ComposedRelease } from "@/types";
import type { Release_File } from "@/types/proto/v1/release_service";
-import { toClipboard } from "@/utils";
+import { getReleaseFileStatement, toClipboard } from "@/utils";
const props = defineProps<{
release: ComposedRelease;
releaseFile: Release_File;
}>();
+const statement = computed(() => getReleaseFileStatement(props.releaseFile));
+
const copyStatement = async () => {
- toClipboard(props.releaseFile.statement).then(() => {
+ toClipboard(statement.value).then(() => {
pushNotification({
module: "bytebase",
style: "SUCCESS",
diff --git a/frontend/src/components/Release/ReleaseDetail/ReleaseFileTable/ReleaseFileTable.vue b/frontend/src/components/Release/ReleaseDetail/ReleaseFileTable/ReleaseFileTable.vue
index 250956f419..6e18c62dc2 100644
--- a/frontend/src/components/Release/ReleaseDetail/ReleaseFileTable/ReleaseFileTable.vue
+++ b/frontend/src/components/Release/ReleaseDetail/ReleaseFileTable/ReleaseFileTable.vue
@@ -15,7 +15,7 @@ import { NDataTable, type DataTableColumn } from "naive-ui";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { Release_File } from "@/types/proto/v1/release_service";
-import { bytesToString } from "@/utils";
+import { bytesToString, getReleaseFileStatement } from "@/utils";
const props = withDefaults(
defineProps<{
@@ -77,7 +77,7 @@ const columnList = computed(() => {
key: "statement",
title: t("common.statement"),
ellipsis: true,
- render: (file) => file.statement,
+ render: (file) => getReleaseFileStatement(file),
},
];
return columns.filter((column) => !column.hide);
diff --git a/frontend/src/components/SQLCheck/SQLCheckButton.vue b/frontend/src/components/SQLCheck/SQLCheckButton.vue
index f1867b4ef1..e8247ff8df 100644
--- a/frontend/src/components/SQLCheck/SQLCheckButton.vue
+++ b/frontend/src/components/SQLCheck/SQLCheckButton.vue
@@ -164,7 +164,7 @@ const runCheckInternal = async (statement: string) => {
// Use a random uuid to avoid duplication.
version: uuidv4(),
type: ReleaseFileType.VERSIONED,
- statement: statement,
+ statement: new TextEncoder().encode(statement),
// Default to DDL change type.
changeType: changeType || Release_File_ChangeType.DDL,
},
diff --git a/frontend/src/types/proto/v1/release_service.ts b/frontend/src/types/proto/v1/release_service.ts
index 117be533b1..153bbfcd83 100644
--- a/frontend/src/types/proto/v1/release_service.ts
+++ b/frontend/src/types/proto/v1/release_service.ts
@@ -269,7 +269,7 @@ export interface Release_File {
version: string;
changeType: Release_File_ChangeType;
/** The statement is used for preview or check purpose. */
- statement: string;
+ statement: Uint8Array;
statementSize: Long;
}
@@ -1353,7 +1353,7 @@ function createBaseRelease_File(): Release_File {
type: ReleaseFileType.TYPE_UNSPECIFIED,
version: "",
changeType: Release_File_ChangeType.CHANGE_TYPE_UNSPECIFIED,
- statement: "",
+ statement: new Uint8Array(0),
statementSize: Long.ZERO,
};
}
@@ -1381,8 +1381,8 @@ export const Release_File: MessageFns<Release_File> = {
if (message.changeType !== Release_File_ChangeType.CHANGE_TYPE_UNSPECIFIED) {
writer.uint32(72).int32(release_File_ChangeTypeToNumber(message.changeType));
}
- if (message.statement !== "") {
- writer.uint32(58).string(message.statement);
+ if (message.statement.length !== 0) {
+ writer.uint32(58).bytes(message.statement);
}
if (!message.statementSize.equals(Long.ZERO)) {
writer.uint32(64).int64(message.statementSize.toString());
@@ -1458,7 +1458,7 @@ export const Release_File: MessageFns<Release_File> = {
break;
}
- message.statement = reader.string();
+ message.statement = reader.bytes();
continue;
}
case 8: {
@@ -1489,7 +1489,7 @@ export const Release_File: MessageFns<Release_File> = {
changeType: isSet(object.changeType)
? release_File_ChangeTypeFromJSON(object.changeType)
: Release_File_ChangeType.CHANGE_TYPE_UNSPECIFIED,
- statement: isSet(object.statement) ? globalThis.String(object.statement) : "",
+ statement: isSet(object.statement) ? bytesFromBase64(object.statement) : new Uint8Array(0),
statementSize: isSet(object.statementSize) ? Long.fromValue(object.statementSize) : Long.ZERO,
};
},
@@ -1517,8 +1517,8 @@ export const Release_File: MessageFns<Release_File> = {
if (message.changeType !== Release_File_ChangeType.CHANGE_TYPE_UNSPECIFIED) {
obj.changeType = release_File_ChangeTypeToJSON(message.changeType);
}
- if (message.statement !== "") {
- obj.statement = message.statement;
+ if (message.statement.length !== 0) {
+ obj.statement = base64FromBytes(message.statement);
}
if (!message.statementSize.equals(Long.ZERO)) {
obj.statementSize = (message.statementSize || Long.ZERO).toString();
@@ -1538,7 +1538,7 @@ export const Release_File: MessageFns<Release_File> = {
message.type = object.type ?? ReleaseFileType.TYPE_UNSPECIFIED;
message.version = object.version ?? "";
message.changeType = object.changeType ?? Release_File_ChangeType.CHANGE_TYPE_UNSPECIFIED;
- message.statement = object.statement ?? "";
+ message.statement = object.statement ?? new Uint8Array(0);
message.statementSize = (object.statementSize !== undefined && object.statementSize !== null)
? Long.fromValue(object.statementSize)
: Long.ZERO;
@@ -2096,6 +2096,23 @@ export const ReleaseServiceDefinition = {
},
} as const;
+function bytesFromBase64(b64: string): Uint8Array {
+ const bin = globalThis.atob(b64);
+ const arr = new Uint8Array(bin.length);
+ for (let i = 0; i < bin.length; ++i) {
+ arr[i] = bin.charCodeAt(i);
+ }
+ return arr;
+}
+
+function base64FromBytes(arr: Uint8Array): string {
+ const bin: string[] = [];
+ arr.forEach((byte) => {
+ bin.push(globalThis.String.fromCharCode(byte));
+ });
+ return globalThis.btoa(bin.join(""));
+}
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
export type DeepPartial<T> = T extends Builtin ? T
diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts
index 2942c9aa64..dbb9848988 100644
--- a/frontend/src/utils/index.ts
+++ b/frontend/src/utils/index.ts
@@ -22,6 +22,7 @@ export * from "./TinyTimer";
export * from "./sheet";
export * from "./naive-ui";
export * from "./useDashboardSidebar";
+export * from "./release";
export * from "./v1";
export * from "./iam";
diff --git a/frontend/src/utils/release.ts b/frontend/src/utils/release.ts
new file mode 100644
index 0000000000..f0223c8da6
--- /dev/null
+++ b/frontend/src/utils/release.ts
@@ -0,0 +1,5 @@
+import type { Release_File } from "@/types/proto/v1/release_service";
+
+export const getReleaseFileStatement = (file: Release_File) => {
+ return new TextDecoder().decode(file.statement);
+};
diff --git a/proto/gen/grpc-doc/openapi.yaml b/proto/gen/grpc-doc/openapi.yaml
index 3d5bf2c253..d7e8b288b8 100644
--- a/proto/gen/grpc-doc/openapi.yaml
+++ b/proto/gen/grpc-doc/openapi.yaml
@@ -11883,6 +11883,7 @@ components:
statement:
type: string
description: The statement is used for preview or check purpose.
+ format: bytes
statementSize:
readOnly: true
type: string
diff --git a/proto/gen/grpc-doc/v1/README.md b/proto/gen/grpc-doc/v1/README.md
index bb96851381..278ce52e01 100644
--- a/proto/gen/grpc-doc/v1/README.md
+++ b/proto/gen/grpc-doc/v1/README.md
@@ -9358,7 +9358,7 @@ When paginating, all other parameters provided to `ListReleases` must match the
| type | [ReleaseFileType](#bytebase-v1-ReleaseFileType) | | |
| version | [string](#string) | | |
| change_type | [Release.File.ChangeType](#bytebase-v1-Release-File-ChangeType) | | |
-| statement | [string](#string) | | The statement is used for preview or check purpose. |
+| statement | [bytes](#bytes) | | The statement is used for preview or check purpose. |
| statement_size | [int64](#int64) | | |
diff --git a/proto/gen/grpc-doc/v1/index.html b/proto/gen/grpc-doc/v1/index.html
index 7b4eed073f..3554c1903c 100644
--- a/proto/gen/grpc-doc/v1/index.html
+++ b/proto/gen/grpc-doc/v1/index.html
@@ -25979,7 +25979,7 @@ Format: projects/{project}/sheets/{sheet} </p></td>
<tr>
<td>statement</td>
- <td><a href="#string">string</a></td>
+ <td><a href="#bytes">bytes</a></td>
<td></td>
<td><p>The statement is used for preview or check purpose. </p></td>
</tr>
diff --git a/proto/generated-go/v1/release_service.pb.go b/proto/generated-go/v1/release_service.pb.go
index 6cf51445b9..43e24350aa 100644
--- a/proto/generated-go/v1/release_service.pb.go
+++ b/proto/generated-go/v1/release_service.pb.go
@@ -873,7 +873,7 @@ type Release_File struct {
Version string `protobuf:"bytes,6,opt,name=version,proto3" json:"version,omitempty"`
ChangeType Release_File_ChangeType `protobuf:"varint,9,opt,name=change_type,json=changeType,proto3,enum=bytebase.v1.Release_File_ChangeType" json:"change_type,omitempty"`
// The statement is used for preview or check purpose.
- Statement string `protobuf:"bytes,7,opt,name=statement,proto3" json:"statement,omitempty"`
+ Statement []byte `protobuf:"bytes,7,opt,name=statement,proto3" json:"statement,omitempty"`
StatementSize int64 `protobuf:"varint,8,opt,name=statement_size,json=statementSize,proto3" json:"statement_size,omitempty"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
@@ -958,11 +958,11 @@ func (x *Release_File) GetChangeType() Release_File_ChangeType {
return Release_File_CHANGE_TYPE_UNSPECIFIED
}
-func (x *Release_File) GetStatement() string {
+func (x *Release_File) GetStatement() []byte {
if x != nil {
return x.Statement
}
- return ""
+ return nil
}
func (x *Release_File) GetStatementSize() int64 {
@@ -1099,7 +1099,7 @@ const file_v1_release_service_proto_rawDesc = "" +
"\aversion\x18\x06 \x01(\tR\aversion\x12E\n" +
"\vchange_type\x18\t \x01(\x0e2$.bytebase.v1.Release.File.ChangeTypeR\n" +
"changeType\x12\x1c\n" +
- "\tstatement\x18\a \x01(\tR\tstatement\x12+\n" +
+ "\tstatement\x18\a \x01(\fR\tstatement\x12+\n" +
"\x0estatement_size\x18\b \x01(\x03B\x04\xe2A\x01\x03R\rstatementSize\"J\n" +
"\n" +
"ChangeType\x12\x1b\n" +
diff --git a/proto/v1/release_service.proto b/proto/v1/release_service.proto
index 4027ea1e35..0c7170e7c1 100644
--- a/proto/v1/release_service.proto
+++ b/proto/v1/release_service.proto
@@ -233,7 +233,7 @@ message Release {
ChangeType change_type = 9;
// The statement is used for preview or check purpose.
- string statement = 7;
+ bytes statement = 7;
int64 statement_size = 8 [(google.api.field_behavior) = OUTPUT_ONLY];
enum ChangeType {