Skip to content

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

feat(schema-editor): highlight changed column (#4234)

boojackeb683220a40f
diff --git a/frontend/src/components/SchemaEditor/Panels/TableEditor.vue b/frontend/src/components/SchemaEditor/Panels/TableEditor.vue
index 186aa6e1c3..de4e41d344 100644
--- a/frontend/src/components/SchemaEditor/Panels/TableEditor.vue
+++ b/frontend/src/components/SchemaEditor/Panels/TableEditor.vue
@@ -76,9 +76,8 @@
:key="`${index}-${column.id}`"
class="grid grid-cols-[repeat(4,_minmax(0,_1fr))_repeat(2,_96px)_minmax(0,_1fr)_32px] gr text-sm even:bg-gray-50"
:class="[
- isDroppedColumn(column) &&
- 'text-red-700 cursor-not-allowed !bg-red-50 opacity-70',
`column-${column.id}`,
+ getColumnItemComputedClassList(column),
]"
>
<div class="table-body-item-container">
@@ -277,6 +276,7 @@ import {
import { getDataTypeSuggestionList } from "@/utils";
import { BBCheckbox, BBSpin } from "@/bbkit";
import HighlightCodeBlock from "@/components/HighlightCodeBlock";
+import { isColumnChanged } from "../utils/column";
import { isTableChanged } from "../utils/table";
import { diffSchema } from "@/utils/schemaEditor/diffSchema";
import EditColumnForeignKeyModal from "../Modals/EditColumnForeignKeyModal.vue";
@@ -388,6 +388,24 @@ const dataTypeOptions = computed(() => {
});
});
+const getColumnItemComputedClassList = (column: Column) => {
+ if (column.status === "dropped") {
+ return ["text-red-700", "cursor-not-allowed", "!bg-red-50", "opacity-70"];
+ } else if (column.status === "created") {
+ return ["text-green-700", "!bg-green-50"];
+ } else if (
+ isColumnChanged(
+ currentTab.value.databaseId,
+ currentTab.value.schemaId,
+ currentTab.value.tableId,
+ column.id
+ )
+ ) {
+ return ["text-yellow-700", "!bg-yellow-50"];
+ }
+ return [];
+};
+
const dataDefaultOptions = [
{
label: "NULL",
diff --git a/frontend/src/components/SchemaEditor/utils/column.ts b/frontend/src/components/SchemaEditor/utils/column.ts
new file mode 100644
index 0000000000..70659c1d21
--- /dev/null
+++ b/frontend/src/components/SchemaEditor/utils/column.ts
@@ -0,0 +1,51 @@
+import { isEqual, isUndefined } from "lodash-es";
+import { useSchemaEditorStore } from "@/store";
+import { DatabaseId } from "@/types";
+
+export const isColumnChanged = (
+ databaseId: DatabaseId,
+ schemaId: string,
+ tableId: string,
+ columnId: string
+): boolean => {
+ const editorStore = useSchemaEditorStore();
+ const originSchema = editorStore.getOriginSchema(databaseId, schemaId);
+ const schema = editorStore.getSchema(databaseId, schemaId);
+ const table = schema?.tableList.find((table) => table.id === tableId);
+ const originTable = originSchema?.tableList.find(
+ (table) => table.id === tableId
+ );
+ const column = table?.columnList.find((column) => column.id === columnId);
+ const originColumn = originTable?.columnList.find(
+ (column) => column.id === columnId
+ );
+
+ const isPrimaryKey = table?.primaryKey.columnIdList.includes(columnId);
+ const isPrimaryKeyOrigin =
+ originTable?.primaryKey.columnIdList.includes(columnId);
+
+ const originForeignKey = originSchema?.foreignKeyList.find(
+ (fk) => fk.tableId === table?.id && fk.columnIdList.includes(columnId)
+ );
+ const foreignKey = schema?.foreignKeyList.find(
+ (fk) => fk.tableId === table?.id && fk.columnIdList.includes(columnId)
+ );
+ const originIndex = originForeignKey?.columnIdList.findIndex(
+ (column) => column === columnId
+ );
+ const originForeignKeyColumn = isUndefined(originIndex)
+ ? undefined
+ : originForeignKey?.referencedColumnIdList[originIndex];
+ const index = foreignKey?.columnIdList.findIndex(
+ (column) => column === columnId
+ );
+ const foreignKeyColumn = isUndefined(index)
+ ? undefined
+ : foreignKey?.referencedColumnIdList[index];
+
+ return (
+ !isEqual(column, originColumn) ||
+ !isEqual(isPrimaryKey, isPrimaryKeyOrigin) ||
+ !isEqual(foreignKeyColumn, originForeignKeyColumn)
+ );
+};