Skip to content

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

Introduce ZERO_ID to represent the expected behavior that there is no ID

天舟46443c249324
diff --git a/frontend/src/components/IssueTable.vue b/frontend/src/components/IssueTable.vue
index 5956ad139f..67eec83b33 100644
--- a/frontend/src/components/IssueTable.vue
+++ b/frontend/src/components/IssueTable.vue
@@ -125,7 +125,7 @@ import {
activeDatabaseId,
activeStage,
} from "../utils";
-import { Issue } from "../types";
+import { Issue, ZERO_ID } from "../types";
type Mode = "ALL" | "PROJECT";
@@ -229,15 +229,18 @@ export default {
const activeEnvironmentName = function (issue: Issue) {
const id = activeEnvironmentId(issue);
- if (id) {
- return store.getters["environment/environmentById"](id).name;
+ if (id == ZERO_ID) {
+ return "";
}
- return "";
+ return store.getters["environment/environmentById"](id).name;
};
const activeDatabaseName = function (issue: Issue) {
- return store.getters["database/databaseById"](activeDatabaseId(issue))
- .name;
+ const id = activeDatabaseId(issue);
+ if (id == ZERO_ID) {
+ return "";
+ }
+ return store.getters["database/databaseById"](id).name;
};
const router = useRouter();
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index 7d3bfbf40d..64cbe64a62 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -2,7 +2,10 @@ import { ResourceObject } from "./jsonapi";
import { BBNotificationStyle } from "../bbkit/types";
import { FieldId } from "../plugins";
+// UNKNOWN_ID means an anomaly.
export const UNKNOWN_ID = "-1";
+// ZERO_ID means an expected behavior. NO ID
+export const ZERO_ID = "0";
// The project to hold those databases synced from the instance but haven't been assigned an application
// project yet. We can't use UNKNOWN_ID because of referential integrity.
@@ -271,7 +274,7 @@ export const unknown = (
};
export const FINAL_STAGE: Stage = {
- id: "0",
+ id: ZERO_ID,
creator: unknown("PRINCIPAL") as Principal,
createdTs: 0,
updater: unknown("PRINCIPAL") as Principal,
@@ -285,7 +288,7 @@ export const FINAL_STAGE: Stage = {
};
export const FINAL_STEP: Step = {
- id: "0",
+ id: ZERO_ID,
issue: unknown("ISSUE") as Issue,
stage: FINAL_STAGE,
creator: unknown("PRINCIPAL") as Principal,
diff --git a/frontend/src/utils/issue.ts b/frontend/src/utils/issue.ts
index 6dfdc423f2..2f6a2a948d 100644
--- a/frontend/src/utils/issue.ts
+++ b/frontend/src/utils/issue.ts
@@ -6,6 +6,7 @@ import {
DatabaseId,
Step,
FINAL_STAGE,
+ ZERO_ID,
} from "../types";
export function stageName(issue: Issue, stageId: StageId): string {
@@ -43,10 +44,16 @@ export function activeStageIsRunning(issue: Issue): boolean {
export function activeEnvironmentId(issue: Issue): EnvironmentId {
const stage: Stage = activeStage(issue);
+ if (stage.id == ZERO_ID) {
+ return ZERO_ID;
+ }
return stage.database.instance.environment.id;
}
export function activeDatabaseId(issue: Issue): DatabaseId {
const stage = activeStage(issue);
+ if (stage.id == ZERO_ID) {
+ return ZERO_ID;
+ }
return stage.database.id;
}