Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: remove deprecated database edit in frontend (#8755)
boojacke265bfe775fd
diff --git a/frontend/package.json b/frontend/package.jsonindex 5fa163d7eb..0116089786 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -9,7 +9,7 @@"release-docker": "export NODE_OPTIONS=--max_old_space_size=8000 && vite build --mode release","lint": "eslint --cache --ext .js,.ts,.tsx,.vue src","lint:fix": "eslint --cache --ext .js,.ts,.tsx,.vue --fix src",- "test": "vitest run",+ "test": "vitest run --passWithNoTests","coverage": "vitest --coverage","copy-config-file": "sh ./scripts/copy_config_files.sh"},diff --git a/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue b/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vueindex 0f15bb9d6b..da23e7b426 100644--- a/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue+++ b/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue@@ -77,7 +77,6 @@</label><buttonclass="text-sm border px-3 leading-8 flex items-center rounded cursor-pointer hover:opacity-80 disabled:cursor-not-allowed disabled:opacity-60"- :disabled="!allowSyncSQLFromSchemaEditor"@click="handleSyncSQLFromSchemaEditor"><heroicons-outline:arrow-path@@ -137,8 +136,8 @@<script lang="ts" setup>import dayjs from "dayjs";-import { cloneDeep, head, uniq } from "lodash-es";-import { computed, onMounted, PropType, reactive, ref, watch } from "vue";+import { cloneDeep, head, isEqual, uniq } from "lodash-es";+import { computed, onMounted, PropType, reactive, ref } from "vue";import { useI18n } from "vue-i18n";import { useRouter } from "vue-router";import ActionConfirmModal from "@/components/SchemaEditorV1/Modals/ActionConfirmModal.vue";@@ -158,9 +157,9 @@ import {unknownProject,} from "@/types";import { Engine } from "@/types/proto/v1/common";+import { DatabaseMetadata } from "@/types/proto/v1/database_service";import { TenantMode } from "@/types/proto/v1/project_service";import { allowGhostMigrationV1 } from "@/utils";-import { validateDatabaseEdit } from "@/utils/schemaEditor/validate";import MonacoEditor from "../MonacoEditor";import { provideSQLCheckContext } from "../SQLCheck";import {@@ -169,7 +168,6 @@ import {} from "../SchemaEditorV1/utils";import GhostDialog from "./GhostDialog.vue";import SchemaEditorSQLCheckButton from "./SchemaEditorSQLCheckButton/SchemaEditorSQLCheckButton.vue";-import { getDatabaseEditListWithSchemaEditor } from "./utils";const MAX_UPLOAD_FILE_SIZE_MB = 1;@@ -211,26 +209,18 @@ const schemaEditorV1Store = useSchemaEditorV1Store();const databaseV1Store = useDatabaseV1Store();const dbSchemaV1Store = useDBSchemaV1Store();const notificationStore = useNotificationStore();-const statementFromSchemaEditor = ref<string>();const ghostDialog = ref<InstanceType<typeof GhostDialog>>();const { runSQLCheck } = provideSQLCheckContext();const allowPreviewIssue = computed(() => {if (state.selectedTab === "schema-editor") {- const databaseEditList = getDatabaseEditListWithSchemaEditor();- return databaseEditList.length !== 0;+ const databaseMetadataMap = getChangedDatabaseMetadatas();+ return databaseMetadataMap && databaseMetadataMap.size > 0;} else {return state.editStatement !== "";}});-const allowSyncSQLFromSchemaEditor = computed(() => {- if (state.selectedTab === "raw-sql") {- return statementFromSchemaEditor.value !== state.editStatement;- }- return false;-});-const databaseList = computed(() => {return props.databaseIdList.map((databaseId) => {return databaseV1Store.getDatabaseByUID(databaseId);@@ -253,7 +243,13 @@ const isTenantProject = computed(() => project.value.tenantMode === TenantMode.TENANT_MODE_ENABLED);-onMounted(() => {+const prepareDatabaseMetadatas = async () => {+ for (const database of databaseList.value) {+ await dbSchemaV1Store.getOrFetchDatabaseMetadata(database.name);+ }+};++onMounted(async () => {if (databaseList.value.length === 0 ||project.value.name === UNKNOWN_PROJECT_NAME@@ -266,6 +262,8 @@ onMounted(() => {emit("close");return;}++ await prepareDatabaseMetadatas();});const handleChangeTab = (tab: TabType) => {@@ -303,59 +301,72 @@ const isUsingGhostMigration = async (databaseList: ComposedDatabase[]) => {};const handleSyncSQLFromSchemaEditor = async () => {- if (!allowSyncSQLFromSchemaEditor.value) {+ const statementMap = await fetchStatementMapWithSchemaEditor();+ if (!statementMap) {return;}+ state.editStatement = Array.from(statementMap.values()).join("\n");+};- const databaseEditMap = await fetchDatabaseEditStatementMapWithSchemaEditor();- if (!databaseEditMap) {- return;+const getChangedDatabaseMetadatas = () => {+ const databaseMetadataMap: Map<string, [DatabaseMetadata, DatabaseMetadata]> =+ new Map();+ for (const database of databaseList.value) {+ const databaseSchema = schemaEditorV1Store.resourceMap["database"].get(+ database.name+ );+ if (!databaseSchema) {+ continue;+ }++ const metadata = dbSchemaV1Store.getDatabaseMetadata(database.name);+ const mergedMetadata = mergeSchemaEditToMetadata(+ databaseSchema.schemaList,+ cloneDeep(metadata)+ );+ if (isEqual(metadata, mergedMetadata)) {+ continue;+ }++ const validationMessages = validateDatabaseMetadata(mergedMetadata);+ if (validationMessages.length > 0) {+ pushNotification({+ module: "bytebase",+ style: "WARN",+ title: "Invalid schema structure",+ description: validationMessages.join("\n"),+ });+ return;+ }++ databaseMetadataMap.set(database.uid, [metadata, mergedMetadata]);}- state.editStatement = Array.from(databaseEditMap.values()).join("\n");- statementFromSchemaEditor.value = state.editStatement;+ return databaseMetadataMap;};-const fetchDatabaseEditStatementMapWithSchemaEditor = async () => {- const databaseEditList = getDatabaseEditListWithSchemaEditor();- const databaseEditMap: Map<string, string> = new Map();- if (databaseEditList.length > 0) {- for (const databaseEdit of databaseEditList) {- const database = databaseV1Store.getDatabaseByUID(- String(databaseEdit.databaseId)- );- const databaseSchema = schemaEditorV1Store.resourceMap["database"].get(- database.name- );- if (!databaseSchema) {- continue;- }+const fetchStatementMapWithSchemaEditor = async () => {+ const statementMap: Map<string, string> = new Map();+ const databaseMetadataMap = getChangedDatabaseMetadatas();+ if (!databaseMetadataMap) {+ return;+ }- const metadata = await dbSchemaV1Store.getOrFetchDatabaseMetadata(- database.name- );- const mergedMetadata = mergeSchemaEditToMetadata(- databaseSchema.schemaList,- cloneDeep(metadata)- );- const validationMessages = validateDatabaseMetadata(mergedMetadata);- if (validationMessages.length > 0) {- pushNotification({- module: "bytebase",- style: "WARN",- title: "Invalid schema structure",- description: validationMessages.join("\n"),- });- return;- }- const { diff } = await schemaDesignServiceClient.diffMetadata({- sourceMetadata: metadata,- targetMetadata: mergedMetadata,- engine: database.instanceEntity.engine,- });- databaseEditMap.set(database.uid, diff);+ for (const [+ databaseId,+ [sourceMetadata, targetMetadata],+ ] of databaseMetadataMap.entries()) {+ const database = databaseV1Store.getDatabaseByUID(databaseId);+ if (!database) {+ continue;}+ const { diff } = await schemaDesignServiceClient.diffMetadata({+ sourceMetadata,+ targetMetadata,+ engine: database.instanceEntity.engine,+ });+ statementMap.set(database.uid, diff);}- return databaseEditMap;+ return statementMap;};const handleUploadFile = (e: Event) => {@@ -447,41 +458,21 @@ const handlePreviewIssue = async () => {!!query.ghost);} else {- const databaseEditList = getDatabaseEditListWithSchemaEditor();- const validateResultList = [];- let hasOnlyAlterTableChanges = true;- for (const databaseEdit of databaseEditList) {- validateResultList.push(...validateDatabaseEdit(databaseEdit));- if (- databaseEdit.createTableList.length > 0 ||- databaseEdit.dropTableList.length > 0- ) {- hasOnlyAlterTableChanges = false;- }- }- if (validateResultList.length > 0) {- notificationStore.pushNotification({- module: "bytebase",- style: "CRITICAL",- title: "Invalid request",- description: validateResultList- .map((result) => result.message)- .join("\n"),- });+ // We should show select ghost mode dialog only for altering table statement not create/drop table.+ // TODO(steven): parse the sql check if there only alter table statement.+ const actionResult = await isUsingGhostMigration(databaseList.value);+ if (actionResult === false) {return;}-- if (hasOnlyAlterTableChanges) {- const actionResult = await isUsingGhostMigration(databaseList.value);- if (actionResult === false) {- return;- }- if (actionResult === "online") {- query.ghost = 1;- }+ if (actionResult === "online") {+ query.ghost = 1;}+ query.name = generateIssueName(+ databaseList.value.map((db) => db.databaseName),+ !!query.ghost+ );- const statementMap = await fetchDatabaseEditStatementMapWithSchemaEditor();+ const statementMap = await fetchStatementMapWithSchemaEditor();if (!statementMap) {return;}@@ -542,16 +533,6 @@ const generateIssueName = (issueNameParts.push(`${datetime} ${tz}`);return issueNameParts.join(" ");};--watch(- () => getDatabaseEditListWithSchemaEditor(),- () => {- statementFromSchemaEditor.value = undefined;- },- {- deep: true,- }-);</script><style>diff --git a/frontend/src/components/AlterSchemaPrepForm/SchemaEditorSQLCheckButton/useSchemaEditorSQLCheck.ts b/frontend/src/components/AlterSchemaPrepForm/SchemaEditorSQLCheckButton/useSchemaEditorSQLCheck.tsindex 565c93086a..9d6bffa36d 100644--- a/frontend/src/components/AlterSchemaPrepForm/SchemaEditorSQLCheckButton/useSchemaEditorSQLCheck.ts+++ b/frontend/src/components/AlterSchemaPrepForm/SchemaEditorSQLCheckButton/useSchemaEditorSQLCheck.ts@@ -1,4 +1,4 @@-import { cloneDeep } from "lodash-es";+import { cloneDeep, isEqual } from "lodash-es";import { Ref, computed } from "vue";import {mergeSchemaEditToMetadata,@@ -8,7 +8,6 @@ import { schemaDesignServiceClient } from "@/grpcweb";import { t } from "@/plugins/i18n";import { useDBSchemaV1Store, useSchemaEditorV1Store } from "@/store";import { ComposedDatabase } from "@/types";-import { getDatabaseEditListWithSchemaEditor } from "../utils";export const useSchemaEditorSQLCheck = (params: {selectedTab: Ref<"raw-sql" | "schema-editor">;@@ -34,7 +33,10 @@ export const useSchemaEditorSQLCheck = (params: {if (selectedTab.value === "raw-sql") {return editStatement.value;} else {- return JSON.stringify(getDatabaseEditListWithSchemaEditor());+ const databaseSchema = schemaEditorV1Store.resourceMap["database"].get(+ database.value.name+ );+ return JSON.stringify(databaseSchema);}});@@ -42,13 +44,6 @@ export const useSchemaEditorSQLCheck = (params: {errors: string[];statement: string;}> => {- const databaseEditList = getDatabaseEditListWithSchemaEditor();- if (databaseEditList.length !== 1) {- return {- errors: [t("schema-editor.nothing-changed")],- statement: "",- };- }const db = database.value;const databaseSchema = schemaEditorV1Store.resourceMap["database"].get(db.name@@ -65,6 +60,12 @@ export const useSchemaEditorSQLCheck = (params: {databaseSchema.schemaList,cloneDeep(metadata));+ if (isEqual(metadata, mergedMetadata)) {+ return {+ errors: [t("schema-editor.nothing-changed")],+ statement: "",+ };+ }const validationMessages = validateDatabaseMetadata(mergedMetadata);if (validationMessages.length > 0) {return {@@ -72,6 +73,7 @@ export const useSchemaEditorSQLCheck = (params: {statement: "",};}+try {const { diff } = await schemaDesignServiceClient.diffMetadata({diff --git a/frontend/src/components/AlterSchemaPrepForm/utils.ts b/frontend/src/components/AlterSchemaPrepForm/utils.tsindex d37ca4a326..e69de29bb2 100644--- a/frontend/src/components/AlterSchemaPrepForm/utils.ts+++ b/frontend/src/components/AlterSchemaPrepForm/utils.ts@@ -1,43 +0,0 @@-import { useSchemaEditorV1Store } from "@/store";-import { DatabaseEdit } from "@/types";-import {- checkHasSchemaChanges,- diffSchema,- mergeDiffResults,-} from "@/utils/schemaEditor/diffSchema";--// getDatabaseEditListWithSchemaEditor will calculate the diff between the origin schema and the current schema-// and return a list of DatabaseEdit. The DatabaseEdit will be only used to check if the schema has changes.-export const getDatabaseEditListWithSchemaEditor = () => {- const schemaEditorV1Store = useSchemaEditorV1Store();-- const databaseEditList: DatabaseEdit[] = [];- for (const databaseSchema of Array.from(- schemaEditorV1Store.resourceMap["database"].values()- )) {- const database = databaseSchema.database;- for (const schema of databaseSchema.schemaList) {- const originSchema = databaseSchema.originSchemaList.find(- (originSchema) => originSchema.id === schema.id- );- const diffSchemaResult = diffSchema(database.name, originSchema, schema);- if (checkHasSchemaChanges(diffSchemaResult)) {- const index = databaseEditList.findIndex(- (edit) => String(edit.databaseId) === database.uid- );- if (index !== -1) {- databaseEditList[index] = {- databaseId: Number(database.uid),- ...mergeDiffResults([diffSchemaResult, databaseEditList[index]]),- };- } else {- databaseEditList.push({- databaseId: Number(database.uid),- ...diffSchemaResult,- });- }- }- }- }- return databaseEditList;-};diff --git a/frontend/src/components/SchemaEditorV1/utils/metadata.ts b/frontend/src/components/SchemaEditorV1/utils/metadata.tsindex d0972a9210..9ee1543eab 100644--- a/frontend/src/components/SchemaEditorV1/utils/metadata.ts+++ b/frontend/src/components/SchemaEditorV1/utils/metadata.ts@@ -223,6 +223,9 @@ const transformSchemaEditToMetadata = (schemaEdit: Schema): SchemaMetadata => {columns: [],indexes: [],foreignKeys: [],+ comment: table.comment,+ userComment: table.userComment,+ classification: table.classification,});for (const column of table.columnList) {@@ -275,6 +278,9 @@ export const transformTableEditToMetadata = (columns: [],indexes: [],foreignKeys: [],+ comment: tableEdit.comment,+ userComment: tableEdit.userComment,+ classification: tableEdit.classification,});for (const column of tableEdit.columnList) {diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.tsindex bb3b20face..3b0bdd2998 100644--- a/frontend/src/types/index.ts+++ b/frontend/src/types/index.ts@@ -34,7 +34,6 @@ export * from "./tab";export * from "./sheet";export * from "./sqlReview";export * from "./utils";-export * from "./schemaEditor";export * from "./externalApproval";export * from "./mfa";export * from "./risk";diff --git a/frontend/src/types/proto/v1/database_edit.ts b/frontend/src/types/proto/v1/database_edit.tsdeleted file mode 100644index 2050d2565b..0000000000--- a/frontend/src/types/proto/v1/database_edit.ts+++ /dev/null@@ -1,1586 +0,0 @@-/* eslint-disable */-import _m0 from "protobufjs/minimal";--export const protobufPackage = "bytebase.v1";--export interface DatabaseEdit {- /** List of schema creation contexts. */- createSchemaContexts: CreateSchemaContext[];- /** List of schema renaming contexts. */- renameSchemaContexts: RenameSchemaContext[];- /** List of schema dropping contexts. */- dropSchemaContexts: DropSchemaContext[];- /** List of table creation contexts. */- createTableContexts: CreateTableContext[];- /** List of table alteration contexts. */- alterTableContexts: AlterTableContext[];- /** List of table renaming contexts. */- renameTableContexts: RenameTableContext[];- /** List of table dropping contexts. */- dropTableContexts: DropTableContext[];-}--export interface CreateSchemaContext {- /** The name of the schema to create. */- name: string;-}--export interface RenameSchemaContext {- /** The old name of the schema. */- oldName: string;- /** The new name of the schema. */- newName: string;-}--export interface DropSchemaContext {- /** The name of the schema to drop. */- name: string;-}--export interface CreateTableContext {- /** The name of the table to create. */- name: string;- /** The schema of the table. */- schema: string;- /** The type of the table. */- type: string;- /** The engine of the table. */- engine: string;- /** The character set of the table. */- characterSet: string;- /** The collation of the table. */- collation: string;- /** The comment of the table. */- comment: string;- /** List of column addition contexts. */- addColumnContexts: AddColumnContext[];- /** List of primary key columns. */- primaryKeys: string[];- /** List of foreign key addition contexts. */- addForeignKeyContexts: AddForeignKeyContext[];-}--export interface AlterTableContext {- /** The name of the table to alter. */- name: string;- /** The schema of the table. */- schema: string;- /** List of column addition contexts. */- addColumnContexts: AddColumnContext[];- /** List of column alteration contexts. */- alterColumnContexts: AlterColumnContext[];- /** List of column dropping contexts. */- dropColumnContexts: DropColumnContext[];- /** List of primary key columns to be dropped. */- dropPrimaryKeys: string[];- /** List of primary key columns. */- primaryKeys: string[];- /** List of foreign key columns to be dropped. */- dropForeignKeys: string[];- /** List of foreign key addition contexts. */- addForeignKeyContexts: AddForeignKeyContext[];-}--export interface RenameTableContext {- /** The schema of the table. */- schema: string;- /** The old name of the table. */- oldName: string;- /** The new name of the table. */- newName: string;-}--export interface DropTableContext {- /** The name of the table to drop. */- name: string;- /** The schema of the table. */- schema: string;-}--export interface AddColumnContext {- /** The name of the column to add. */- name: string;- /** The type of the column. */- type: string;- /** The character set of the column. */- characterSet: string;- /** The collation of the column. */- collation: string;- /** The comment of the column. */- comment: string;- /** Whether the column is nullable. */- nullable: boolean;- /** The default value of the column. */- defaultValue: string;- /** Whether the column has a default value. */- hasDefaultValue: boolean;-}--export interface AlterColumnContext {- /** The old name of the column. */- oldName: string;- /** The new name of the column. */- newName: string;- /** The type of the column. */- type: string;- /** The character set of the column. */- characterSet: string;- /** The collation of the column. */- collation: string;- /** The comment of the column. */- comment: string;- /** Whether the column is nullable. */- nullable: boolean;- /** The default value of the column. */- defaultValue: string;- /** Whether the default value of the column has changed. */- isDefaultValueChanged: boolean;-}--export interface DropColumnContext {- /** The name of the column to drop. */- name: string;-}--export interface AddForeignKeyContext {- /** The column of the foreign key. */- column: string;- /** The referenced schema of the foreign key. */- referencedSchema: string;- /** The referenced table of the foreign key. */- referencedTable: string;- /** The referenced column of the foreign key. */- referencedColumn: string;-}--function createBaseDatabaseEdit(): DatabaseEdit {- return {- createSchemaContexts: [],- renameSchemaContexts: [],- dropSchemaContexts: [],- createTableContexts: [],- alterTableContexts: [],- renameTableContexts: [],- dropTableContexts: [],- };-}--export const DatabaseEdit = {- encode(message: DatabaseEdit, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {- for (const v of message.createSchemaContexts) {- CreateSchemaContext.encode(v!, writer.uint32(10).fork()).ldelim();- }- for (const v of message.renameSchemaContexts) {- RenameSchemaContext.encode(v!, writer.uint32(18).fork()).ldelim();- }- for (const v of message.dropSchemaContexts) {- DropSchemaContext.encode(v!, writer.uint32(26).fork()).ldelim();- }- for (const v of message.createTableContexts) {- CreateTableContext.encode(v!, writer.uint32(34).fork()).ldelim();- }- for (const v of message.alterTableContexts) {- AlterTableContext.encode(v!, writer.uint32(42).fork()).ldelim();- }- for (const v of message.renameTableContexts) {- RenameTableContext.encode(v!, writer.uint32(50).fork()).ldelim();- }- for (const v of message.dropTableContexts) {- DropTableContext.encode(v!, writer.uint32(58).fork()).ldelim();- }- return writer;- },-- decode(input: _m0.Reader | Uint8Array, length?: number): DatabaseEdit {- const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);- let end = length === undefined ? reader.len : reader.pos + length;- const message = createBaseDatabaseEdit();- while (reader.pos < end) {- const tag = reader.uint32();- switch (tag >>> 3) {- case 1:- if (tag !== 10) {- break;- }-- message.createSchemaContexts.push(CreateSchemaContext.decode(reader, reader.uint32()));- continue;- case 2:- if (tag !== 18) {- break;- }-- message.renameSchemaContexts.push(RenameSchemaContext.decode(reader, reader.uint32()));- continue;- case 3:- if (tag !== 26) {- break;- }-- message.dropSchemaContexts.push(DropSchemaContext.decode(reader, reader.uint32()));- continue;- case 4:- if (tag !== 34) {- break;- }-- message.createTableContexts.push(CreateTableContext.decode(reader, reader.uint32()));- continue;- case 5:- if (tag !== 42) {- break;- }-- message.alterTableContexts.push(AlterTableContext.decode(reader, reader.uint32()));- continue;- case 6:- if (tag !== 50) {- break;- }-- message.renameTableContexts.push(RenameTableContext.decode(reader, reader.uint32()));- continue;- case 7:- if (tag !== 58) {- break;- }-- message.dropTableContexts.push(DropTableContext.decode(reader, reader.uint32()));- continue;- }- if ((tag & 7) === 4 || tag === 0) {- break;- }- reader.skipType(tag & 7);- }- return message;- },-- fromJSON(object: any): DatabaseEdit {- return {- createSchemaContexts: Array.isArray(object?.createSchemaContexts)- ? object.createSchemaContexts.map((e: any) => CreateSchemaContext.fromJSON(e))- : [],- renameSchemaContexts: Array.isArray(object?.renameSchemaContexts)- ? object.renameSchemaContexts.map((e: any) => RenameSchemaContext.fromJSON(e))- : [],- dropSchemaContexts: Array.isArray(object?.dropSchemaContexts)- ? object.dropSchemaContexts.map((e: any) => DropSchemaContext.fromJSON(e))- : [],- createTableContexts: Array.isArray(object?.createTableContexts)- ? object.createTableContexts.map((e: any) => CreateTableContext.fromJSON(e))- : [],- alterTableContexts: Array.isArray(object?.alterTableContexts)- ? object.alterTableContexts.map((e: any) => AlterTableContext.fromJSON(e))- : [],- renameTableContexts: Array.isArray(object?.renameTableContexts)- ? object.renameTableContexts.map((e: any) => RenameTableContext.fromJSON(e))- : [],- dropTableContexts: Array.isArray(object?.dropTableContexts)- ? object.dropTableContexts.map((e: any) => DropTableContext.fromJSON(e))- : [],- };- },-- toJSON(message: DatabaseEdit): unknown {- const obj: any = {};- if (message.createSchemaContexts) {- obj.createSchemaContexts = message.createSchemaContexts.map((e) => e ? CreateSchemaContext.toJSON(e) : undefined);- } else {- obj.createSchemaContexts = [];- }- if (message.renameSchemaContexts) {- obj.renameSchemaContexts = message.renameSchemaContexts.map((e) => e ? RenameSchemaContext.toJSON(e) : undefined);- } else {- obj.renameSchemaContexts = [];- }- if (message.dropSchemaContexts) {- obj.dropSchemaContexts = message.dropSchemaContexts.map((e) => e ? DropSchemaContext.toJSON(e) : undefined);- } else {- obj.dropSchemaContexts = [];- }- if (message.createTableContexts) {- obj.createTableContexts = message.createTableContexts.map((e) => e ? CreateTableContext.toJSON(e) : undefined);- } else {- obj.createTableContexts = [];- }- if (message.alterTableContexts) {- obj.alterTableContexts = message.alterTableContexts.map((e) => e ? AlterTableContext.toJSON(e) : undefined);- } else {- obj.alterTableContexts = [];- }- if (message.renameTableContexts) {- obj.renameTableContexts = message.renameTableContexts.map((e) => e ? RenameTableContext.toJSON(e) : undefined);- } else {- obj.renameTableContexts = [];- }- if (message.dropTableContexts) {- obj.dropTableContexts = message.dropTableContexts.map((e) => e ? DropTableContext.toJSON(e) : undefined);- } else {- obj.dropTableContexts = [];- }- return obj;- },-- create(base?: DeepPartial<DatabaseEdit>): DatabaseEdit {- return DatabaseEdit.fromPartial(base ?? {});- },-- fromPartial(object: DeepPartial<DatabaseEdit>): DatabaseEdit {- const message = createBaseDatabaseEdit();- message.createSchemaContexts = object.createSchemaContexts?.map((e) => CreateSchemaContext.fromPartial(e)) || [];- message.renameSchemaContexts = object.renameSchemaContexts?.map((e) => RenameSchemaContext.fromPartial(e)) || [];- message.dropSchemaContexts = object.dropSchemaContexts?.map((e) => DropSchemaContext.fromPartial(e)) || [];- message.createTableContexts = object.createTableContexts?.map((e) => CreateTableContext.fromPartial(e)) || [];- message.alterTableContexts = object.alterTableContexts?.map((e) => AlterTableContext.fromPartial(e)) || [];- message.renameTableContexts = object.renameTableContexts?.map((e) => RenameTableContext.fromPartial(e)) || [];- message.dropTableContexts = object.dropTableContexts?.map((e) => DropTableContext.fromPartial(e)) || [];- return message;- },-};--function createBaseCreateSchemaContext(): CreateSchemaContext {- return { name: "" };-}--export const CreateSchemaContext = {- encode(message: CreateSchemaContext, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {- if (message.name !== "") {- writer.uint32(10).string(message.name);- }- return writer;- },-- decode(input: _m0.Reader | Uint8Array, length?: number): CreateSchemaContext {- const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);- let end = length === undefined ? reader.len : reader.pos + length;- const message = createBaseCreateSchemaContext();- while (reader.pos < end) {- const tag = reader.uint32();- switch (tag >>> 3) {- case 1:- if (tag !== 10) {- break;- }-- message.name = reader.string();- continue;- }- if ((tag & 7) === 4 || tag === 0) {- break;- }- reader.skipType(tag & 7);- }- return message;- },-- fromJSON(object: any): CreateSchemaContext {- return { name: isSet(object.name) ? String(object.name) : "" };- },-- toJSON(message: CreateSchemaContext): unknown {- const obj: any = {};- message.name !== undefined && (obj.name = message.name);- return obj;- },-- create(base?: DeepPartial<CreateSchemaContext>): CreateSchemaContext {- return CreateSchemaContext.fromPartial(base ?? {});- },-- fromPartial(object: DeepPartial<CreateSchemaContext>): CreateSchemaContext {- const message = createBaseCreateSchemaContext();- message.name = object.name ?? "";- return message;- },-};--function createBaseRenameSchemaContext(): RenameSchemaContext {- return { oldName: "", newName: "" };-}--export const RenameSchemaContext = {- encode(message: RenameSchemaContext, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {- if (message.oldName !== "") {- writer.uint32(10).string(message.oldName);- }- if (message.newName !== "") {- writer.uint32(18).string(message.newName);- }- return writer;- },-- decode(input: _m0.Reader | Uint8Array, length?: number): RenameSchemaContext {- const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);- let end = length === undefined ? reader.len : reader.pos + length;- const message = createBaseRenameSchemaContext();- while (reader.pos < end) {- const tag = reader.uint32();- switch (tag >>> 3) {- case 1:- if (tag !== 10) {- break;- }-- message.oldName = reader.string();- continue;- case 2:- if (tag !== 18) {- break;- }-- message.newName = reader.string();- continue;- }- if ((tag & 7) === 4 || tag === 0) {- break;- }- reader.skipType(tag & 7);- }- return message;- },-- fromJSON(object: any): RenameSchemaContext {- return {- oldName: isSet(object.oldName) ? String(object.oldName) : "",- newName: isSet(object.newName) ? String(object.newName) : "",- };- },-- toJSON(message: RenameSchemaContext): unknown {- const obj: any = {};- message.oldName !== undefined && (obj.oldName = message.oldName);- message.newName !== undefined && (obj.newName = message.newName);- return obj;- },-- create(base?: DeepPartial<RenameSchemaContext>): RenameSchemaContext {- return RenameSchemaContext.fromPartial(base ?? {});- },-- fromPartial(object: DeepPartial<RenameSchemaContext>): RenameSchemaContext {- const message = createBaseRenameSchemaContext();- message.oldName = object.oldName ?? "";- message.newName = object.newName ?? "";- return message;- },-};--function createBaseDropSchemaContext(): DropSchemaContext {- return { name: "" };-}--export const DropSchemaContext = {- encode(message: DropSchemaContext, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {- if (message.name !== "") {- writer.uint32(10).string(message.name);- }- return writer;- },-- decode(input: _m0.Reader | Uint8Array, length?: number): DropSchemaContext {- const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);- let end = length === undefined ? reader.len : reader.pos + length;- const message = createBaseDropSchemaContext();- while (reader.pos < end) {- const tag = reader.uint32();- switch (tag >>> 3) {- case 1:- if (tag !== 10) {- break;- }-- message.name = reader.string();- continue;- }- if ((tag & 7) === 4 || tag === 0) {- break;- }- reader.skipType(tag & 7);- }- return message;- },-- fromJSON(object: any): DropSchemaContext {- return { name: isSet(object.name) ? String(object.name) : "" };- },-- toJSON(message: DropSchemaContext): unknown {- const obj: any = {};- message.name !== undefined && (obj.name = message.name);- return obj;- },-- create(base?: DeepPartial<DropSchemaContext>): DropSchemaContext {- return DropSchemaContext.fromPartial(base ?? {});- },-- fromPartial(object: DeepPartial<DropSchemaContext>): DropSchemaContext {- const message = createBaseDropSchemaContext();- message.name = object.name ?? "";- return message;- },-};--function createBaseCreateTableContext(): CreateTableContext {- return {- name: "",- schema: "",- type: "",- engine: "",- characterSet: "",- collation: "",- comment: "",- addColumnContexts: [],- primaryKeys: [],- addForeignKeyContexts: [],- };-}--export const CreateTableContext = {- encode(message: CreateTableContext, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {- if (message.name !== "") {- writer.uint32(10).string(message.name);- }- if (message.schema !== "") {- writer.uint32(18).string(message.schema);- }- if (message.type !== "") {- writer.uint32(26).string(message.type);- }- if (message.engine !== "") {- writer.uint32(34).string(message.engine);- }- if (message.characterSet !== "") {- writer.uint32(42).string(message.characterSet);- }- if (message.collation !== "") {- writer.uint32(50).string(message.collation);- }- if (message.comment !== "") {- writer.uint32(58).string(message.comment);- }- for (const v of message.addColumnContexts) {- AddColumnContext.encode(v!, writer.uint32(66).fork()).ldelim();- }- for (const v of message.primaryKeys) {- writer.uint32(74).string(v!);- }- for (const v of message.addForeignKeyContexts) {- AddForeignKeyContext.encode(v!, writer.uint32(82).fork()).ldelim();- }- return writer;- },-- decode(input: _m0.Reader | Uint8Array, length?: number): CreateTableContext {- const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);- let end = length === undefined ? reader.len : reader.pos + length;- const message = createBaseCreateTableContext();- while (reader.pos < end) {- const tag = reader.uint32();- switch (tag >>> 3) {- case 1:- if (tag !== 10) {- break;- }-- message.name = reader.string();- continue;- case 2:- if (tag !== 18) {- break;- }-- message.schema = reader.string();- continue;- case 3:- if (tag !== 26) {- break;- }-- message.type = reader.string();- continue;- case 4:- if (tag !== 34) {- break;- }-- message.engine = reader.string();- continue;- case 5:- if (tag !== 42) {- break;- }-- message.characterSet = reader.string();- continue;- case 6:- if (tag !== 50) {- break;- }-- message.collation = reader.string();- continue;- case 7:- if (tag !== 58) {- break;- }-- message.comment = reader.string();- continue;- case 8:- if (tag !== 66) {- break;- }-- message.addColumnContexts.push(AddColumnContext.decode(reader, reader.uint32()));- continue;- case 9:- if (tag !== 74) {- break;- }-- message.primaryKeys.push(reader.string());- continue;- case 10:- if (tag !== 82) {- break;- }-- message.addForeignKeyContexts.push(AddForeignKeyContext.decode(reader, reader.uint32()));- continue;- }- if ((tag & 7) === 4 || tag === 0) {- break;- }- reader.skipType(tag & 7);- }- return message;- },-- fromJSON(object: any): CreateTableContext {- return {- name: isSet(object.name) ? String(object.name) : "",- schema: isSet(object.schema) ? String(object.schema) : "",- type: isSet(object.type) ? String(object.type) : "",- engine: isSet(object.engine) ? String(object.engine) : "",- characterSet: isSet(object.characterSet) ? String(object.characterSet) : "",- collation: isSet(object.collation) ? String(object.collation) : "",- comment: isSet(object.comment) ? String(object.comment) : "",- addColumnContexts: Array.isArray(object?.addColumnContexts)- ? object.addColumnContexts.map((e: any) => AddColumnContext.fromJSON(e))- : [],- primaryKeys: Array.isArray(object?.primaryKeys) ? object.primaryKeys.map((e: any) => String(e)) : [],- addForeignKeyContexts: Array.isArray(object?.addForeignKeyContexts)- ? object.addForeignKeyContexts.map((e: any) => AddForeignKeyContext.fromJSON(e))- : [],- };- },-- toJSON(message: CreateTableContext): unknown {- const obj: any = {};- message.name !== undefined && (obj.name = message.name);- message.schema !== undefined && (obj.schema = message.schema);- message.type !== undefined && (obj.type = message.type);- message.engine !== undefined && (obj.engine = message.engine);- message.characterSet !== undefined && (obj.characterSet = message.characterSet);- message.collation !== undefined && (obj.collation = message.collation);- message.comment !== undefined && (obj.comment = message.comment);- if (message.addColumnContexts) {- obj.addColumnContexts = message.addColumnContexts.map((e) => e ? AddColumnContext.toJSON(e) : undefined);- } else {- obj.addColumnContexts = [];- }- if (message.primaryKeys) {- obj.primaryKeys = message.primaryKeys.map((e) => e);- } else {- obj.primaryKeys = [];- }- if (message.addForeignKeyContexts) {- obj.addForeignKeyContexts = message.addForeignKeyContexts.map((e) =>- e ? AddForeignKeyContext.toJSON(e) : undefined- );- } else {- obj.addForeignKeyContexts = [];- }- return obj;- },-- create(base?: DeepPartial<CreateTableContext>): CreateTableContext {- return CreateTableContext.fromPartial(base ?? {});- },-- fromPartial(object: DeepPartial<CreateTableContext>): CreateTableContext {- const message = createBaseCreateTableContext();- message.name = object.name ?? "";- message.schema = object.schema ?? "";- message.type = object.type ?? "";- message.engine = object.engine ?? "";- message.characterSet = object.characterSet ?? "";- message.collation = object.collation ?? "";- message.comment = object.comment ?? "";- message.addColumnContexts = object.addColumnContexts?.map((e) => AddColumnContext.fromPartial(e)) || [];- message.primaryKeys = object.primaryKeys?.map((e) => e) || [];- message.addForeignKeyContexts = object.addForeignKeyContexts?.map((e) => AddForeignKeyContext.fromPartial(e)) || [];- return message;- },-};--function createBaseAlterTableContext(): AlterTableContext {- return {- name: "",- schema: "",- addColumnContexts: [],- alterColumnContexts: [],- dropColumnContexts: [],- dropPrimaryKeys: [],- primaryKeys: [],- dropForeignKeys: [],- addForeignKeyContexts: [],- };-}--export const AlterTableContext = {- encode(message: AlterTableContext, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {- if (message.name !== "") {- writer.uint32(10).string(message.name);- }- if (message.schema !== "") {- writer.uint32(18).string(message.schema);- }- for (const v of message.addColumnContexts) {- AddColumnContext.encode(v!, writer.uint32(26).fork()).ldelim();- }- for (const v of message.alterColumnContexts) {- AlterColumnContext.encode(v!, writer.uint32(34).fork()).ldelim();- }- for (const v of message.dropColumnContexts) {- DropColumnContext.encode(v!, writer.uint32(42).fork()).ldelim();- }- for (const v of message.dropPrimaryKeys) {- writer.uint32(50).string(v!);- }- for (const v of message.primaryKeys) {- writer.uint32(58).string(v!);- }- for (const v of message.dropForeignKeys) {- writer.uint32(66).string(v!);- }- for (const v of message.addForeignKeyContexts) {- AddForeignKeyContext.encode(v!, writer.uint32(74).fork()).ldelim();- }- return writer;- },-- decode(input: _m0.Reader | Uint8Array, length?: number): AlterTableContext {- const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);- let end = length === undefined ? reader.len : reader.pos + length;- const message = createBaseAlterTableContext();- while (reader.pos < end) {- const tag = reader.uint32();- switch (tag >>> 3) {- case 1:- if (tag !== 10) {- break;- }-- message.name = reader.string();- continue;- case 2:- if (tag !== 18) {- break;- }-- message.schema = reader.string();- continue;- case 3:- if (tag !== 26) {- break;- }-- message.addColumnContexts.push(AddColumnContext.decode(reader, reader.uint32()));- continue;- case 4:- if (tag !== 34) {- break;- }-- message.alterColumnContexts.push(AlterColumnContext.decode(reader, reader.uint32()));- continue;- case 5:- if (tag !== 42) {- break;- }-- message.dropColumnContexts.push(DropColumnContext.decode(reader, reader.uint32()));- continue;- case 6:- if (tag !== 50) {- break;- }-- message.dropPrimaryKeys.push(reader.string());- continue;- case 7:- if (tag !== 58) {- break;- }-- message.primaryKeys.push(reader.string());- continue;- case 8:- if (tag !== 66) {- break;- }-- message.dropForeignKeys.push(reader.string());- continue;- case 9:- if (tag !== 74) {- break;- }-- message.addForeignKeyContexts.push(AddForeignKeyContext.decode(reader, reader.uint32()));- continue;- }- if ((tag & 7) === 4 || tag === 0) {- break;- }- reader.skipType(tag & 7);- }- return message;- },-- fromJSON(object: any): AlterTableContext {- return {- name: isSet(object.name) ? String(object.name) : "",- schema: isSet(object.schema) ? String(object.schema) : "",- addColumnContexts: Array.isArray(object?.addColumnContexts)- ? object.addColumnContexts.map((e: any) => AddColumnContext.fromJSON(e))- : [],- alterColumnContexts: Array.isArray(object?.alterColumnContexts)- ? object.alterColumnContexts.map((e: any) => AlterColumnContext.fromJSON(e))- : [],- dropColumnContexts: Array.isArray(object?.dropColumnContexts)- ? object.dropColumnContexts.map((e: any) => DropColumnContext.fromJSON(e))- : [],- dropPrimaryKeys: Array.isArray(object?.dropPrimaryKeys) ? object.dropPrimaryKeys.map((e: any) => String(e)) : [],- primaryKeys: Array.isArray(object?.primaryKeys) ? object.primaryKeys.map((e: any) => String(e)) : [],- dropForeignKeys: Array.isArray(object?.dropForeignKeys) ? object.dropForeignKeys.map((e: any) => String(e)) : [],- addForeignKeyContexts: Array.isArray(object?.addForeignKeyContexts)- ? object.addForeignKeyContexts.map((e: any) => AddForeignKeyContext.fromJSON(e))- : [],- };- },-- toJSON(message: AlterTableContext): unknown {- const obj: any = {};- message.name !== undefined && (obj.name = message.name);- message.schema !== undefined && (obj.schema = message.schema);- if (message.addColumnContexts) {- obj.addColumnContexts = message.addColumnContexts.map((e) => e ? AddColumnContext.toJSON(e) : undefined);- } else {- obj.addColumnContexts = [];- }- if (message.alterColumnContexts) {- obj.alterColumnContexts = message.alterColumnContexts.map((e) => e ? AlterColumnContext.toJSON(e) : undefined);- } else {- obj.alterColumnContexts = [];- }- if (message.dropColumnContexts) {- obj.dropColumnContexts = message.dropColumnContexts.map((e) => e ? DropColumnContext.toJSON(e) : undefined);- } else {- obj.dropColumnContexts = [];- }- if (message.dropPrimaryKeys) {- obj.dropPrimaryKeys = message.dropPrimaryKeys.map((e) => e);- } else {- obj.dropPrimaryKeys = [];- }- if (message.primaryKeys) {- obj.primaryKeys = message.primaryKeys.map((e) => e);- } else {- obj.primaryKeys = [];- }- if (message.dropForeignKeys) {- obj.dropForeignKeys = message.dropForeignKeys.map((e) => e);- } else {- obj.dropForeignKeys = [];- }- if (message.addForeignKeyContexts) {- obj.addForeignKeyContexts = message.addForeignKeyContexts.map((e) =>- e ? AddForeignKeyContext.toJSON(e) : undefined- );- } else {- obj.addForeignKeyContexts = [];- }- return obj;- },-- create(base?: DeepPartial<AlterTableContext>): AlterTableContext {- return AlterTableContext.fromPartial(base ?? {});- },-- fromPartial(object: DeepPartial<AlterTableContext>): AlterTableContext {- const message = createBaseAlterTableContext();- message.name = object.name ?? "";- message.schema = object.schema ?? "";- message.addColumnContexts = object.addColumnContexts?.map((e) => AddColumnContext.fromPartial(e)) || [];- message.alterColumnContexts = object.alterColumnContexts?.map((e) => AlterColumnContext.fromPartial(e)) || [];- message.dropColumnContexts = object.dropColumnContexts?.map((e) => DropColumnContext.fromPartial(e)) || [];- message.dropPrimaryKeys = object.dropPrimaryKeys?.map((e) => e) || [];- message.primaryKeys = object.primaryKeys?.map((e) => e) || [];- message.dropForeignKeys = object.dropForeignKeys?.map((e) => e) || [];- message.addForeignKeyContexts = object.addForeignKeyContexts?.map((e) => AddForeignKeyContext.fromPartial(e)) || [];- return message;- },-};--function createBaseRenameTableContext(): RenameTableContext {- return { schema: "", oldName: "", newName: "" };-}--export const RenameTableContext = {- encode(message: RenameTableContext, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {- if (message.schema !== "") {- writer.uint32(10).string(message.schema);- }- if (message.oldName !== "") {- writer.uint32(18).string(message.oldName);- }- if (message.newName !== "") {- writer.uint32(26).string(message.newName);- }- return writer;- },-- decode(input: _m0.Reader | Uint8Array, length?: number): RenameTableContext {- const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);- let end = length === undefined ? reader.len : reader.pos + length;- const message = createBaseRenameTableContext();- while (reader.pos < end) {- const tag = reader.uint32();- switch (tag >>> 3) {- case 1:- if (tag !== 10) {- break;- }-- message.schema = reader.string();- continue;- case 2:- if (tag !== 18) {- break;- }-- message.oldName = reader.string();- continue;- case 3:- if (tag !== 26) {- break;- }-- message.newName = reader.string();- continue;- }- if ((tag & 7) === 4 || tag === 0) {- break;- }- reader.skipType(tag & 7);- }- return message;- },-- fromJSON(object: any): RenameTableContext {- return {- schema: isSet(object.schema) ? String(object.schema) : "",- oldName: isSet(object.oldName) ? String(object.oldName) : "",- newName: isSet(object.newName) ? String(object.newName) : "",- };- },-- toJSON(message: RenameTableContext): unknown {- const obj: any = {};- message.schema !== undefined && (obj.schema = message.schema);- message.oldName !== undefined && (obj.oldName = message.oldName);- message.newName !== undefined && (obj.newName = message.newName);- return obj;- },-- create(base?: DeepPartial<RenameTableContext>): RenameTableContext {- return RenameTableContext.fromPartial(base ?? {});- },-- fromPartial(object: DeepPartial<RenameTableContext>): RenameTableContext {- const message = createBaseRenameTableContext();- message.schema = object.schema ?? "";- message.oldName = object.oldName ?? "";- message.newName = object.newName ?? "";- return message;- },-};--function createBaseDropTableContext(): DropTableContext {- return { name: "", schema: "" };-}--export const DropTableContext = {- encode(message: DropTableContext, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {- if (message.name !== "") {- writer.uint32(10).string(message.name);- }- if (message.schema !== "") {- writer.uint32(18).string(message.schema);- }- return writer;- },-- decode(input: _m0.Reader | Uint8Array, length?: number): DropTableContext {- const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);- let end = length === undefined ? reader.len : reader.pos + length;- const message = createBaseDropTableContext();- while (reader.pos < end) {- const tag = reader.uint32();- switch (tag >>> 3) {- case 1:- if (tag !== 10) {- break;- }-- message.name = reader.string();- continue;- case 2:- if (tag !== 18) {- break;- }-- message.schema = reader.string();- continue;- }- if ((tag & 7) === 4 || tag === 0) {- break;- }- reader.skipType(tag & 7);- }- return message;- },-- fromJSON(object: any): DropTableContext {- return {- name: isSet(object.name) ? String(object.name) : "",- schema: isSet(object.schema) ? String(object.schema) : "",- };- },-- toJSON(message: DropTableContext): unknown {- const obj: any = {};- message.name !== undefined && (obj.name = message.name);- message.schema !== undefined && (obj.schema = message.schema);- return obj;- },-- create(base?: DeepPartial<DropTableContext>): DropTableContext {- return DropTableContext.fromPartial(base ?? {});- },-- fromPartial(object: DeepPartial<DropTableContext>): DropTableContext {- const message = createBaseDropTableContext();- message.name = object.name ?? "";- message.schema = object.schema ?? "";- return message;- },-};--function createBaseAddColumnContext(): AddColumnContext {- return {- name: "",- type: "",- characterSet: "",- collation: "",- comment: "",- nullable: false,- defaultValue: "",- hasDefaultValue: false,- };-}--export const AddColumnContext = {- encode(message: AddColumnContext, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {- if (message.name !== "") {- writer.uint32(10).string(message.name);- }- if (message.type !== "") {- writer.uint32(18).string(message.type);- }- if (message.characterSet !== "") {- writer.uint32(26).string(message.characterSet);- }- if (message.collation !== "") {- writer.uint32(34).string(message.collation);- }- if (message.comment !== "") {- writer.uint32(42).string(message.comment);- }- if (message.nullable === true) {- writer.uint32(48).bool(message.nullable);- }- if (message.defaultValue !== "") {- writer.uint32(58).string(message.defaultValue);- }- if (message.hasDefaultValue === true) {- writer.uint32(64).bool(message.hasDefaultValue);- }- return writer;- },-- decode(input: _m0.Reader | Uint8Array, length?: number): AddColumnContext {- const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);- let end = length === undefined ? reader.len : reader.pos + length;- const message = createBaseAddColumnContext();- while (reader.pos < end) {- const tag = reader.uint32();- switch (tag >>> 3) {- case 1:- if (tag !== 10) {- break;- }-- message.name = reader.string();- continue;- case 2:- if (tag !== 18) {- break;- }-- message.type = reader.string();- continue;- case 3:- if (tag !== 26) {- break;- }-- message.characterSet = reader.string();- continue;- case 4:- if (tag !== 34) {- break;- }-- message.collation = reader.string();- continue;- case 5:- if (tag !== 42) {- break;- }-- message.comment = reader.string();- continue;- case 6:- if (tag !== 48) {- break;- }-- message.nullable = reader.bool();- continue;- case 7:- if (tag !== 58) {- break;- }-- message.defaultValue = reader.string();- continue;- case 8:- if (tag !== 64) {- break;- }-- message.hasDefaultValue = reader.bool();- continue;- }- if ((tag & 7) === 4 || tag === 0) {- break;- }- reader.skipType(tag & 7);- }- return message;- },-- fromJSON(object: any): AddColumnContext {- return {- name: isSet(object.name) ? String(object.name) : "",- type: isSet(object.type) ? String(object.type) : "",- characterSet: isSet(object.characterSet) ? String(object.characterSet) : "",- collation: isSet(object.collation) ? String(object.collation) : "",- comment: isSet(object.comment) ? String(object.comment) : "",- nullable: isSet(object.nullable) ? Boolean(object.nullable) : false,- defaultValue: isSet(object.defaultValue) ? String(object.defaultValue) : "",- hasDefaultValue: isSet(object.hasDefaultValue) ? Boolean(object.hasDefaultValue) : false,- };- },-- toJSON(message: AddColumnContext): unknown {- const obj: any = {};- message.name !== undefined && (obj.name = message.name);- message.type !== undefined && (obj.type = message.type);- message.characterSet !== undefined && (obj.characterSet = message.characterSet);- message.collation !== undefined && (obj.collation = message.collation);- message.comment !== undefined && (obj.comment = message.comment);- message.nullable !== undefined && (obj.nullable = message.nullable);- message.defaultValue !== undefined && (obj.defaultValue = message.defaultValue);- message.hasDefaultValue !== undefined && (obj.hasDefaultValue = message.hasDefaultValue);- return obj;- },-- create(base?: DeepPartial<AddColumnContext>): AddColumnContext {- return AddColumnContext.fromPartial(base ?? {});- },-- fromPartial(object: DeepPartial<AddColumnContext>): AddColumnContext {- const message = createBaseAddColumnContext();- message.name = object.name ?? "";- message.type = object.type ?? "";- message.characterSet = object.characterSet ?? "";- message.collation = object.collation ?? "";- message.comment = object.comment ?? "";- message.nullable = object.nullable ?? false;- message.defaultValue = object.defaultValue ?? "";- message.hasDefaultValue = object.hasDefaultValue ?? false;- return message;- },-};--function createBaseAlterColumnContext(): AlterColumnContext {- return {- oldName: "",- newName: "",- type: "",- characterSet: "",- collation: "",- comment: "",- nullable: false,- defaultValue: "",- isDefaultValueChanged: false,- };-}--export const AlterColumnContext = {- encode(message: AlterColumnContext, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {- if (message.oldName !== "") {- writer.uint32(10).string(message.oldName);- }- if (message.newName !== "") {- writer.uint32(18).string(message.newName);- }- if (message.type !== "") {- writer.uint32(26).string(message.type);- }- if (message.characterSet !== "") {- writer.uint32(34).string(message.characterSet);- }- if (message.collation !== "") {- writer.uint32(42).string(message.collation);- }- if (message.comment !== "") {- writer.uint32(50).string(message.comment);- }- if (message.nullable === true) {- writer.uint32(56).bool(message.nullable);- }- if (message.defaultValue !== "") {- writer.uint32(66).string(message.defaultValue);- }- if (message.isDefaultValueChanged === true) {- writer.uint32(72).bool(message.isDefaultValueChanged);- }- return writer;- },-- decode(input: _m0.Reader | Uint8Array, length?: number): AlterColumnContext {- const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);- let end = length === undefined ? reader.len : reader.pos + length;- const message = createBaseAlterColumnContext();- while (reader.pos < end) {- const tag = reader.uint32();- switch (tag >>> 3) {- case 1:- if (tag !== 10) {- break;- }-- message.oldName = reader.string();- continue;- case 2:- if (tag !== 18) {- break;- }-- message.newName = reader.string();- continue;- case 3:- if (tag !== 26) {- break;- }-- message.type = reader.string();- continue;- case 4:- if (tag !== 34) {- break;- }-- message.characterSet = reader.string();- continue;- case 5:- if (tag !== 42) {- break;- }-- message.collation = reader.string();- continue;- case 6:- if (tag !== 50) {- break;- }-- message.comment = reader.string();- continue;- case 7:- if (tag !== 56) {- break;- }-- message.nullable = reader.bool();- continue;- case 8:- if (tag !== 66) {- break;- }-- message.defaultValue = reader.string();- continue;- case 9:- if (tag !== 72) {- break;- }-- message.isDefaultValueChanged = reader.bool();- continue;- }- if ((tag & 7) === 4 || tag === 0) {- break;- }- reader.skipType(tag & 7);- }- return message;- },-- fromJSON(object: any): AlterColumnContext {- return {- oldName: isSet(object.oldName) ? String(object.oldName) : "",- newName: isSet(object.newName) ? String(object.newName) : "",- type: isSet(object.type) ? String(object.type) : "",- characterSet: isSet(object.characterSet) ? String(object.characterSet) : "",- collation: isSet(object.collation) ? String(object.collation) : "",- comment: isSet(object.comment) ? String(object.comment) : "",- nullable: isSet(object.nullable) ? Boolean(object.nullable) : false,- defaultValue: isSet(object.defaultValue) ? String(object.defaultValue) : "",- isDefaultValueChanged: isSet(object.isDefaultValueChanged) ? Boolean(object.isDefaultValueChanged) : false,- };- },-- toJSON(message: AlterColumnContext): unknown {- const obj: any = {};- message.oldName !== undefined && (obj.oldName = message.oldName);- message.newName !== undefined && (obj.newName = message.newName);- message.type !== undefined && (obj.type = message.type);- message.characterSet !== undefined && (obj.characterSet = message.characterSet);- message.collation !== undefined && (obj.collation = message.collation);- message.comment !== undefined && (obj.comment = message.comment);- message.nullable !== undefined && (obj.nullable = message.nullable);- message.defaultValue !== undefined && (obj.defaultValue = message.defaultValue);- message.isDefaultValueChanged !== undefined && (obj.isDefaultValueChanged = message.isDefaultValueChanged);- return obj;- },-- create(base?: DeepPartial<AlterColumnContext>): AlterColumnContext {- return AlterColumnContext.fromPartial(base ?? {});- },-- fromPartial(object: DeepPartial<AlterColumnContext>): AlterColumnContext {- const message = createBaseAlterColumnContext();- message.oldName = object.oldName ?? "";- message.newName = object.newName ?? "";- message.type = object.type ?? "";- message.characterSet = object.characterSet ?? "";- message.collation = object.collation ?? "";- message.comment = object.comment ?? "";- message.nullable = object.nullable ?? false;- message.defaultValue = object.defaultValue ?? "";- message.isDefaultValueChanged = object.isDefaultValueChanged ?? false;- return message;- },-};--function createBaseDropColumnContext(): DropColumnContext {- return { name: "" };-}--export const DropColumnContext = {- encode(message: DropColumnContext, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {- if (message.name !== "") {- writer.uint32(10).string(message.name);- }- return writer;- },-- decode(input: _m0.Reader | Uint8Array, length?: number): DropColumnContext {- const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);- let end = length === undefined ? reader.len : reader.pos + length;- const message = createBaseDropColumnContext();- while (reader.pos < end) {- const tag = reader.uint32();- switch (tag >>> 3) {- case 1:- if (tag !== 10) {- break;- }-- message.name = reader.string();- continue;- }- if ((tag & 7) === 4 || tag === 0) {- break;- }- reader.skipType(tag & 7);- }- return message;- },-- fromJSON(object: any): DropColumnContext {- return { name: isSet(object.name) ? String(object.name) : "" };- },-- toJSON(message: DropColumnContext): unknown {- const obj: any = {};- message.name !== undefined && (obj.name = message.name);- return obj;- },-- create(base?: DeepPartial<DropColumnContext>): DropColumnContext {- return DropColumnContext.fromPartial(base ?? {});- },-- fromPartial(object: DeepPartial<DropColumnContext>): DropColumnContext {- const message = createBaseDropColumnContext();- message.name = object.name ?? "";- return message;- },-};--function createBaseAddForeignKeyContext(): AddForeignKeyContext {- return { column: "", referencedSchema: "", referencedTable: "", referencedColumn: "" };-}--export const AddForeignKeyContext = {- encode(message: AddForeignKeyContext, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {- if (message.column !== "") {- writer.uint32(10).string(message.column);- }- if (message.referencedSchema !== "") {- writer.uint32(18).string(message.referencedSchema);- }- if (message.referencedTable !== "") {- writer.uint32(26).string(message.referencedTable);- }- if (message.referencedColumn !== "") {- writer.uint32(34).string(message.referencedColumn);- }- return writer;- },-- decode(input: _m0.Reader | Uint8Array, length?: number): AddForeignKeyContext {- const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);- let end = length === undefined ? reader.len : reader.pos + length;- const message = createBaseAddForeignKeyContext();- while (reader.pos < end) {- const tag = reader.uint32();- switch (tag >>> 3) {- case 1:- if (tag !== 10) {- break;- }-- message.column = reader.string();- continue;- case 2:- if (tag !== 18) {- break;- }-- message.referencedSchema = reader.string();- continue;- case 3:- if (tag !== 26) {- break;- }-- message.referencedTable = reader.string();- continue;- case 4:- if (tag !== 34) {- break;- }-- message.referencedColumn = reader.string();- continue;- }- if ((tag & 7) === 4 || tag === 0) {- break;- }- reader.skipType(tag & 7);- }- return message;- },-- fromJSON(object: any): AddForeignKeyContext {- return {- column: isSet(object.column) ? String(object.column) : "",- referencedSchema: isSet(object.referencedSchema) ? String(object.referencedSchema) : "",- referencedTable: isSet(object.referencedTable) ? String(object.referencedTable) : "",- referencedColumn: isSet(object.referencedColumn) ? String(object.referencedColumn) : "",- };- },-- toJSON(message: AddForeignKeyContext): unknown {- const obj: any = {};- message.column !== undefined && (obj.column = message.column);- message.referencedSchema !== undefined && (obj.referencedSchema = message.referencedSchema);- message.referencedTable !== undefined && (obj.referencedTable = message.referencedTable);- message.referencedColumn !== undefined && (obj.referencedColumn = message.referencedColumn);- return obj;- },-- create(base?: DeepPartial<AddForeignKeyContext>): AddForeignKeyContext {- return AddForeignKeyContext.fromPartial(base ?? {});- },-- fromPartial(object: DeepPartial<AddForeignKeyContext>): AddForeignKeyContext {- const message = createBaseAddForeignKeyContext();- message.column = object.column ?? "";- message.referencedSchema = object.referencedSchema ?? "";- message.referencedTable = object.referencedTable ?? "";- message.referencedColumn = object.referencedColumn ?? "";- return message;- },-};--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>;--function isSet(value: any): boolean {- return value !== null && value !== undefined;-}diff --git a/frontend/src/types/schemaEditor/index.ts b/frontend/src/types/schemaEditor/index.tsdeleted file mode 100644index 7530b7228a..0000000000--- a/frontend/src/types/schemaEditor/index.ts+++ /dev/null@@ -1,121 +0,0 @@-/**- * Type definition for API message.- */-export interface DatabaseEdit {- databaseId: number;-- createSchemaList: CreateSchemaContext[];- renameSchemaList: RenameSchemaContext[];- dropSchemaList: DropSchemaContext[];- createTableList: CreateTableContext[];- alterTableList: AlterTableContext[];- renameTableList: RenameTableContext[];- dropTableList: DropTableContext[];-}--export interface CreateSchemaContext {- schema: string;-}--export interface RenameSchemaContext {- oldName: string;- newName: string;-}--export interface DropSchemaContext {- schema: string;-}--export interface CreateTableContext {- schema: string;- name: string;- engine: string;- characterSet: string;- collation: string;- comment: string;-- addColumnList: AddColumnContext[];- primaryKeyList: string[];- addForeignKeyList: AddForeignKeyContext[];-}--export interface AlterTableContext {- schema: string;- name: string;-- addColumnList: AddColumnContext[];- alterColumnList: AlterColumnContext[];- changeColumnList: ChangeColumnContext[];- dropColumnList: DropColumnContext[];- dropPrimaryKey: boolean;- dropPrimaryKeyList: string[];- primaryKeyList?: string[];- dropForeignKeyList: string[];- addForeignKeyList: AddForeignKeyContext[];-}--export interface RenameTableContext {- schema: string;- oldName: string;- newName: string;-}--export interface DropTableContext {- schema: string;- name: string;-}--export interface AddColumnContext {- name: string;- type: string;- characterSet: string;- collation: string;- comment: string;- nullable: boolean;- default?: string;-}--export interface AlterColumnContext {- oldName: string;- newName: string;- type?: string;- comment?: string;- nullable?: boolean;- defaultChanged: boolean;- default?: string;-}--export interface ChangeColumnContext {- oldName: string;- newName: string;- type: string;- characterSet: string;- collation: string;- comment: string;- nullable: boolean;- default?: string;-}--export interface DropColumnContext {- name: string;-}--export interface AddForeignKeyContext {- columnList: string[];- referencedSchema: string;- referencedTable: string;- referencedColumnList: string[];-}--/**- * Type definition for DatabaseEdit validation API message.- */-export interface ValidateResult {- type: string;- message: string;-}--export interface DatabaseEditResult {- statement: string;- validateResultList: ValidateResult[];-}diff --git a/frontend/src/types/v1/schemaEditor/atomType.ts b/frontend/src/types/v1/schemaEditor/atomType.tsindex 3e2868d272..ceef46e9ba 100644--- a/frontend/src/types/v1/schemaEditor/atomType.ts+++ b/frontend/src/types/v1/schemaEditor/atomType.ts@@ -1,10 +1,10 @@import { v1 as uuidv1 } from "uuid";-import { isGhostTable } from "@/utils";import {SchemaMetadata,TableMetadata,ColumnMetadata,-} from "../../proto/v1/database_service";+} from "@/types/proto/v1/database_service";+import { isGhostTable } from "@/utils";type Status = "normal" | "created" | "dropped";diff --git a/frontend/src/utils/schemaEditor/diffColumn.test.ts b/frontend/src/utils/schemaEditor/diffColumn.test.tsdeleted file mode 100644index fa28a21b0a..0000000000--- a/frontend/src/utils/schemaEditor/diffColumn.test.ts+++ /dev/null@@ -1,173 +0,0 @@-import { expect, it } from "vitest";-import {- AddColumnContext,- DropColumnContext,- ChangeColumnContext,- AlterColumnContext,-} from "@/types";-import { Column } from "@/types/v1/schemaEditor";-import { diffColumnList } from "./diffColumn";--it("diff add column list", () => {- const testList: {- originColumnList: Column[];- columnList: Column[];- wanted: {- addColumnList: AddColumnContext[];- alterColumnList: AlterColumnContext[];- changeColumnList: ChangeColumnContext[];- dropColumnList: DropColumnContext[];- };- }[] = [- {- originColumnList: [],- columnList: [- {- id: "1",- name: "id",- type: "int",- comment: "",- nullable: false,- status: "created",- } as any as Column,- ],- wanted: {- addColumnList: [- {- name: "id",- type: "int",- comment: "",- nullable: false,- characterSet: "",- collation: "",- default: undefined,- },- ],- alterColumnList: [],- changeColumnList: [],- dropColumnList: [],- },- },- ];-- for (const test of testList) {- const result = diffColumnList(test.originColumnList, test.columnList);- expect(result).toStrictEqual(test.wanted);- }-});--it("diff modify column list", () => {- const testList: {- originColumnList: Column[];- columnList: Column[];- wanted: {- addColumnList: AddColumnContext[];- alterColumnList: AlterColumnContext[];- changeColumnList: ChangeColumnContext[];- dropColumnList: DropColumnContext[];- };- }[] = [- {- originColumnList: [- {- id: "1",- name: "id",- type: "int",- comment: "",- nullable: true,- status: "normal",- } as any as Column,- ],- columnList: [- {- id: "1",- name: "id",- type: "varchar",- comment: "",- nullable: false,- status: "normal",- } as any as Column,- ],- wanted: {- addColumnList: [],- alterColumnList: [- {- oldName: "id",- newName: "id",- type: "varchar",- nullable: false,- defaultChanged: false,- },- ],- changeColumnList: [- {- oldName: "id",- newName: "id",- type: "varchar",- comment: "",- nullable: false,- characterSet: "",- collation: "",- default: undefined,- },- ],- dropColumnList: [],- },- },- ];-- for (const test of testList) {- const result = diffColumnList(test.originColumnList, test.columnList);- expect(result).toStrictEqual(test.wanted);- }-});--it("diff drop column list", () => {- const testList: {- originColumnList: Column[];- columnList: Column[];- wanted: {- addColumnList: AddColumnContext[];- alterColumnList: AlterColumnContext[];- changeColumnList: ChangeColumnContext[];- dropColumnList: DropColumnContext[];- };- }[] = [- {- originColumnList: [- {- id: "1",- name: "id",- type: "int",- comment: "",- nullable: true,- } as any as Column,- ],- columnList: [- {- id: "1",- name: "id",- type: "int",- comment: "",- nullable: true,- status: "dropped",- } as any as Column,- ],- wanted: {- addColumnList: [],- alterColumnList: [],- changeColumnList: [],- dropColumnList: [- {- name: "id",- },- ],- },- },- ];-- for (const test of testList) {- const result = diffColumnList(test.originColumnList, test.columnList);- expect(result).toStrictEqual(test.wanted);- }-});diff --git a/frontend/src/utils/schemaEditor/diffColumn.ts b/frontend/src/utils/schemaEditor/diffColumn.tsdeleted file mode 100644index 4386cdb7c4..0000000000--- a/frontend/src/utils/schemaEditor/diffColumn.ts+++ /dev/null@@ -1,88 +0,0 @@-import { isEqual, isUndefined } from "lodash-es";-import type {- AddColumnContext,- DropColumnContext,- ChangeColumnContext,- AlterColumnContext,-} from "@/types/schemaEditor";-import { Column } from "@/types/v1/schemaEditor";-import {- getColumnComment,- transformColumnToAddColumnContext,- transformColumnToChangeColumnContext,-} from "./transform";--// diffColumnList gets the differences between column object list.-// Including addColumnList, modifyColumnList and dropColumnList.-export const diffColumnList = (- originColumnList: Column[],- columnList: Column[]-) => {- const addColumnContextList: AddColumnContext[] = [];- const addedColumnList = columnList.filter(- (column) => column.status === "created"- );- for (const column of addedColumnList) {- addColumnContextList.push(transformColumnToAddColumnContext(column));- }-- const alterColumnContextList: AlterColumnContext[] = [];- const changeColumnContextList: ChangeColumnContext[] = [];- const changedColumnList = columnList.filter(- (column) => column.status === "normal"- );- for (const column of changedColumnList) {- const originColumn = originColumnList.find(- (originColumn) => originColumn.id === column.id- );- if (isUndefined(originColumn)) {- continue;- }- if (!isEqual(originColumn, column)) {- changeColumnContextList.push(- transformColumnToChangeColumnContext(originColumn, column)- );-- const alterColumnContext: AlterColumnContext = {- oldName: originColumn.name,- newName: column.name,- defaultChanged: false,- };- if (!isEqual(originColumn.type, column.type)) {- alterColumnContext.type = column.type;- }-- if (!isEqual(getColumnComment(originColumn), getColumnComment(column))) {- alterColumnContext.comment = getColumnComment(column);- }- if (!isEqual(originColumn.nullable, column.nullable)) {- alterColumnContext.nullable = column.nullable;- }- if (!isEqual(originColumn.default, column.default)) {- alterColumnContext.defaultChanged = true;- alterColumnContext.default = column.default;- }- alterColumnContextList.push(alterColumnContext);- }- }-- const dropColumnContextList: DropColumnContext[] = [];- const droppedColumnList = columnList.filter(- (column) => column.status === "dropped"- );- for (const column of droppedColumnList) {- const originColumn = originColumnList.find((item) => item.id === column.id);- if (originColumn) {- dropColumnContextList.push({- name: originColumn.name,- });- }- }-- return {- addColumnList: addColumnContextList,- alterColumnList: alterColumnContextList,- changeColumnList: changeColumnContextList,- dropColumnList: dropColumnContextList,- };-};diff --git a/frontend/src/utils/schemaEditor/diffSchema.ts b/frontend/src/utils/schemaEditor/diffSchema.tsdeleted file mode 100644index e33dc46085..0000000000--- a/frontend/src/utils/schemaEditor/diffSchema.ts+++ /dev/null@@ -1,319 +0,0 @@-import { isEqual, isUndefined } from "lodash-es";-import { useSchemaEditorV1Store } from "@/store";-import {- AlterTableContext,- CreateSchemaContext,- CreateTableContext,- DropSchemaContext,- DropTableContext,- RenameSchemaContext,- RenameTableContext,-} from "@/types/schemaEditor";-import { Schema } from "@/types/v1/schemaEditor";-import { diffColumnList } from "./diffColumn";-import { transformTableToCreateTableContext } from "./transform";--interface DiffResult {- createSchemaList: CreateSchemaContext[];- renameSchemaList: RenameSchemaContext[];- dropSchemaList: DropSchemaContext[];- createTableList: CreateTableContext[];- alterTableList: AlterTableContext[];- renameTableList: RenameTableContext[];- dropTableList: DropTableContext[];-}--export const diffSchema = (- database: string,- originSchema: Schema | undefined,- schema: Schema-): DiffResult => {- const schemaEditorV1Store = useSchemaEditorV1Store();- const createSchemaContextList: CreateSchemaContext[] = [];- const renameSchemaContextList: RenameSchemaContext[] = [];- const dropSchemaContextList: DropSchemaContext[] = [];- if (originSchema && originSchema.name !== schema.name) {- renameSchemaContextList.push({- oldName: originSchema.name,- newName: schema.name,- });- }- if (schema.status === "created") {- createSchemaContextList.push({- schema: schema.name,- });- } else if (schema.status === "dropped") {- dropSchemaContextList.push({- schema: schema.name,- });- }-- const createTableContextList: CreateTableContext[] = [];- const createdTableList = schema.tableList.filter(- (table) => table.status === "created"- );- for (const table of createdTableList) {- const createTableContext = transformTableToCreateTableContext(- schema.name,- table- );- const diffColumnListResult = diffColumnList([], table.columnList);- createTableContext.addColumnList = diffColumnListResult.addColumnList;- for (const columnId of table.primaryKey.columnIdList) {- const column = table.columnList.find((column) => column.id === columnId);- if (column) {- createTableContext.primaryKeyList.push(column.name);- }- }- const foreignKeyList = table.foreignKeyList.filter(- (fk) => fk.tableId === table.id- );- for (const foreignKey of foreignKeyList) {- const referencedSchema = schemaEditorV1Store.getSchema(- database,- foreignKey.referencedSchemaId- );- const referencedTable = schemaEditorV1Store.getTable(- database,- foreignKey.referencedSchemaId,- foreignKey.referencedTableId- );- if (referencedSchema && referencedTable) {- const columnNameList: string[] = [];- const referencedColumnNameList: string[] = [];- for (const columnId of foreignKey.columnIdList) {- const column = table.columnList.find(- (column) => column.id === columnId- );- if (column) {- columnNameList.push(column.name);- }- }- for (const referencedColumnId of foreignKey.referencedColumnIdList) {- const column = referencedTable.columnList.find(- (column) => column.id === referencedColumnId- );- if (column) {- referencedColumnNameList.push(column.name);- }- }-- createTableContext.addForeignKeyList.push({- columnList: columnNameList,- referencedSchema: referencedSchema.name,- referencedTable: referencedTable.name,- referencedColumnList: referencedColumnNameList,- });- }- }- createTableContextList.push(createTableContext);- }-- const alterTableContextList: AlterTableContext[] = [];- const renameTableContextList: RenameTableContext[] = [];- const changedTableList = schema.tableList.filter(- (table) => table.status === "normal"- );- for (const table of changedTableList) {- const originTable = originSchema?.tableList.find(- (originTable) => originTable.id === table.id- );- if (!originTable) {- continue;- }-- const originPrimaryKey = originTable.primaryKey;- const primaryKey = table.primaryKey;- const originForeignKeyList = originTable.foreignKeyList.filter(- (fk) => fk.tableId === table.id- );- const foreignKeyList = table.foreignKeyList.filter(- (fk) => fk.tableId === table.id- );-- if (- !isEqual(originTable, table) ||- !isEqual(originPrimaryKey, primaryKey) ||- !isEqual(originForeignKeyList, foreignKeyList)- ) {- if (originTable.name !== table.name) {- renameTableContextList.push({- schema: schema.name,- oldName: originTable.name,- newName: table.name,- });- }-- const columnListDiffResult = diffColumnList(- originTable.columnList,- table.columnList- );- if (- !isEqual(originPrimaryKey, primaryKey) ||- !isEqual(originForeignKeyList, foreignKeyList) ||- columnListDiffResult.addColumnList.length > 0 ||- columnListDiffResult.changeColumnList.length > 0 ||- columnListDiffResult.dropColumnList.length > 0- ) {- const alterTableContext: AlterTableContext = {- schema: schema.name,- name: table.name,- ...columnListDiffResult,- dropPrimaryKey: false,- dropPrimaryKeyList: [],- dropForeignKeyList: [],- addForeignKeyList: [],- };-- // Compose primary key changes.- if (!isEqual(originPrimaryKey, primaryKey)) {- const droppedColumnNameList = alterTableContext.dropColumnList.map(- (column) => column.name- );- const filterOriginPrimaryKeyColumnNameList: string[] = [];- for (const columnId of originPrimaryKey.columnIdList) {- const column = originTable.columnList.find(- (column) => column.id === columnId- );- if (column && !droppedColumnNameList.includes(column.name)) {- filterOriginPrimaryKeyColumnNameList.push(column.name);- }- }- const primaryKeyColumnNameList: string[] = [];- for (const columnId of primaryKey.columnIdList) {- const column = table.columnList.find(- (column) => column.id === columnId- );- if (column) {- primaryKeyColumnNameList.push(column.name);- }- }-- if (- !isEqual(- filterOriginPrimaryKeyColumnNameList,- primaryKeyColumnNameList- )- ) {- if (originPrimaryKey.columnIdList.length !== 0) {- alterTableContext.dropPrimaryKey = true;- alterTableContext.dropPrimaryKeyList.push(originPrimaryKey.name);- }- alterTableContext.primaryKeyList = primaryKeyColumnNameList;- }- }-- // Compose foreign key changes.- if (!isEqual(originForeignKeyList, foreignKeyList)) {- for (const foreignKey of foreignKeyList) {- const originForeignKey = originForeignKeyList?.find(- (fk) => fk.name === foreignKey.name- );-- if (!isEqual(originForeignKey, foreignKey)) {- if (!isUndefined(originForeignKey)) {- alterTableContext.dropForeignKeyList.push(- originForeignKey.name- );- }- if (- foreignKey.columnIdList.length > 0 &&- foreignKey.columnIdList.length ===- foreignKey.referencedColumnIdList.length- ) {- const referencedSchema = schemaEditorV1Store.getSchema(- database,- foreignKey.referencedSchemaId- );- const referencedTable = referencedSchema?.tableList.find(- (table) => table.id === foreignKey.referencedTableId- );- if (!referencedSchema || !referencedTable) {- continue;- }-- const columnList: string[] = [];- const referencedColumnList: string[] = [];- for (const columnId of foreignKey.columnIdList) {- const column = table.columnList.find(- (column) => column.id === columnId- );- const columnIndex = foreignKey.columnIdList.findIndex(- (item) => item === column?.id- );- const referencedColumn = referencedTable?.columnList.find(- (column) =>- column.id ===- foreignKey.referencedColumnIdList[columnIndex]- );- if (- column &&- referencedColumn &&- column.status !== "dropped"- ) {- columnList.push(column.name);- referencedColumnList.push(referencedColumn.name);- }- }-- alterTableContext.addForeignKeyList.push({- columnList,- referencedSchema: referencedSchema.name,- referencedTable: referencedTable.name,- referencedColumnList,- });- }- }- }- }-- alterTableContextList.push(alterTableContext);- }- }- }-- const dropTableContextList: DropTableContext[] = [];- const droppedTableList = schema.tableList.filter(- (table) => table.status === "dropped"- );- for (const table of droppedTableList) {- dropTableContextList.push({- schema: schema.name,- name: table.name,- });- }-- return {- createSchemaList: createSchemaContextList,- renameSchemaList: renameSchemaContextList,- dropSchemaList: dropSchemaContextList,- createTableList: createTableContextList,- alterTableList: alterTableContextList,- renameTableList: renameTableContextList,- dropTableList: dropTableContextList,- };-};--export const checkHasSchemaChanges = (diffResult: DiffResult): boolean => {- return (- diffResult.createSchemaList.length > 0 ||- diffResult.renameSchemaList.length > 0 ||- diffResult.dropSchemaList.length > 0 ||- diffResult.createTableList.length > 0 ||- diffResult.alterTableList.length > 0 ||- diffResult.renameTableList.length > 0 ||- diffResult.dropTableList.length > 0- );-};--export const mergeDiffResults = (diffResults: DiffResult[]): DiffResult => {- return {- createSchemaList: diffResults.map((item) => item.createSchemaList).flat(),- renameSchemaList: diffResults.map((item) => item.renameSchemaList).flat(),- dropSchemaList: diffResults.map((item) => item.dropSchemaList).flat(),- createTableList: diffResults.map((item) => item.createTableList).flat(),- alterTableList: diffResults.map((item) => item.alterTableList).flat(),- renameTableList: diffResults.map((item) => item.renameTableList).flat(),- dropTableList: diffResults.map((item) => item.dropTableList).flat(),- };-};diff --git a/frontend/src/utils/schemaEditor/transform.ts b/frontend/src/utils/schemaEditor/transform.tsdeleted file mode 100644index a10d113067..0000000000--- a/frontend/src/utils/schemaEditor/transform.ts+++ /dev/null@@ -1,65 +0,0 @@-import { defaultTo } from "lodash-es";-import {- AddColumnContext,- CreateTableContext,- ChangeColumnContext,-} from "@/types";-import { Column, Table } from "@/types/v1/schemaEditor";--export const getColumnComment = (column: Column): string => {- return [- defaultTo(column.classification, ""),- defaultTo(column.userComment, ""),- ]- .filter((val) => val)- .join("-");-};--export const transformColumnToAddColumnContext = (- column: Column-): AddColumnContext => {- return {- name: defaultTo(column.name, ""),- type: defaultTo(column.type, ""),- comment: getColumnComment(column),- nullable: defaultTo(column.nullable, false),- default: defaultTo(column.default, undefined),- characterSet: "",- collation: "",- };-};--export const transformColumnToChangeColumnContext = (- originColumn: Column,- column: Column-): ChangeColumnContext => {- return {- oldName: defaultTo(originColumn.name, ""),- newName: defaultTo(column.name, ""),- type: defaultTo(column.type, ""),- comment: getColumnComment(column),- nullable: defaultTo(column.nullable, false),- default: defaultTo(column.default, undefined),- characterSet: "",- collation: "",- };-};--export const transformTableToCreateTableContext = (- schema: string,- table: Table-): CreateTableContext => {- return {- schema,- name: defaultTo(table.name, ""),- engine: defaultTo(table.engine, ""),- collation: defaultTo(table.collation, ""),- comment: defaultTo(table.comment, ""),- addColumnList: [],- primaryKeyList: [],- addForeignKeyList: [],- // As we don't have a CharacterSet field in table model,- // set it as an empty string for now.- characterSet: "",- };-};diff --git a/frontend/src/utils/schemaEditor/validate.ts b/frontend/src/utils/schemaEditor/validate.tsdeleted file mode 100644index c5e2340857..0000000000--- a/frontend/src/utils/schemaEditor/validate.ts+++ /dev/null@@ -1,18 +0,0 @@-import { DatabaseEdit, ValidateResult } from "@/types";--export const validateDatabaseEdit = (- databaseEdit: DatabaseEdit-): ValidateResult[] => {- const validateResultList: ValidateResult[] = [];-- for (const createTableContext of databaseEdit.createTableList) {- if (createTableContext.addColumnList.length === 0) {- validateResultList.push({- type: "ERROR",- message: `Table ${createTableContext.name} should has at least one column.`,- });- }- }-- return validateResultList;-};