Skip to content

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

feat: show checks (#16181)

rebeliced7eded08a4ca
diff --git a/frontend/src/components/Icon/CheckIcon.vue b/frontend/src/components/Icon/CheckIcon.vue
new file mode 100644
index 0000000000..1957a5f069
--- /dev/null
+++ b/frontend/src/components/Icon/CheckIcon.vue
@@ -0,0 +1,7 @@
+<template>
+ <CheckIcon class="w-3 h-3" />
+</template>
+
+<script setup lang="ts">
+import CheckIcon from "~icons/tabler/check";
+</script>
\ No newline at end of file
diff --git a/frontend/src/components/Icon/index.ts b/frontend/src/components/Icon/index.ts
index aecf5ca4ca..6d9a3b9bf9 100644
--- a/frontend/src/components/Icon/index.ts
+++ b/frontend/src/components/Icon/index.ts
@@ -1,3 +1,4 @@
+import CheckIcon from "./CheckIcon.vue";
import ColumnIcon from "./ColumnIcon.vue";
import DatabaseIcon from "./DatabaseIcon.vue";
import EngineIcon from "./EngineIcon.vue";
@@ -34,4 +35,5 @@ export {
PackageIcon,
SequenceIcon,
TriggerIcon,
+ CheckIcon,
};
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 22e51efd35..b129a5d246 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1484,6 +1484,7 @@
"foreign-key": {
"reference": "Reference"
},
+ "checks": "Checks",
"create-target-database-or-schema-for-backup": "Please create the target database or schema for the backup first",
"revision": {
"self": "Revision",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 3eae1ca8cb..e9e4f1f017 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1505,7 +1505,8 @@
"self": "Nueva línea base",
"successfully-established": "Se estableció con éxito una nueva línea base"
}
- }
+ },
+ "checks": "Cheques"
},
"project": {
"table": {
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 7cdf6c5026..98d964d1a4 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -1505,7 +1505,8 @@
"self": "新しいベースライン",
"successfully-established": "新しいベースラインを確立しました"
}
- }
+ },
+ "checks": "チェック"
},
"project": {
"table": {
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 0cb65cef78..2e4c412c00 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -1505,7 +1505,8 @@
"self": "Đường cơ sở mới",
"successfully-established": "Đã thiết lập thành công đường cơ sở mới"
}
- }
+ },
+ "checks": "Kiểm tra"
},
"project": {
"table": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index c2fca7ffe1..fd79e2c363 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1505,7 +1505,8 @@
"self": "建立新基线",
"successfully-established": "成功建立新的基线"
}
- }
+ },
+ "checks": "Check 约束"
},
"project": {
"table": {
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/CheckNode.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/CheckNode.vue
new file mode 100644
index 0000000000..5ed227dee6
--- /dev/null
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/CheckNode.vue
@@ -0,0 +1,61 @@
+<template>
+ <CommonNode
+ :text="target.check"
+ :keyword="keyword"
+ :highlight="true"
+ :indent="0"
+ >
+ <template #icon>
+ <CheckIcon class="!w-3.5 !h-3.5 text-gray-500" />
+ </template>
+ <template #suffix>
+ <div
+ class="flex items-center justify-end gap-1 overflow-hidden whitespace-nowrap shrink opacity-80 !font-normal"
+ >
+ <NTag
+ size="small"
+ class="text-size-adjust-none"
+ style="--n-height: 16px; --n-padding: 0 3px; --n-font-size: 10px"
+ >
+ {{ checkMetadata?.expression }}
+ </NTag>
+ </div>
+ </template>
+ </CommonNode>
+</template>
+
+<script setup lang="ts">
+import { NTag } from "naive-ui";
+import { computed } from "vue";
+import { CheckIcon } from "@/components/Icon";
+import type { TreeNode } from "../tree";
+import { useDBSchemaV1Store } from "@/store";
+import CommonNode from "./CommonNode.vue";
+
+const props = defineProps<{
+ node: TreeNode;
+ keyword: string;
+}>();
+
+const dbSchema = useDBSchemaV1Store();
+const target = computed(
+ () => (props.node as TreeNode<"check">).meta.target
+);
+
+const tableMetadata = computed(() => {
+ if ("table" in target.value) {
+ const { database, schema, table } = target.value;
+ return dbSchema.getTableMetadata({ database, schema, table });
+ }
+ return undefined;
+});
+
+const checkMetadata = computed(() => {
+ const { check } = target.value;
+
+ if ("table" in target.value) {
+ return tableMetadata.value?.checkConstraints.find((c) => c.name === check);
+ }
+ return undefined;
+});
+</script>
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/Label.vue b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/Label.vue
index 9c87b8f40d..9e7159240a 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/Label.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/TreeNode/Label.vue
@@ -20,6 +20,9 @@
<template v-if="type === 'foreign-key'">
<ForeignKeyNode :node="node" :keyword="keyword" />
</template>
+ <template v-if="type === 'check'">
+ <CheckNode :node="node" :keyword="keyword" />
+ </template>
<template v-if="type === 'partition-table'">
<PartitionTableNode :node="node" :keyword="keyword" />
</template>
@@ -55,6 +58,7 @@
<script lang="ts" setup>
import { computed } from "vue";
import type { TreeNode } from "../tree";
+import CheckNode from "./CheckNode.vue";
import ColumnNode from "./ColumnNode.vue";
import DatabaseNode from "./DatabaseNode.vue";
import DependencyColumnNode from "./DependencyColumnNode.vue";
diff --git a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/tree.ts b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/tree.ts
index 54241831b7..914a9375ca 100644
--- a/frontend/src/views/sql-editor/AsidePanel/SchemaPane/tree.ts
+++ b/frontend/src/views/sql-editor/AsidePanel/SchemaPane/tree.ts
@@ -3,6 +3,7 @@ import { type RenderFunction } from "vue";
import { t } from "@/plugins/i18n";
import type { ComposedDatabase } from "@/types";
import type {
+ CheckConstraintMetadata,
ColumnMetadata,
DatabaseMetadata,
DependencyColumn,
@@ -30,6 +31,7 @@ export type NodeType =
| "column"
| "index"
| "foreign-key"
+ | "check"
| "dependency-column"
| "expandable-text" // Text nodes to display "Tables / Views / Functions / Triggers" etc.
| "error"; // Error nodes to display "<Empty>" or "Cannot fetch ..." etc.
@@ -62,6 +64,9 @@ export type RichIndexMetadata = RichTableMetadata & {
export type RichForeignKeyMetadata = RichTableMetadata & {
foreignKey: string;
};
+export type RichCheckMetadata = RichTableMetadata & {
+ check: string;
+};
export type RichPartitionTableMetadata = RichTableMetadata & {
partition: string;
};
@@ -116,25 +121,27 @@ export type NodeTarget<T extends NodeType = NodeType> = T extends "database"
? RichIndexMetadata
: T extends "foreign-key"
? RichForeignKeyMetadata
- : T extends "partition-table"
- ? RichPartitionTableMetadata
- : T extends "view"
- ? RichViewMetadata
- : T extends "procedure"
- ? RichProcedureMetadata
- : T extends "package"
- ? RichPackageMetadata
- : T extends "function"
- ? RichFunctionMetadata
- : T extends "sequence"
- ? RichSequenceMetadata
- : T extends "trigger"
- ? RichTriggerMetadata
- : T extends "expandable-text"
- ? TextTarget<true, any>
- : T extends "error"
- ? ErrorTarget
- : never;
+ : T extends "check"
+ ? RichCheckMetadata
+ : T extends "partition-table"
+ ? RichPartitionTableMetadata
+ : T extends "view"
+ ? RichViewMetadata
+ : T extends "procedure"
+ ? RichProcedureMetadata
+ : T extends "package"
+ ? RichPackageMetadata
+ : T extends "function"
+ ? RichFunctionMetadata
+ : T extends "sequence"
+ ? RichSequenceMetadata
+ : T extends "trigger"
+ ? RichTriggerMetadata
+ : T extends "expandable-text"
+ ? TextTarget<true, any>
+ : T extends "error"
+ ? ErrorTarget
+ : never;
export type TreeState = "UNSET" | "LOADING" | "READY";
@@ -162,6 +169,7 @@ export const LeafNodeTypes: readonly NodeType[] = [
"column",
"index",
"foreign-key",
+ "check",
"procedure",
"package",
"function",
@@ -243,6 +251,12 @@ export const keyForNodeTarget = <T extends NodeType>(
keyForNodeTarget("table", target as NodeTarget<"table">),
`foreignKeys/${foreignKey}`,
].join("/");
+ case "check":
+ const { check } = target as NodeTarget<"check">;
+ return [
+ keyForNodeTarget("table", target as NodeTarget<"table">),
+ `checks/${check}`,
+ ].join("/");
case "partition-table":
const { partition } = target as NodeTarget<"partition-table">;
return [
@@ -422,6 +436,26 @@ const mapForeignKeyNodes = (
return children;
};
+const mapCheckNodes = (
+ target: NodeTarget<"table">,
+ checks: CheckConstraintMetadata[],
+ parentKey: string
+) => {
+ if (checks.length === 0) {
+ // Create a "<Empty>" check node placeholder
+ return [createDummyNode("check", parentKey)];
+ }
+
+ const children = checks.map((check) => {
+ const node = mapTreeNodeByType("check", {
+ ...target,
+ check: check.name,
+ });
+ return node;
+ });
+ return children;
+};
+
const mapTableNodes = (
schema: SchemaMetadata,
target: NodeTarget<"schema">,
@@ -485,6 +519,21 @@ const mapTableNodes = (
);
node.children.push(triggerNode);
}
+
+ // Map checks
+ if (table.checkConstraints.length > 0) {
+ const checksFolderNode = createExpandableTextNode(
+ "check",
+ node.key,
+ () => t("database.checks")
+ );
+ checksFolderNode.children = mapCheckNodes(
+ node.meta.target,
+ table.checkConstraints,
+ checksFolderNode.key
+ )
+ node.children.push(checksFolderNode);
+ }
// Map table-level partitions.
if (table.partitions.length > 0) {