Skip to content

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

refactor: use wrappers instead of the hasDefault and Default (#3940)

rebelice20e787ed4984
diff --git a/frontend/src/types/proto/database.ts b/frontend/src/types/proto/database.ts
index d7480379a1..bc4e12af9d 100644
--- a/frontend/src/types/proto/database.ts
+++ b/frontend/src/types/proto/database.ts
@@ -1,6 +1,7 @@
/* eslint-disable */
import Long from "long";
import _m0 from "protobufjs/minimal";
+import { StringValue } from "./google/protobuf/wrappers";
export const protobufPackage = "bytebase.store";
@@ -67,14 +68,8 @@ export interface ColumnMetadata {
name: string;
/** The position is the position in columns. */
position: number;
- /**
- * The has_default is whether a column has a default.
- * In proto3, we cannot distinguish between an empty string default value or no default.
- * We have to introduce a boolean field to indicate the existance of a default.
- */
- hasDefault: boolean;
- /** The default is the default of a column. */
- default: string;
+ /** The default is the default of a column. Use google.protobuf.StringValue to distinguish between an empty string default value or no default. */
+ default?: string;
/** The nullable is the nullable of a column. */
nullable: boolean;
/** The type is the type of a column. */
@@ -506,8 +501,7 @@ function createBaseColumnMetadata(): ColumnMetadata {
return {
name: "",
position: 0,
- hasDefault: false,
- default: "",
+ default: undefined,
nullable: false,
type: "",
characterSet: "",
@@ -524,26 +518,23 @@ export const ColumnMetadata = {
if (message.position !== 0) {
writer.uint32(16).int32(message.position);
}
- if (message.hasDefault === true) {
- writer.uint32(24).bool(message.hasDefault);
- }
- if (message.default !== "") {
- writer.uint32(34).string(message.default);
+ if (message.default !== undefined) {
+ StringValue.encode({ value: message.default! }, writer.uint32(26).fork()).ldelim();
}
if (message.nullable === true) {
- writer.uint32(40).bool(message.nullable);
+ writer.uint32(32).bool(message.nullable);
}
if (message.type !== "") {
- writer.uint32(50).string(message.type);
+ writer.uint32(42).string(message.type);
}
if (message.characterSet !== "") {
- writer.uint32(58).string(message.characterSet);
+ writer.uint32(50).string(message.characterSet);
}
if (message.collation !== "") {
- writer.uint32(66).string(message.collation);
+ writer.uint32(58).string(message.collation);
}
if (message.comment !== "") {
- writer.uint32(74).string(message.comment);
+ writer.uint32(66).string(message.comment);
}
return writer;
},
@@ -562,24 +553,21 @@ export const ColumnMetadata = {
message.position = reader.int32();
break;
case 3:
- message.hasDefault = reader.bool();
+ message.default = StringValue.decode(reader, reader.uint32()).value;
break;
case 4:
- message.default = reader.string();
- break;
- case 5:
message.nullable = reader.bool();
break;
- case 6:
+ case 5:
message.type = reader.string();
break;
- case 7:
+ case 6:
message.characterSet = reader.string();
break;
- case 8:
+ case 7:
message.collation = reader.string();
break;
- case 9:
+ case 8:
message.comment = reader.string();
break;
default:
@@ -594,8 +582,7 @@ export const ColumnMetadata = {
return {
name: isSet(object.name) ? String(object.name) : "",
position: isSet(object.position) ? Number(object.position) : 0,
- hasDefault: isSet(object.hasDefault) ? Boolean(object.hasDefault) : false,
- default: isSet(object.default) ? String(object.default) : "",
+ default: isSet(object.default) ? String(object.default) : undefined,
nullable: isSet(object.nullable) ? Boolean(object.nullable) : false,
type: isSet(object.type) ? String(object.type) : "",
characterSet: isSet(object.characterSet) ? String(object.characterSet) : "",
@@ -608,7 +595,6 @@ export const ColumnMetadata = {
const obj: any = {};
message.name !== undefined && (obj.name = message.name);
message.position !== undefined && (obj.position = Math.round(message.position));
- message.hasDefault !== undefined && (obj.hasDefault = message.hasDefault);
message.default !== undefined && (obj.default = message.default);
message.nullable !== undefined && (obj.nullable = message.nullable);
message.type !== undefined && (obj.type = message.type);
@@ -622,8 +608,7 @@ export const ColumnMetadata = {
const message = createBaseColumnMetadata();
message.name = object.name ?? "";
message.position = object.position ?? 0;
- message.hasDefault = object.hasDefault ?? false;
- message.default = object.default ?? "";
+ message.default = object.default ?? undefined;
message.nullable = object.nullable ?? false;
message.type = object.type ?? "";
message.characterSet = object.characterSet ?? "";
diff --git a/frontend/src/types/proto/google/protobuf/wrappers.ts b/frontend/src/types/proto/google/protobuf/wrappers.ts
new file mode 100644
index 0000000000..c45f90c7ca
--- /dev/null
+++ b/frontend/src/types/proto/google/protobuf/wrappers.ts
@@ -0,0 +1,590 @@
+/* eslint-disable */
+import Long from "long";
+import _m0 from "protobufjs/minimal";
+
+export const protobufPackage = "google.protobuf";
+
+/**
+ * Wrapper message for `double`.
+ *
+ * The JSON representation for `DoubleValue` is JSON number.
+ */
+export interface DoubleValue {
+ /** The double value. */
+ value: number;
+}
+
+/**
+ * Wrapper message for `float`.
+ *
+ * The JSON representation for `FloatValue` is JSON number.
+ */
+export interface FloatValue {
+ /** The float value. */
+ value: number;
+}
+
+/**
+ * Wrapper message for `int64`.
+ *
+ * The JSON representation for `Int64Value` is JSON string.
+ */
+export interface Int64Value {
+ /** The int64 value. */
+ value: number;
+}
+
+/**
+ * Wrapper message for `uint64`.
+ *
+ * The JSON representation for `UInt64Value` is JSON string.
+ */
+export interface UInt64Value {
+ /** The uint64 value. */
+ value: number;
+}
+
+/**
+ * Wrapper message for `int32`.
+ *
+ * The JSON representation for `Int32Value` is JSON number.
+ */
+export interface Int32Value {
+ /** The int32 value. */
+ value: number;
+}
+
+/**
+ * Wrapper message for `uint32`.
+ *
+ * The JSON representation for `UInt32Value` is JSON number.
+ */
+export interface UInt32Value {
+ /** The uint32 value. */
+ value: number;
+}
+
+/**
+ * Wrapper message for `bool`.
+ *
+ * The JSON representation for `BoolValue` is JSON `true` and `false`.
+ */
+export interface BoolValue {
+ /** The bool value. */
+ value: boolean;
+}
+
+/**
+ * Wrapper message for `string`.
+ *
+ * The JSON representation for `StringValue` is JSON string.
+ */
+export interface StringValue {
+ /** The string value. */
+ value: string;
+}
+
+/**
+ * Wrapper message for `bytes`.
+ *
+ * The JSON representation for `BytesValue` is JSON string.
+ */
+export interface BytesValue {
+ /** The bytes value. */
+ value: Uint8Array;
+}
+
+function createBaseDoubleValue(): DoubleValue {
+ return { value: 0 };
+}
+
+export const DoubleValue = {
+ encode(message: DoubleValue, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
+ if (message.value !== 0) {
+ writer.uint32(9).double(message.value);
+ }
+ return writer;
+ },
+
+ decode(input: _m0.Reader | Uint8Array, length?: number): DoubleValue {
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
+ let end = length === undefined ? reader.len : reader.pos + length;
+ const message = createBaseDoubleValue();
+ while (reader.pos < end) {
+ const tag = reader.uint32();
+ switch (tag >>> 3) {
+ case 1:
+ message.value = reader.double();
+ break;
+ default:
+ reader.skipType(tag & 7);
+ break;
+ }
+ }
+ return message;
+ },
+
+ fromJSON(object: any): DoubleValue {
+ return { value: isSet(object.value) ? Number(object.value) : 0 };
+ },
+
+ toJSON(message: DoubleValue): unknown {
+ const obj: any = {};
+ message.value !== undefined && (obj.value = message.value);
+ return obj;
+ },
+
+ fromPartial<I extends Exact<DeepPartial<DoubleValue>, I>>(object: I): DoubleValue {
+ const message = createBaseDoubleValue();
+ message.value = object.value ?? 0;
+ return message;
+ },
+};
+
+function createBaseFloatValue(): FloatValue {
+ return { value: 0 };
+}
+
+export const FloatValue = {
+ encode(message: FloatValue, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
+ if (message.value !== 0) {
+ writer.uint32(13).float(message.value);
+ }
+ return writer;
+ },
+
+ decode(input: _m0.Reader | Uint8Array, length?: number): FloatValue {
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
+ let end = length === undefined ? reader.len : reader.pos + length;
+ const message = createBaseFloatValue();
+ while (reader.pos < end) {
+ const tag = reader.uint32();
+ switch (tag >>> 3) {
+ case 1:
+ message.value = reader.float();
+ break;
+ default:
+ reader.skipType(tag & 7);
+ break;
+ }
+ }
+ return message;
+ },
+
+ fromJSON(object: any): FloatValue {
+ return { value: isSet(object.value) ? Number(object.value) : 0 };
+ },
+
+ toJSON(message: FloatValue): unknown {
+ const obj: any = {};
+ message.value !== undefined && (obj.value = message.value);
+ return obj;
+ },
+
+ fromPartial<I extends Exact<DeepPartial<FloatValue>, I>>(object: I): FloatValue {
+ const message = createBaseFloatValue();
+ message.value = object.value ?? 0;
+ return message;
+ },
+};
+
+function createBaseInt64Value(): Int64Value {
+ return { value: 0 };
+}
+
+export const Int64Value = {
+ encode(message: Int64Value, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
+ if (message.value !== 0) {
+ writer.uint32(8).int64(message.value);
+ }
+ return writer;
+ },
+
+ decode(input: _m0.Reader | Uint8Array, length?: number): Int64Value {
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
+ let end = length === undefined ? reader.len : reader.pos + length;
+ const message = createBaseInt64Value();
+ while (reader.pos < end) {
+ const tag = reader.uint32();
+ switch (tag >>> 3) {
+ case 1:
+ message.value = longToNumber(reader.int64() as Long);
+ break;
+ default:
+ reader.skipType(tag & 7);
+ break;
+ }
+ }
+ return message;
+ },
+
+ fromJSON(object: any): Int64Value {
+ return { value: isSet(object.value) ? Number(object.value) : 0 };
+ },
+
+ toJSON(message: Int64Value): unknown {
+ const obj: any = {};
+ message.value !== undefined && (obj.value = Math.round(message.value));
+ return obj;
+ },
+
+ fromPartial<I extends Exact<DeepPartial<Int64Value>, I>>(object: I): Int64Value {
+ const message = createBaseInt64Value();
+ message.value = object.value ?? 0;
+ return message;
+ },
+};
+
+function createBaseUInt64Value(): UInt64Value {
+ return { value: 0 };
+}
+
+export const UInt64Value = {
+ encode(message: UInt64Value, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
+ if (message.value !== 0) {
+ writer.uint32(8).uint64(message.value);
+ }
+ return writer;
+ },
+
+ decode(input: _m0.Reader | Uint8Array, length?: number): UInt64Value {
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
+ let end = length === undefined ? reader.len : reader.pos + length;
+ const message = createBaseUInt64Value();
+ while (reader.pos < end) {
+ const tag = reader.uint32();
+ switch (tag >>> 3) {
+ case 1:
+ message.value = longToNumber(reader.uint64() as Long);
+ break;
+ default:
+ reader.skipType(tag & 7);
+ break;
+ }
+ }
+ return message;
+ },
+
+ fromJSON(object: any): UInt64Value {
+ return { value: isSet(object.value) ? Number(object.value) : 0 };
+ },
+
+ toJSON(message: UInt64Value): unknown {
+ const obj: any = {};
+ message.value !== undefined && (obj.value = Math.round(message.value));
+ return obj;
+ },
+
+ fromPartial<I extends Exact<DeepPartial<UInt64Value>, I>>(object: I): UInt64Value {
+ const message = createBaseUInt64Value();
+ message.value = object.value ?? 0;
+ return message;
+ },
+};
+
+function createBaseInt32Value(): Int32Value {
+ return { value: 0 };
+}
+
+export const Int32Value = {
+ encode(message: Int32Value, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
+ if (message.value !== 0) {
+ writer.uint32(8).int32(message.value);
+ }
+ return writer;
+ },
+
+ decode(input: _m0.Reader | Uint8Array, length?: number): Int32Value {
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
+ let end = length === undefined ? reader.len : reader.pos + length;
+ const message = createBaseInt32Value();
+ while (reader.pos < end) {
+ const tag = reader.uint32();
+ switch (tag >>> 3) {
+ case 1:
+ message.value = reader.int32();
+ break;
+ default:
+ reader.skipType(tag & 7);
+ break;
+ }
+ }
+ return message;
+ },
+
+ fromJSON(object: any): Int32Value {
+ return { value: isSet(object.value) ? Number(object.value) : 0 };
+ },
+
+ toJSON(message: Int32Value): unknown {
+ const obj: any = {};
+ message.value !== undefined && (obj.value = Math.round(message.value));
+ return obj;
+ },
+
+ fromPartial<I extends Exact<DeepPartial<Int32Value>, I>>(object: I): Int32Value {
+ const message = createBaseInt32Value();
+ message.value = object.value ?? 0;
+ return message;
+ },
+};
+
+function createBaseUInt32Value(): UInt32Value {
+ return { value: 0 };
+}
+
+export const UInt32Value = {
+ encode(message: UInt32Value, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
+ if (message.value !== 0) {
+ writer.uint32(8).uint32(message.value);
+ }
+ return writer;
+ },
+
+ decode(input: _m0.Reader | Uint8Array, length?: number): UInt32Value {
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
+ let end = length === undefined ? reader.len : reader.pos + length;
+ const message = createBaseUInt32Value();
+ while (reader.pos < end) {
+ const tag = reader.uint32();
+ switch (tag >>> 3) {
+ case 1:
+ message.value = reader.uint32();
+ break;
+ default:
+ reader.skipType(tag & 7);
+ break;
+ }
+ }
+ return message;
+ },
+
+ fromJSON(object: any): UInt32Value {
+ return { value: isSet(object.value) ? Number(object.value) : 0 };
+ },
+
+ toJSON(message: UInt32Value): unknown {
+ const obj: any = {};
+ message.value !== undefined && (obj.value = Math.round(message.value));
+ return obj;
+ },
+
+ fromPartial<I extends Exact<DeepPartial<UInt32Value>, I>>(object: I): UInt32Value {
+ const message = createBaseUInt32Value();
+ message.value = object.value ?? 0;
+ return message;
+ },
+};
+
+function createBaseBoolValue(): BoolValue {
+ return { value: false };
+}
+
+export const BoolValue = {
+ encode(message: BoolValue, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
+ if (message.value === true) {
+ writer.uint32(8).bool(message.value);
+ }
+ return writer;
+ },
+
+ decode(input: _m0.Reader | Uint8Array, length?: number): BoolValue {
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
+ let end = length === undefined ? reader.len : reader.pos + length;
+ const message = createBaseBoolValue();
+ while (reader.pos < end) {
+ const tag = reader.uint32();
+ switch (tag >>> 3) {
+ case 1:
+ message.value = reader.bool();
+ break;
+ default:
+ reader.skipType(tag & 7);
+ break;
+ }
+ }
+ return message;
+ },
+
+ fromJSON(object: any): BoolValue {
+ return { value: isSet(object.value) ? Boolean(object.value) : false };
+ },
+
+ toJSON(message: BoolValue): unknown {
+ const obj: any = {};
+ message.value !== undefined && (obj.value = message.value);
+ return obj;
+ },
+
+ fromPartial<I extends Exact<DeepPartial<BoolValue>, I>>(object: I): BoolValue {
+ const message = createBaseBoolValue();
+ message.value = object.value ?? false;
+ return message;
+ },
+};
+
+function createBaseStringValue(): StringValue {
+ return { value: "" };
+}
+
+export const StringValue = {
+ encode(message: StringValue, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
+ if (message.value !== "") {
+ writer.uint32(10).string(message.value);
+ }
+ return writer;
+ },
+
+ decode(input: _m0.Reader | Uint8Array, length?: number): StringValue {
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
+ let end = length === undefined ? reader.len : reader.pos + length;
+ const message = createBaseStringValue();
+ while (reader.pos < end) {
+ const tag = reader.uint32();
+ switch (tag >>> 3) {
+ case 1:
+ message.value = reader.string();
+ break;
+ default:
+ reader.skipType(tag & 7);
+ break;
+ }
+ }
+ return message;
+ },
+
+ fromJSON(object: any): StringValue {
+ return { value: isSet(object.value) ? String(object.value) : "" };
+ },
+
+ toJSON(message: StringValue): unknown {
+ const obj: any = {};
+ message.value !== undefined && (obj.value = message.value);
+ return obj;
+ },
+
+ fromPartial<I extends Exact<DeepPartial<StringValue>, I>>(object: I): StringValue {
+ const message = createBaseStringValue();
+ message.value = object.value ?? "";
+ return message;
+ },
+};
+
+function createBaseBytesValue(): BytesValue {
+ return { value: new Uint8Array() };
+}
+
+export const BytesValue = {
+ encode(message: BytesValue, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
+ if (message.value.length !== 0) {
+ writer.uint32(10).bytes(message.value);
+ }
+ return writer;
+ },
+
+ decode(input: _m0.Reader | Uint8Array, length?: number): BytesValue {
+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
+ let end = length === undefined ? reader.len : reader.pos + length;
+ const message = createBaseBytesValue();
+ while (reader.pos < end) {
+ const tag = reader.uint32();
+ switch (tag >>> 3) {
+ case 1:
+ message.value = reader.bytes();
+ break;
+ default:
+ reader.skipType(tag & 7);
+ break;
+ }
+ }
+ return message;
+ },
+
+ fromJSON(object: any): BytesValue {
+ return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array() };
+ },
+
+ toJSON(message: BytesValue): unknown {
+ const obj: any = {};
+ message.value !== undefined &&
+ (obj.value = base64FromBytes(message.value !== undefined ? message.value : new Uint8Array()));
+ return obj;
+ },
+
+ fromPartial<I extends Exact<DeepPartial<BytesValue>, I>>(object: I): BytesValue {
+ const message = createBaseBytesValue();
+ message.value = object.value ?? new Uint8Array();
+ return message;
+ },
+};
+
+declare var self: any | undefined;
+declare var window: any | undefined;
+declare var global: any | undefined;
+var globalThis: any = (() => {
+ if (typeof globalThis !== "undefined") {
+ return globalThis;
+ }
+ if (typeof self !== "undefined") {
+ return self;
+ }
+ if (typeof window !== "undefined") {
+ return window;
+ }
+ if (typeof global !== "undefined") {
+ return global;
+ }
+ throw "Unable to locate global object";
+})();
+
+function bytesFromBase64(b64: string): Uint8Array {
+ if (globalThis.Buffer) {
+ return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
+ } else {
+ 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 {
+ if (globalThis.Buffer) {
+ return globalThis.Buffer.from(arr).toString("base64");
+ } else {
+ const bin: string[] = [];
+ arr.forEach((byte) => {
+ bin.push(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
+ : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
+ : T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
+ : Partial<T>;
+
+type KeysOfUnion<T> = T extends T ? keyof T : never;
+export type Exact<P, I extends P> = P extends Builtin ? P
+ : P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };
+
+function longToNumber(long: Long): number {
+ if (long.gt(Number.MAX_SAFE_INTEGER)) {
+ throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
+ }
+ return long.toNumber();
+}
+
+if (_m0.util.Long !== Long) {
+ _m0.util.Long = Long as any;
+ _m0.configure();
+}
+
+function isSet(value: any): boolean {
+ return value !== null && value !== undefined;
+}
diff --git a/frontend/src/utils/schemaEditor/transform.ts b/frontend/src/utils/schemaEditor/transform.ts
index d08998373c..4f009c12b1 100644
--- a/frontend/src/utils/schemaEditor/transform.ts
+++ b/frontend/src/utils/schemaEditor/transform.ts
@@ -37,8 +37,8 @@ export const transformColumnDataToColumn = (
type: columnMetadata.type,
nullable: columnMetadata.nullable,
comment: columnMetadata.comment,
- hasDefault: columnMetadata.hasDefault,
- default: columnMetadata.default,
+ hasDefault: columnMetadata.default !== undefined,
+ default: columnMetadata.default === undefined ? "" : columnMetadata.default,
status: "normal",
};
};
diff --git a/plugin/advisor/catalog/state.go b/plugin/advisor/catalog/state.go
index 5e70aeed07..a8cd2afe0d 100644
--- a/plugin/advisor/catalog/state.go
+++ b/plugin/advisor/catalog/state.go
@@ -78,8 +78,8 @@ func newTableState(t *storepb.TableMetadata) *TableState {
func newColumnState(c *storepb.ColumnMetadata, position int) *ColumnState {
defaultValue := (*string)(nil)
- if c.HasDefault {
- defaultValue = copyStringPointer(&c.Default)
+ if c.Default != nil {
+ defaultValue = copyStringPointer(&c.Default.Value)
}
return &ColumnState{
name: c.Name,
diff --git a/plugin/advisor/catalog/test/mysql_walk_through.yaml b/plugin/advisor/catalog/test/mysql_walk_through.yaml
index f3971f7f3a..40b6cb32cf 100644
--- a/plugin/advisor/catalog/test/mysql_walk_through.yaml
+++ b/plugin/advisor/catalog/test/mysql_walk_through.yaml
@@ -120,8 +120,8 @@
columns:
- name: a
position: 1
- hasdefault: true
- default: "1"
+ default:
+ value: "1"
nullable: false
type: int(11)
characterset: ""
@@ -129,8 +129,7 @@
comment: ""
- name: b
position: 2
- hasdefault: false
- default: ""
+ default: null
nullable: false
type: varchar(200)
characterset: utf8mb4
@@ -138,8 +137,7 @@
comment: ""
- name: c
position: 3
- hasdefault: false
- default: ""
+ default: null
nullable: true
type: int(11)
characterset: ""
@@ -147,8 +145,7 @@
comment: This is a comment
- name: d
position: 4
- hasdefault: false
- default: ""
+ default: null
nullable: true
type: varchar(10)
characterset: ""
@@ -220,8 +217,8 @@
columns:
- name: a
position: 1
- hasdefault: true
- default: "1"
+ default:
+ value: "1"
nullable: false
type: int(11)
characterset: ""
@@ -229,8 +226,7 @@
comment: ""
- name: b
position: 2
- hasdefault: false
- default: ""
+ default: null
nullable: false
type: varchar(200)
characterset: utf8mb4
@@ -238,8 +234,7 @@
comment: ""
- name: c
position: 3
- hasdefault: false
- default: ""
+ default: null
nullable: true
type: int(11)
characterset: ""
@@ -247,8 +242,7 @@
comment: This is a comment
- name: d
position: 4
- hasdefault: false
- default: ""
+ default: null
nullable: true
type: varchar(10)
characterset: ""
@@ -341,8 +335,8 @@
columns:
- name: a
position: 1
- hasdefault: true
- default: "1"
+ default:
+ value: "1"
nullable: false
type: int(11)
characterset: ""
@@ -350,8 +344,7 @@
comment: ""
- name: b
position: 2
- hasdefault: false
- default: ""
+ default: null
nullable: false
type: varchar(200)
characterset: utf8mb4
@@ -359,8 +352,7 @@
comment: ""
- name: c
position: 3
- hasdefault: false
- default: ""
+ default: null
nullable: true
type: int(11)
characterset: ""
@@ -368,8 +360,7 @@
comment: This is a comment
- name: d
position: 4
- hasdefault: false
- default: ""
+ default: null
nullable: true
type: varchar(10)
characterset: ""
@@ -457,8 +448,7 @@
columns:
- name: a
position: 1
- hasdefault: false
- default: ""
+ default: null
nullable: false
type: int(11)
characterset: ""
@@ -466,8 +456,7 @@
comment: ""
- name: b
position: 2
- hasdefault: false
- default: ""
+ default: null
nullable: false
type: int(11)
characterset: ""
@@ -542,8 +531,7 @@
columns:
- name: a
position: 1
- hasdefault: false
- default: ""
+ default: null
nullable: true
type: int(11)
characterset: ""
@@ -607,8 +595,7 @@
columns:
- name: b
position: 1
- hasdefault: false
- default: ""
+ default: null
nullable: true
type: varchar(20)
characterset: ""
@@ -616,8 +603,7 @@
comment: ""
- name: a_copy
position: 2
- hasdefault: false
- default: ""
+ default: null
nullable: false
type: int(11)
characterset: ""
@@ -625,8 +611,7 @@
comment: ""
- name: a1
position: 3
- hasdefault: false
- default: ""
+ default: null
nullable: true
type: int(11)
characterset: ""
@@ -634,8 +619,7 @@
comment: ""
- name: d_copy
position: 4
- hasdefault: false
- default: ""
+ default: null
nullable: true
type: varchar(10)
characterset: ""
@@ -643,8 +627,7 @@
comment: ""
- name: e
position: 5
- hasdefault: false
- default: ""
+ default: null
nullable: true
type: int(11)
characterset: ""
@@ -728,8 +711,8 @@
columns:
- name: a
position: 1
- hasdefault: true
- default: "1"
+ default:
+ value: "1"
nullable: false
type: int(11)
characterset: ""
@@ -737,8 +720,7 @@
comment: ""
- name: b
position: 2
- hasdefault: false
- default: ""
+ default: null
nullable: false
type: varchar(200)
characterset: utf8mb4
@@ -746,8 +728,7 @@
comment: ""
- name: c
position: 3
- hasdefault: false
- default: ""
+ default: null
nullable: true
type: int(11)
characterset: ""
@@ -755,8 +736,7 @@
comment: This is a comment
- name: d
position: 4
- hasdefault: false
- default: ""
+ default: null
nullable: true
type: varchar(10)
characterset: ""
@@ -844,8 +824,8 @@
columns:
- name: a
position: 1
- hasdefault: true
- default: "1"
+ default:
+ value: "1"
nullable: false
type: int(11)
characterset: ""
@@ -853,8 +833,7 @@
comment: ""
- name: b
position: 2
- hasdefault: false
- default: ""
+ default: null
nullable: false
type: varchar(200)
characterset: utf8mb4
diff --git a/plugin/advisor/catalog/test/mysql_walk_through_for_incomplete.yaml b/plugin/advisor/catalog/test/mysql_walk_through_for_incomplete.yaml
index 9a24fb056c..c561c82aba 100644
--- a/plugin/advisor/catalog/test/mysql_walk_through_for_incomplete.yaml
+++ b/plugin/advisor/catalog/test/mysql_walk_through_for_incomplete.yaml
@@ -39,8 +39,7 @@
columns:
- name: a_copy
position: 0
- hasdefault: false
- default: ""
+ default: null
nullable: false
type: ""
characterset: ""
@@ -85,12 +84,12 @@
extensions: []
err: null
- statement: |4-
- ALTER TABLE t ADD PRIMARY KEY (a);
- ALTER TABLE t ADD UNIQUE (b);
- CREATE INDEX idx_a on t(a);
- CREATE INDEX b_2 on t(b, a);
- CREATE UNIQUE INDEX b_3 on t(b, c, d);
- CREATE FULLTEXT INDEX b_4 on t(b, d) WITH PARSER ngram INVISIBLE;
+ ALTER TABLE t ADD PRIMARY KEY (a);
+ ALTER TABLE t ADD UNIQUE (b);
+ CREATE INDEX idx_a on t(a);
+ CREATE INDEX b_2 on t(b, a);
+ CREATE UNIQUE INDEX b_3 on t(b, c, d);
+ CREATE FULLTEXT INDEX b_4 on t(b, d) WITH PARSER ngram INVISIBLE;
want:
name: ""
schemas:
@@ -166,16 +165,16 @@
extensions: []
err: null
- statement: |4-
- CREATE TABLE t(
- a int PRIMARY KEY DEFAULT 1,
- b varchar(200) CHARACTER SET utf8mb4 NOT NULL UNIQUE,
- c int auto_increment NULL COMMENT 'This is a comment',
- d varchar(10) COLLATE utf8mb4_polish_ci,
- KEY idx_a (a),
- INDEX (b, a),
- UNIQUE (b, c, d),
- FULLTEXT (b, d) WITH PARSER ngram INVISIBLE
- )
+ CREATE TABLE t(
+ a int PRIMARY KEY DEFAULT 1,
+ b varchar(200) CHARACTER SET utf8mb4 NOT NULL UNIQUE,
+ c int auto_increment NULL COMMENT 'This is a comment',
+ d varchar(10) COLLATE utf8mb4_polish_ci,
+ KEY idx_a (a),
+ INDEX (b, a),
+ UNIQUE (b, c, d),
+ FULLTEXT (b, d) WITH PARSER ngram INVISIBLE
+ )
want:
name: ""
schemas:
@@ -185,8 +184,8 @@
columns:
- name: a
position: 1
- hasdefault: true
- default: "1"
+ default:
+ value: "1"
nullable: false
type: int(11)
characterset: ""
@@ -194,8 +193,7 @@
comment: ""
- name: b
position: 2
- hasdefault: false
- default: ""
+ default: null
nullable: false
type: varchar(200)
characterset: utf8mb4
@@ -203,8 +201,7 @@
comment: ""
- name: c
position: 3
- hasdefault: false
- default: ""
+ default: null
nullable: true
type: int(11)
characterset: ""
@@ -212,8 +209,7 @@
comment: This is a comment
- name: d
position: 4
- hasdefault: false
- default: ""
+ default: null
nullable: true
type: varchar(10)
characterset: ""
diff --git a/plugin/advisor/catalog/walk_through_test.go b/plugin/advisor/catalog/walk_through_test.go
index 044a694ab9..dcbae5c0e3 100644
--- a/plugin/advisor/catalog/walk_through_test.go
+++ b/plugin/advisor/catalog/walk_through_test.go
@@ -8,6 +8,7 @@ import (
"testing"
"github.com/stretchr/testify/require"
+ "google.golang.org/protobuf/types/known/wrapperspb"
"gopkg.in/yaml.v3"
"github.com/bytebase/bytebase/plugin/advisor/db"
@@ -212,8 +213,7 @@ func (t *TableState) convertToColumnMetadataList() []*storepb.ColumnMetadata {
}
if column.defaultValue != nil {
- columnMeta.HasDefault = true
- columnMeta.Default = *column.defaultValue
+ columnMeta.Default = &wrapperspb.StringValue{Value: *column.defaultValue}
}
if column.characterSet != nil {
diff --git a/proto/generated-go/store/database.pb.go b/proto/generated-go/store/database.pb.go
index 9273f487af..111336a632 100644
--- a/proto/generated-go/store/database.pb.go
+++ b/proto/generated-go/store/database.pb.go
@@ -9,6 +9,7 @@ package store
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
+ wrapperspb "google.golang.org/protobuf/types/known/wrapperspb"
reflect "reflect"
sync "sync"
)
@@ -331,22 +332,18 @@ type ColumnMetadata struct {
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
// The position is the position in columns.
Position int32 `protobuf:"varint,2,opt,name=position,proto3" json:"position,omitempty"`
- // The has_default is whether a column has a default.
- // In proto3, we cannot distinguish between an empty string default value or no default.
- // We have to introduce a boolean field to indicate the existance of a default.
- HasDefault bool `protobuf:"varint,3,opt,name=has_default,json=hasDefault,proto3" json:"has_default,omitempty"`
- // The default is the default of a column.
- Default string `protobuf:"bytes,4,opt,name=default,proto3" json:"default,omitempty"`
+ // The default is the default of a column. Use google.protobuf.StringValue to distinguish between an empty string default value or no default.
+ Default *wrapperspb.StringValue `protobuf:"bytes,3,opt,name=default,proto3" json:"default,omitempty"`
// The nullable is the nullable of a column.
- Nullable bool `protobuf:"varint,5,opt,name=nullable,proto3" json:"nullable,omitempty"`
+ Nullable bool `protobuf:"varint,4,opt,name=nullable,proto3" json:"nullable,omitempty"`
// The type is the type of a column.
- Type string `protobuf:"bytes,6,opt,name=type,proto3" json:"type,omitempty"`
+ Type string `protobuf:"bytes,5,opt,name=type,proto3" json:"type,omitempty"`
// The character_set is the character_set of a column.
- CharacterSet string `protobuf:"bytes,7,opt,name=character_set,json=characterSet,proto3" json:"character_set,omitempty"`
+ CharacterSet string `protobuf:"bytes,6,opt,name=character_set,json=characterSet,proto3" json:"character_set,omitempty"`
// The collation is the collation of a column.
- Collation string `protobuf:"bytes,8,opt,name=collation,proto3" json:"collation,omitempty"`
+ Collation string `protobuf:"bytes,7,opt,name=collation,proto3" json:"collation,omitempty"`
// The comment is the comment of a column.
- Comment string `protobuf:"bytes,9,opt,name=comment,proto3" json:"comment,omitempty"`
+ Comment string `protobuf:"bytes,8,opt,name=comment,proto3" json:"comment,omitempty"`
}
func (x *ColumnMetadata) Reset() {
@@ -395,18 +392,11 @@ func (x *ColumnMetadata) GetPosition() int32 {
return 0
}
-func (x *ColumnMetadata) GetHasDefault() bool {
- if x != nil {
- return x.HasDefault
- }
- return false
-}
-
-func (x *ColumnMetadata) GetDefault() string {
+func (x *ColumnMetadata) GetDefault() *wrapperspb.StringValue {
if x != nil {
return x.Default
}
- return ""
+ return nil
}
func (x *ColumnMetadata) GetNullable() bool {
@@ -811,7 +801,9 @@ var File_store_database_proto protoreflect.FileDescriptor
var file_store_database_proto_rawDesc = []byte{
0x0a, 0x14, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2f, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65,
0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65,
- 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x22, 0xe6, 0x01, 0x0a, 0x10, 0x44, 0x61, 0x74, 0x61, 0x62,
+ 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x1a, 0x1e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70,
+ 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x77, 0x72, 0x61, 0x70, 0x70, 0x65, 0x72, 0x73,
+ 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xe6, 0x01, 0x0a, 0x10, 0x44, 0x61, 0x74, 0x61, 0x62,
0x61, 0x73, 0x65, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x6e,
0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12,
0x38, 0x0a, 0x07, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b,
@@ -863,70 +855,70 @@ var file_store_database_proto_rawDesc = []byte{
0x67, 0x6e, 0x5f, 0x6b, 0x65, 0x79, 0x73, 0x18, 0x0c, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x22, 0x2e,
0x62, 0x79, 0x74, 0x65, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2e, 0x46,
0x6f, 0x72, 0x65, 0x69, 0x67, 0x6e, 0x4b, 0x65, 0x79, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74,
- 0x61, 0x52, 0x0b, 0x66, 0x6f, 0x72, 0x65, 0x69, 0x67, 0x6e, 0x4b, 0x65, 0x79, 0x73, 0x22, 0x88,
+ 0x61, 0x52, 0x0b, 0x66, 0x6f, 0x72, 0x65, 0x69, 0x67, 0x6e, 0x4b, 0x65, 0x79, 0x73, 0x22, 0x85,
0x02, 0x0a, 0x0e, 0x43, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74,
0x61, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f,
0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f,
- 0x6e, 0x12, 0x1f, 0x0a, 0x0b, 0x68, 0x61, 0x73, 0x5f, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74,
- 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x68, 0x61, 0x73, 0x44, 0x65, 0x66, 0x61, 0x75,
- 0x6c, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x18, 0x04, 0x20,
- 0x01, 0x28, 0x09, 0x52, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x12, 0x1a, 0x0a, 0x08,
- 0x6e, 0x75, 0x6c, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08,
- 0x6e, 0x75, 0x6c, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65,
- 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x23, 0x0a, 0x0d,
- 0x63, 0x68, 0x61, 0x72, 0x61, 0x63, 0x74, 0x65, 0x72, 0x5f, 0x73, 0x65, 0x74, 0x18, 0x07, 0x20,
- 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x68, 0x61, 0x72, 0x61, 0x63, 0x74, 0x65, 0x72, 0x53, 0x65,
- 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6f, 0x6c, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x08,
- 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x6f, 0x6c, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12,
- 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09,
- 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x5c, 0x0a, 0x0c, 0x56, 0x69, 0x65,
- 0x77, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d,
- 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1e, 0x0a,
- 0x0a, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28,
- 0x09, 0x52, 0x0a, 0x64, 0x65, 0x66, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x18, 0x0a,
- 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07,
- 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0xbf, 0x01, 0x0a, 0x0d, 0x49, 0x6e, 0x64, 0x65,
- 0x78, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d,
- 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x20, 0x0a,
- 0x0b, 0x65, 0x78, 0x70, 0x72, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x03,
- 0x28, 0x09, 0x52, 0x0b, 0x65, 0x78, 0x70, 0x72, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x12,
- 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74,
- 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x18, 0x04, 0x20,
- 0x01, 0x28, 0x08, 0x52, 0x06, 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x70,
- 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x70, 0x72,
- 0x69, 0x6d, 0x61, 0x72, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x69, 0x73, 0x69, 0x62, 0x6c, 0x65,
- 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x76, 0x69, 0x73, 0x69, 0x62, 0x6c, 0x65, 0x12,
- 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09,
- 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x7b, 0x0a, 0x11, 0x45, 0x78, 0x74,
- 0x65, 0x6e, 0x73, 0x69, 0x6f, 0x6e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12,
- 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61,
- 0x6d, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x18, 0x02, 0x20, 0x01,
- 0x28, 0x09, 0x52, 0x06, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65,
- 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72,
- 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74,
- 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72,
- 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0xa2, 0x02, 0x0a, 0x12, 0x46, 0x6f, 0x72, 0x65, 0x69,
- 0x67, 0x6e, 0x4b, 0x65, 0x79, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a,
- 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d,
- 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x03,
- 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x73, 0x12, 0x2b, 0x0a, 0x11, 0x72,
- 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x5f, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61,
- 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63,
- 0x65, 0x64, 0x53, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x12, 0x29, 0x0a, 0x10, 0x72, 0x65, 0x66, 0x65,
- 0x72, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x5f, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x04, 0x20, 0x01,
- 0x28, 0x09, 0x52, 0x0f, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x54, 0x61,
- 0x62, 0x6c, 0x65, 0x12, 0x2d, 0x0a, 0x12, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65,
- 0x64, 0x5f, 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x09, 0x52,
- 0x11, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x43, 0x6f, 0x6c, 0x75, 0x6d,
- 0x6e, 0x73, 0x12, 0x1b, 0x0a, 0x09, 0x6f, 0x6e, 0x5f, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x18,
- 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6f, 0x6e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12,
- 0x1b, 0x0a, 0x09, 0x6f, 0x6e, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x18, 0x07, 0x20, 0x01,
- 0x28, 0x09, 0x52, 0x08, 0x6f, 0x6e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x1d, 0x0a, 0x0a,
- 0x6d, 0x61, 0x74, 0x63, 0x68, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09,
- 0x52, 0x09, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x54, 0x79, 0x70, 0x65, 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,
+ 0x6e, 0x12, 0x36, 0x0a, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x18, 0x03, 0x20, 0x01,
+ 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74,
+ 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x56, 0x61, 0x6c, 0x75, 0x65,
+ 0x52, 0x07, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6c, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x6e, 0x75, 0x6c,
+ 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x6e, 0x75, 0x6c,
+ 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x05, 0x20,
+ 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x63, 0x68, 0x61,
+ 0x72, 0x61, 0x63, 0x74, 0x65, 0x72, 0x5f, 0x73, 0x65, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09,
+ 0x52, 0x0c, 0x63, 0x68, 0x61, 0x72, 0x61, 0x63, 0x74, 0x65, 0x72, 0x53, 0x65, 0x74, 0x12, 0x1c,
+ 0x0a, 0x09, 0x63, 0x6f, 0x6c, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x07, 0x20, 0x01, 0x28,
+ 0x09, 0x52, 0x09, 0x63, 0x6f, 0x6c, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x07,
+ 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63,
+ 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x5c, 0x0a, 0x0c, 0x56, 0x69, 0x65, 0x77, 0x4d, 0x65,
+ 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01,
+ 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x64, 0x65,
+ 0x66, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a,
+ 0x64, 0x65, 0x66, 0x69, 0x6e, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f,
+ 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d,
+ 0x6d, 0x65, 0x6e, 0x74, 0x22, 0xbf, 0x01, 0x0a, 0x0d, 0x49, 0x6e, 0x64, 0x65, 0x78, 0x4d, 0x65,
+ 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01,
+ 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x65, 0x78,
+ 0x70, 0x72, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52,
+ 0x0b, 0x65, 0x78, 0x70, 0x72, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x12, 0x0a, 0x04,
+ 0x74, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65,
+ 0x12, 0x16, 0x0a, 0x06, 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08,
+ 0x52, 0x06, 0x75, 0x6e, 0x69, 0x71, 0x75, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x69, 0x6d,
+ 0x61, 0x72, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x70, 0x72, 0x69, 0x6d, 0x61,
+ 0x72, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x69, 0x73, 0x69, 0x62, 0x6c, 0x65, 0x18, 0x06, 0x20,
+ 0x01, 0x28, 0x08, 0x52, 0x07, 0x76, 0x69, 0x73, 0x69, 0x62, 0x6c, 0x65, 0x12, 0x18, 0x0a, 0x07,
+ 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63,
+ 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, 0x22, 0x7b, 0x0a, 0x11, 0x45, 0x78, 0x74, 0x65, 0x6e, 0x73,
+ 0x69, 0x6f, 0x6e, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x6e,
+ 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12,
+ 0x16, 0x0a, 0x06, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
+ 0x06, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69,
+ 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f,
+ 0x6e, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e,
+ 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74,
+ 0x69, 0x6f, 0x6e, 0x22, 0xa2, 0x02, 0x0a, 0x12, 0x46, 0x6f, 0x72, 0x65, 0x69, 0x67, 0x6e, 0x4b,
+ 0x65, 0x79, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61,
+ 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x18,
+ 0x0a, 0x07, 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x09, 0x52,
+ 0x07, 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x73, 0x12, 0x2b, 0x0a, 0x11, 0x72, 0x65, 0x66, 0x65,
+ 0x72, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x5f, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x18, 0x03, 0x20,
+ 0x01, 0x28, 0x09, 0x52, 0x10, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x53,
+ 0x63, 0x68, 0x65, 0x6d, 0x61, 0x12, 0x29, 0x0a, 0x10, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e,
+ 0x63, 0x65, 0x64, 0x5f, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52,
+ 0x0f, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x54, 0x61, 0x62, 0x6c, 0x65,
+ 0x12, 0x2d, 0x0a, 0x12, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x5f, 0x63,
+ 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x09, 0x52, 0x11, 0x72, 0x65,
+ 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x43, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x73, 0x12,
+ 0x1b, 0x0a, 0x09, 0x6f, 0x6e, 0x5f, 0x64, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x18, 0x06, 0x20, 0x01,
+ 0x28, 0x09, 0x52, 0x08, 0x6f, 0x6e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x1b, 0x0a, 0x09,
+ 0x6f, 0x6e, 0x5f, 0x75, 0x70, 0x64, 0x61, 0x74, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52,
+ 0x08, 0x6f, 0x6e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x6d, 0x61, 0x74,
+ 0x63, 0x68, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6d,
+ 0x61, 0x74, 0x63, 0x68, 0x54, 0x79, 0x70, 0x65, 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 (
@@ -943,14 +935,15 @@ func file_store_database_proto_rawDescGZIP() []byte {
var file_store_database_proto_msgTypes = make([]protoimpl.MessageInfo, 8)
var file_store_database_proto_goTypes = []interface{}{
- (*DatabaseMetadata)(nil), // 0: bytebase.store.DatabaseMetadata
- (*SchemaMetadata)(nil), // 1: bytebase.store.SchemaMetadata
- (*TableMetadata)(nil), // 2: bytebase.store.TableMetadata
- (*ColumnMetadata)(nil), // 3: bytebase.store.ColumnMetadata
- (*ViewMetadata)(nil), // 4: bytebase.store.ViewMetadata
- (*IndexMetadata)(nil), // 5: bytebase.store.IndexMetadata
- (*ExtensionMetadata)(nil), // 6: bytebase.store.ExtensionMetadata
- (*ForeignKeyMetadata)(nil), // 7: bytebase.store.ForeignKeyMetadata
+ (*DatabaseMetadata)(nil), // 0: bytebase.store.DatabaseMetadata
+ (*SchemaMetadata)(nil), // 1: bytebase.store.SchemaMetadata
+ (*TableMetadata)(nil), // 2: bytebase.store.TableMetadata
+ (*ColumnMetadata)(nil), // 3: bytebase.store.ColumnMetadata
+ (*ViewMetadata)(nil), // 4: bytebase.store.ViewMetadata
+ (*IndexMetadata)(nil), // 5: bytebase.store.IndexMetadata
+ (*ExtensionMetadata)(nil), // 6: bytebase.store.ExtensionMetadata
+ (*ForeignKeyMetadata)(nil), // 7: bytebase.store.ForeignKeyMetadata
+ (*wrapperspb.StringValue)(nil), // 8: google.protobuf.StringValue
}
var file_store_database_proto_depIdxs = []int32{
1, // 0: bytebase.store.DatabaseMetadata.schemas:type_name -> bytebase.store.SchemaMetadata
@@ -960,11 +953,12 @@ var file_store_database_proto_depIdxs = []int32{
3, // 4: bytebase.store.TableMetadata.columns:type_name -> bytebase.store.ColumnMetadata
5, // 5: bytebase.store.TableMetadata.indexes:type_name -> bytebase.store.IndexMetadata
7, // 6: bytebase.store.TableMetadata.foreign_keys:type_name -> bytebase.store.ForeignKeyMetadata
- 7, // [7:7] is the sub-list for method output_type
- 7, // [7:7] is the sub-list for method input_type
- 7, // [7:7] is the sub-list for extension type_name
- 7, // [7:7] is the sub-list for extension extendee
- 0, // [0:7] is the sub-list for field type_name
+ 8, // 7: bytebase.store.ColumnMetadata.default:type_name -> google.protobuf.StringValue
+ 8, // [8:8] is the sub-list for method output_type
+ 8, // [8:8] is the sub-list for method input_type
+ 8, // [8:8] is the sub-list for extension type_name
+ 8, // [8:8] is the sub-list for extension extendee
+ 0, // [0:8] is the sub-list for field type_name
}
func init() { file_store_database_proto_init() }
diff --git a/proto/store/database.proto b/proto/store/database.proto
index 8e1ced94a2..26d74d2349 100644
--- a/proto/store/database.proto
+++ b/proto/store/database.proto
@@ -3,6 +3,8 @@ syntax = "proto3";
package bytebase.store;
option go_package = "generated-go/store";
+import "google/protobuf/wrappers.proto";
+
// DatabaseMetadata is the metadata for databases.
message DatabaseMetadata {
string name = 1;
@@ -83,28 +85,23 @@ message ColumnMetadata {
// The position is the position in columns.
int32 position = 2;
- // The has_default is whether a column has a default.
- // In proto3, we cannot distinguish between an empty string default value or no default.
- // We have to introduce a boolean field to indicate the existance of a default.
- bool has_default = 3;
-
- // The default is the default of a column.
- string default = 4;
+ // The default is the default of a column. Use google.protobuf.StringValue to distinguish between an empty string default value or no default.
+ google.protobuf.StringValue default = 3;
// The nullable is the nullable of a column.
- bool nullable = 5;
+ bool nullable = 4;
// The type is the type of a column.
- string type = 6;
+ string type = 5;
// The character_set is the character_set of a column.
- string character_set = 7;
+ string character_set = 6;
// The collation is the collation of a column.
- string collation = 8;
+ string collation = 7;
// The comment is the comment of a column.
- string comment = 9;
+ string comment = 8;
}
// ViewMetadata is the metadata for views.
diff --git a/server/runner/schemasync/syncer.go b/server/runner/schemasync/syncer.go
index 2e5f3498ab..5e5c8f94e4 100644
--- a/server/runner/schemasync/syncer.go
+++ b/server/runner/schemasync/syncer.go
@@ -15,6 +15,7 @@ import (
"github.com/pkg/errors"
"go.uber.org/zap"
"google.golang.org/protobuf/testing/protocmp"
+ "google.golang.org/protobuf/types/known/wrapperspb"
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/common"
@@ -495,8 +496,7 @@ func convertDBSchema(schema *db.Schema) *storepb.DatabaseMetadata {
Comment: column.Comment,
}
if column.Default != nil {
- columnMetadata.HasDefault = true
- columnMetadata.Default = *column.Default
+ columnMetadata.Default = &wrapperspb.StringValue{Value: *column.Default}
}
tableMetadata.Columns = append(tableMetadata.Columns, columnMetadata)
}
diff --git a/server/runner/schemasync/syncer_test.go b/server/runner/schemasync/syncer_test.go
index 5e24a19eb7..cb93d566ae 100644
--- a/server/runner/schemasync/syncer_test.go
+++ b/server/runner/schemasync/syncer_test.go
@@ -4,6 +4,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
+ "google.golang.org/protobuf/types/known/wrapperspb"
"github.com/bytebase/bytebase/plugin/db"
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
@@ -201,8 +202,7 @@ func TestConvertDBSchema(t *testing.T) {
{
Name: "id",
Position: 0,
- HasDefault: false,
- Default: "",
+ Default: nil,
Nullable: false,
Type: "int",
CharacterSet: "charset1",
@@ -212,8 +212,7 @@ func TestConvertDBSchema(t *testing.T) {
{
Name: "name",
Position: 1,
- HasDefault: true,
- Default: "Jay",
+ Default: &wrapperspb.StringValue{Value: "Jay"},
Nullable: false,
Type: "varchar(10)",
CharacterSet: "charset1",
@@ -223,8 +222,7 @@ func TestConvertDBSchema(t *testing.T) {
{
Name: "age",
Position: 2,
- HasDefault: false,
- Default: "",
+ Default: nil,
Nullable: false,
Type: "int",
CharacterSet: "charset1",
diff --git a/tests/schema_update_test.go b/tests/schema_update_test.go
index b8fc50486f..382f04e18c 100644
--- a/tests/schema_update_test.go
+++ b/tests/schema_update_test.go
@@ -20,6 +20,7 @@ import (
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/testing/protocmp"
+ "google.golang.org/protobuf/types/known/wrapperspb"
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/plugin/advisor"
@@ -1884,8 +1885,8 @@ CREATE TABLE public.book (
Name: "book",
DataSize: 8192,
Columns: []*storepb.ColumnMetadata{
- {Name: "id", Position: 1, HasDefault: true, Nullable: true, Type: "integer"},
- {Name: "name", Position: 2, HasDefault: true, Nullable: true, Type: "text"},
+ {Name: "id", Position: 1, Default: &wrapperspb.StringValue{Value: ""}, Nullable: true, Type: "integer"},
+ {Name: "name", Position: 2, Default: &wrapperspb.StringValue{Value: ""}, Nullable: true, Type: "text"},
},
},
},