Skip to content

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

chore: only allow to editor the first partition/sub-partition (#13651)

Liu Ji0fd0a8792da5
diff --git a/frontend/src/components/SchemaEditorLite/Panels/PartitionsEditor/PartitionsEditor.vue b/frontend/src/components/SchemaEditorLite/Panels/PartitionsEditor/PartitionsEditor.vue
index ce9ed99f0f..72e9407e3c 100644
--- a/frontend/src/components/SchemaEditorLite/Panels/PartitionsEditor/PartitionsEditor.vue
+++ b/frontend/src/components/SchemaEditorLite/Panels/PartitionsEditor/PartitionsEditor.vue
@@ -28,7 +28,7 @@
<script setup lang="tsx">
import { useElementSize } from "@vueuse/core";
-import { pull } from "lodash-es";
+import { head, pull } from "lodash-es";
import { ChevronDownIcon } from "lucide-vue-next";
import { NDataTable, type DataTableColumn } from "naive-ui";
import { computed, ref } from "vue";
@@ -181,10 +181,38 @@ const flattenItemList = computed(() => {
return list;
});
+const firstPartition = computed(() => {
+ return head(
+ flattenItemList.value.filter((item) => item.parent === undefined)
+ );
+});
+const firstSubPartition = computed(() => {
+ return head(
+ flattenItemList.value.filter((item) => item.parent !== undefined)
+ );
+});
+
const getItemKey = (item: FlattenTablePartitionMetadata) => {
return markUUID(item.partition);
};
+const allowEditTypeAndExprForItem = (item: FlattenTablePartitionMetadata) => {
+ if (
+ item.parent === undefined &&
+ firstPartition.value &&
+ item !== firstPartition.value
+ ) {
+ return false;
+ } else if (
+ item.parent !== undefined &&
+ firstSubPartition.value &&
+ item !== firstSubPartition.value
+ ) {
+ return false;
+ }
+ return true;
+};
+
const columns = computed(() => {
const columns: (DataTableColumn<FlattenTablePartitionMetadata> & {
hide?: boolean;
@@ -227,13 +255,30 @@ const columns = computed(() => {
minWidth: 140,
className: "input-cell",
render: (item) => {
+ if (!allowEditTypeAndExprForItem(item)) {
+ return (
+ <div
+ class="flex items-center text-control-placeholder italic cursor-disallowed px-1.5"
+ style="height: 34px"
+ >
+ {item.partition.type}
+ </div>
+ );
+ }
return (
<TypeCell
readonly={!allowEditPartition(item.partition)}
partition={item.partition}
parent={item.parent}
onUpdate:type={(type) => {
- item.partition.type = type;
+ flattenItemList.value
+ .filter((it) => {
+ if (item.parent === undefined) return it.parent === undefined;
+ return it.parent !== undefined;
+ })
+ .forEach((it) => {
+ it.partition.type = type;
+ });
emit("update");
}}
/>
@@ -247,12 +292,29 @@ const columns = computed(() => {
minWidth: 140,
className: "input-cell",
render: (item) => {
+ if (!allowEditTypeAndExprForItem(item)) {
+ return (
+ <div
+ class="flex items-center text-control-placeholder italic cursor-disallowed px-1.5"
+ style="height: 34px"
+ >
+ {item.partition.expression}
+ </div>
+ );
+ }
return (
<ExpressionCell
readonly={!allowEditPartition(item.partition)}
partition={item.partition}
onUpdate:expression={(expression) => {
- item.partition.expression = expression;
+ flattenItemList.value
+ .filter((it) => {
+ if (item.parent === undefined) return it.parent === undefined;
+ return it.parent !== undefined;
+ })
+ .forEach((it) => {
+ it.partition.expression = expression;
+ });
emit("update");
}}
/>
@@ -331,8 +393,10 @@ const columns = computed(() => {
}
}}
onAdd-sub={() => {
+ const first = firstSubPartition.value;
const sub = TablePartitionMetadata.fromPartial({
- type: TablePartitionMetadata_Type.HASH,
+ type: first?.partition.type ?? TablePartitionMetadata_Type.HASH,
+ expression: first?.partition.expression ?? "",
});
markStatus(sub, "created");
if (item.partition.subpartitions) {
diff --git a/frontend/src/components/SchemaEditorLite/Panels/TableEditor.vue b/frontend/src/components/SchemaEditorLite/Panels/TableEditor.vue
index ff59eee4e2..a9e1c144fe 100644
--- a/frontend/src/components/SchemaEditorLite/Panels/TableEditor.vue
+++ b/frontend/src/components/SchemaEditorLite/Panels/TableEditor.vue
@@ -189,7 +189,7 @@
</template>
<script lang="ts" setup>
-import { cloneDeep, pull } from "lodash-es";
+import { cloneDeep, head, pull } from "lodash-es";
import { PlusIcon } from "lucide-vue-next";
import { ArrowLeftIcon } from "lucide-vue-next";
import { NButton } from "naive-ui";
@@ -450,8 +450,10 @@ const handleAddIndex = () => {
markTableStatus("updated");
};
const handleAddPartition = () => {
+ const first = head(props.table.partitions);
const partition = TablePartitionMetadata.fromPartial({
- type: TablePartitionMetadata_Type.HASH,
+ type: first?.type ?? TablePartitionMetadata_Type.HASH,
+ expression: first?.expression ?? "",
});
// eslint-disable-next-line vue/no-mutating-props
props.table.partitions.push(partition);