Skip to content

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

chore: add drifted filter to listing database (#15903)

boojack740e5489f45c
diff --git a/backend/api/v1/database_service.go b/backend/api/v1/database_service.go
index fddf91c438..08120bfc6c 100644
--- a/backend/api/v1/database_service.go
+++ b/backend/api/v1/database_service.go
@@ -220,6 +220,16 @@ func getListDatabaseFilter(filter string) (*store.ListResourceFilter, error) {
labelValues := strings.Split(keyVal[1], ",")
positionalArgs = append(positionalArgs, labelValues)
return fmt.Sprintf("db.metadata->'labels'->>'%s' = ANY($%d)", labelKey, len(positionalArgs)), nil
+ case "drifted":
+ drifted, ok := value.(bool)
+ if !ok {
+ return "", status.Errorf(codes.InvalidArgument, "invalid drifted filter %q", value)
+ }
+ condition := "IS"
+ if !drifted {
+ condition = "IS NOT"
+ }
+ return fmt.Sprintf("(db.metadata->>'drifted')::boolean %s TRUE", condition), nil
case "exclude_unassigned":
if _, ok := value.(bool); ok {
positionalArgs = append(positionalArgs, base.DefaultProjectID)
diff --git a/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts b/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts
index c6cb5e454e..71db6cf19f 100644
--- a/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts
+++ b/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts
@@ -171,6 +171,24 @@ export const useCommonSearchScopeOptions = (
}),
allowMultiple: true,
}),
+ drifted: () => ({
+ id: "drifted",
+ title: t("database.drifted.self"),
+ description: t("database.drifted.schema-drift-detected.self"),
+ options: [
+ {
+ value: "true",
+ keywords: ["true"],
+ render: () => "TRUE",
+ },
+ {
+ value: "false",
+ keywords: ["false"],
+ render: () => "FALSE",
+ },
+ ],
+ allowMultiple: false,
+ }),
} as Record<SearchScopeId, () => ScopeOption>;
const scopes: ScopeOption[] = [];
diff --git a/frontend/src/components/ProjectDatabasesPanel.vue b/frontend/src/components/ProjectDatabasesPanel.vue
index 6ce15dedcc..bd40f85544 100644
--- a/frontend/src/components/ProjectDatabasesPanel.vue
+++ b/frontend/src/components/ProjectDatabasesPanel.vue
@@ -129,6 +129,7 @@ const scopeOptions = useCommonSearchScopeOptions([
...CommonFilterScopeIdList,
"database-label",
"engine",
+ "drifted",
]);
const selectedInstance = computed(() => {
@@ -163,12 +164,23 @@ const selectedEngines = computed(() => {
.map((scope) => engineFromJSON(scope.value));
});
+const selectedDriftedValue = computed(() => {
+ const driftedValue = state.params.scopes.find(
+ (scope) => scope.id === "drifted"
+ )?.value;
+ if (driftedValue === undefined) {
+ return undefined;
+ }
+ return driftedValue === "true" ? true : false;
+});
+
const filter = computed(() => ({
instance: selectedInstance.value,
environment: selectedEnvironment.value,
query: state.params.query,
labels: selectedLabels.value,
engines: selectedEngines.value,
+ drifted: selectedDriftedValue.value,
}));
const selectedDatabases = computed((): ComposedDatabase[] => {
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 3681013c76..1dbdd24537 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -1492,6 +1492,7 @@
},
"not-found": "Cannot found the database",
"drifted": {
+ "self": "Schema drifted",
"schema-drift-detected": {
"self": "Schema drift detected",
"description": "The schema is different from the last applied schema. This may cause application errors and should be resolved."
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index e9303b20c8..20cbc74b67 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -1492,6 +1492,7 @@
},
"not-found": "No se puede encontrar la base de datos",
"drifted": {
+ "self": "El esquema se desvió",
"schema-drift-detected": {
"self": "Se detectó una desviación del esquema",
"description": "El esquema es diferente del último aplicado. Esto puede causar errores de aplicación y debe solucionarse."
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 77030fb5b4..85dd2c0193 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -1492,6 +1492,7 @@
},
"not-found": "データベースが見つかりません",
"drifted": {
+ "self": "スキーマがずれた",
"schema-drift-detected": {
"self": "スキーマドリフトが検出されました",
"description": "スキーマが最後に適用されたスキーマと異なります。アプリケーションエラーが発生する可能性があるため、解決する必要があります。"
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index 9a1fde5427..2e22116bc2 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -1492,6 +1492,7 @@
},
"not-found": "Không tìm thấy cơ sở dữ liệu",
"drifted": {
+ "self": "Sơ đồ trôi dạt",
"schema-drift-detected": {
"self": "Đã phát hiện sự trôi dạt của sơ đồ",
"description": "Sơ đồ khác với sơ đồ được áp dụng lần cuối. Điều này có thể gây ra lỗi ứng dụng và cần được giải quyết."
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index afaf55de65..76022a5511 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -1492,6 +1492,7 @@
},
"not-found": "找不到数据库",
"drifted": {
+ "self": "Schema 偏差",
"schema-drift-detected": {
"self": "检测到 Schema 偏差",
"description": "当前数据库 Schema 与 Bytebase 中记录的 Schema 不一致。请及时检查并修复以避免潜在问题。"
diff --git a/frontend/src/store/modules/v1/database.ts b/frontend/src/store/modules/v1/database.ts
index 579f02abc4..5fd0adb9f5 100644
--- a/frontend/src/store/modules/v1/database.ts
+++ b/frontend/src/store/modules/v1/database.ts
@@ -20,7 +20,7 @@ import type {
BatchUpdateDatabasesRequest,
} from "@/types/proto/v1/database_service";
import type { InstanceResource } from "@/types/proto/v1/instance_service";
-import { extractDatabaseResourceName } from "@/utils";
+import { extractDatabaseResourceName, isNullOrUndefined } from "@/utils";
import {
instanceNamePrefix,
projectNamePrefix,
@@ -41,6 +41,7 @@ export interface DatabaseFilter {
labels?: string[];
engines?: Engine[];
excludeEngines?: Engine[];
+ drifted?: boolean;
}
const isValidParentName = (parent: string): boolean => {
@@ -83,6 +84,9 @@ const getListDatabaseFilter = (filter: DatabaseFilter): string => {
`!(engine in [${filter.excludeEngines.map((e) => `"${engineToJSON(e)}"`).join(", ")}])`
);
}
+ if (!isNullOrUndefined(filter.drifted)) {
+ params.push(`drifted == ${filter.drifted}`);
+ }
const keyword = filter.query?.trim()?.toLowerCase();
if (keyword) {
params.push(`name.matches("${keyword}")`);
diff --git a/frontend/src/utils/v1/advanced-search/common.ts b/frontend/src/utils/v1/advanced-search/common.ts
index cb9369a3c8..574cdbb656 100644
--- a/frontend/src/utils/v1/advanced-search/common.ts
+++ b/frontend/src/utils/v1/advanced-search/common.ts
@@ -27,6 +27,7 @@ export const AllSearchScopeIdList = [
// database related search scopes.
"engine",
"database-label",
+ "drifted",
// issue related search scopes.
"subscriber",
"label",