Skip to content

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

Bring back DEFAULT_PROJECT_ID to hold db synced from the instance

天舟45318f101678
diff --git a/frontend/src/components/InstanceForm.vue b/frontend/src/components/InstanceForm.vue
index 9a6b2e88ca..bf29c71ba5 100644
--- a/frontend/src/components/InstanceForm.vue
+++ b/frontend/src/components/InstanceForm.vue
@@ -276,7 +276,6 @@ import {
UNKNOWN_ID,
Principal,
InstancePatch,
- DEFAULT_PROJECT_ID,
} from "../types";
interface LocalState {
diff --git a/frontend/src/components/ProjectSelect.vue b/frontend/src/components/ProjectSelect.vue
index febe40ed07..8788385395 100644
--- a/frontend/src/components/ProjectSelect.vue
+++ b/frontend/src/components/ProjectSelect.vue
@@ -11,12 +11,15 @@
<option disabled :selected="UNKNOWN_ID == state.selectedId">
Select project
</option>
+ <option v-if="state.selectedId == DEFAULT_PROJECT_ID" :selected="true">
+ Default
+ </option>
<!-- It may happen the selected id might not be in the project list.
e.g. the selected project is deleted after the selection and we
are unable to cleanup properly. In such case, the seleted project id
is orphaned and we just display the id. -->
<option
- v-if="selectedIdNotInList"
+ v-else-if="selectedIdNotInList"
:value="state.selectedId"
:selected="true"
>
@@ -44,8 +47,7 @@
<script lang="ts">
import { computed, ComputedRef, reactive, watch, watchEffect } from "vue";
import { useStore } from "vuex";
-import { DEFAULT_PROJECT_ID, Principal, Project, UNKNOWN_ID } from "../types";
-import { isDBAOrOwner } from "../utils";
+import { Principal, Project, UNKNOWN_ID, DEFAULT_PROJECT_ID } from "../types";
interface LocalState {
selectedId: string;
@@ -76,29 +78,19 @@ export default {
);
const prepareProjectList = () => {
- // Fetches the entire project list if DBA or above.
- if (isDBAOrOwner(currentUser.value.role)) {
- store.dispatch("project/fetchProjectList").catch((error) => {
+ store
+ .dispatch("project/fetchProjectListByUser", {
+ userId: currentUser.value.id,
+ })
+ .catch((error) => {
console.log(error);
});
- } else {
- store
- .dispatch("project/fetchProjectListByUser", {
- userId: currentUser.value.id,
- })
- .catch((error) => {
- console.log(error);
- });
- }
};
watchEffect(prepareProjectList);
const projectList = computed((): Project[] => {
- const list = isDBAOrOwner(currentUser.value.role)
- ? store.getters["project/projectList"]()
- : store.getters["project/projectListByUser"](currentUser.value.id);
- return list;
+ return store.getters["project/projectListByUser"](currentUser.value.id);
});
const selectedIdNotInList = computed((): boolean => {
@@ -122,6 +114,7 @@ export default {
return {
UNKNOWN_ID,
+ DEFAULT_PROJECT_ID,
state,
projectList,
selectedIdNotInList,
diff --git a/frontend/src/miragejs/seeds/index.ts b/frontend/src/miragejs/seeds/index.ts
index 2d322cc813..ceb66ec4e0 100644
--- a/frontend/src/miragejs/seeds/index.ts
+++ b/frontend/src/miragejs/seeds/index.ts
@@ -6,6 +6,7 @@ import {
Principal,
StageType,
Task,
+ DEFAULT_PROJECT_ID,
} from "../../types";
import { databaseSlug, taskSlug } from "../../utils";
@@ -604,13 +605,20 @@ const createInstanceList = (
for (let j = 0; j < 2; j++) {
server.create("database", {
- workspaceId: instance.workspaceId,
+ workspaceId: workspaceId,
projectId: projectList[i % projectList.length].id,
instance,
});
}
}
+ server.create("database", {
+ workspaceId: workspaceId,
+ projectId: DEFAULT_PROJECT_ID,
+ name: "syncdb",
+ instance: instanceList[0],
+ });
+
return instanceList;
};
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index d0c331634c..42f21ceceb 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -4,6 +4,8 @@ import { FieldId } from "../plugins";
export const UNKNOWN_ID = "-1";
+// 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.
export const DEFAULT_PROJECT_ID = "1";
export type ResourceType =