Skip to content

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

Add v-database-sync-status directive to transform database sync status type

天舟3d86495ece7b
diff --git a/frontend/src/components/DatabaseTable.vue b/frontend/src/components/DatabaseTable.vue
index 0208c9a356..419bdf3c57 100644
--- a/frontend/src/components/DatabaseTable.vue
+++ b/frontend/src/components/DatabaseTable.vue
@@ -17,7 +17,7 @@
<BBTableCell class="w-24">
{{ instanceName(database.instance) }}
</BBTableCell>
- <BBTableCell class="w-8">
+ <BBTableCell class="w-8" v-database-sync-status>
{{ database.syncStatus }}
</BBTableCell>
<BBTableCell class="w-16">
diff --git a/frontend/src/directives/database-sync-status.ts b/frontend/src/directives/database-sync-status.ts
new file mode 100644
index 0000000000..e11169dabd
--- /dev/null
+++ b/frontend/src/directives/database-sync-status.ts
@@ -0,0 +1,20 @@
+import { DatabaseSyncStatus } from "../types";
+
+const directive = {
+ beforeMount(el: HTMLElement) {
+ const syncStatus = el.innerText as DatabaseSyncStatus;
+ switch (syncStatus) {
+ case "OK":
+ el.innerText = "OK";
+ return;
+ case "DRIFTED":
+ el.innerText = "Drifted";
+ return;
+ case "NOT_FOUND":
+ el.innerText = "Not found";
+ return;
+ }
+ },
+};
+
+export default directive;
diff --git a/frontend/src/main.js b/frontend/src/main.js
index 381b39b8c7..a27b8b1552 100644
--- a/frontend/src/main.js
+++ b/frontend/src/main.js
@@ -29,6 +29,7 @@ import {
BBTableTabFilter,
BBTextField,
} from "./bbkit";
+import databaseSyncStatus from "./directives/database-sync-status";
import dataSourceType from "./directives/data-source-type";
import highlight from "./directives/highlight";
import role from "./directives/role";
@@ -78,6 +79,7 @@ app
// The normal hljs.initHighlightingOnLoad() won't work because router change would cause vue
// to re-render the page and remove the event listener required for
.directive("highlight", highlight)
+ .directive("database-sync-status", databaseSyncStatus)
.directive("data-source-type", dataSourceType)
.directive("role", role)
.use(store)
diff --git a/frontend/src/miragejs/factories/database.js b/frontend/src/miragejs/factories/database.js
index 65d47cf41a..9d1546bda1 100644
--- a/frontend/src/miragejs/factories/database.js
+++ b/frontend/src/miragejs/factories/database.js
@@ -21,7 +21,7 @@ export default {
return "OK";
}
if (i % 3 == 1) {
- return "MISMATCH";
+ return "DRIFTED";
}
if (i % 3 == 2) {
return "NOT_FOUND";
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index 6d96d72ed7..c132fd0f6d 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -710,11 +710,11 @@ export type DataSourceMemberNew = {
// in the "database" object.
// "OK" means find the exact match
-// "MISMATCH" means we find the database with the same name, but the fingerprint is different,
+// "DRIFTED" means we find the database with the same name, but the fingerprint is different,
// this usually indicates the underlying database has been recreated (might for a entirely different purpose)
// "NOT_FOUND" means no matching database name found, this ususally means someone changes
// the underlying db name.
-export type DatabaseSyncStatus = "OK" | "MISMATCH" | "NOT_FOUND";
+export type DatabaseSyncStatus = "OK" | "DRIFTED" | "NOT_FOUND";
// Database
export type Database = {
id: DatabaseId;
diff --git a/frontend/src/views/DatabaseDetail.vue b/frontend/src/views/DatabaseDetail.vue
index ddcb55c4a0..c882fbf793 100644
--- a/frontend/src/views/DatabaseDetail.vue
+++ b/frontend/src/views/DatabaseDetail.vue
@@ -48,7 +48,7 @@
<dt class="sr-only">Sync Status</dt>
<dd class="flex items-center text-sm md:mr-4">
<span class="textlabel">Sync status&nbsp;-&nbsp;</span>
- {{ database.syncStatus }}
+ <span v-database-sync-status>{{ database.syncStatus }}</span>
</dd>
<dt class="sr-only">Last successful sync</dt>
<dd class="flex items-center text-sm">