Skip to content

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

fix: database effected environment (#7537)

ecmadaoe6a1741fd42c
diff --git a/frontend/src/components/AlterSchemaPrepForm/ProjectStandardView.vue b/frontend/src/components/AlterSchemaPrepForm/ProjectStandardView.vue
index 6a896ec122..10ff84640c 100644
--- a/frontend/src/components/AlterSchemaPrepForm/ProjectStandardView.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/ProjectStandardView.vue
@@ -165,7 +165,7 @@ const emit = defineEmits<{
const databaseListGroupByEnvironment = computed(() => {
const listByEnv = props.environmentList.map((environment) => {
const databaseList = props.databaseList.filter(
- (db) => db.instanceEntity.environment === environment.name
+ (db) => db.effectiveEnvironment === environment.name
);
return {
environment,
diff --git a/frontend/src/components/DatabaseDetail/Settings/DatabaseSettingsPanel.vue b/frontend/src/components/DatabaseDetail/Settings/DatabaseSettingsPanel.vue
index c9c3324ba8..271e004985 100644
--- a/frontend/src/components/DatabaseDetail/Settings/DatabaseSettingsPanel.vue
+++ b/frontend/src/components/DatabaseDetail/Settings/DatabaseSettingsPanel.vue
@@ -10,6 +10,7 @@
name="environment"
:disabled="!allowEdit"
:selected-id="environment?.uid"
+ :default-environment="database.instanceEntity.environment"
@select-environment-id="handleSelectEnvironmentUID"
/>
</div>
@@ -33,15 +34,12 @@ const databaseStore = useDatabaseV1Store();
const envStore = useEnvironmentV1Store();
const environment = computed(() => {
- return envStore.getEnvironmentByName(
- props.database.environment ||
- props.database.instanceEntity.environmentEntity.name
- );
+ return envStore.getEnvironmentByName(props.database.effectiveEnvironment);
});
const handleSelectEnvironmentUID = async (uid: number | string) => {
const environment = envStore.getEnvironmentByUID(String(uid));
- if (environment.name === props.database.environment) {
+ if (environment.name === props.database.effectiveEnvironment) {
return;
}
const databasePatch = cloneDeep(props.database);
diff --git a/frontend/src/components/DatabaseSelect.vue b/frontend/src/components/DatabaseSelect.vue
index 9cd03f9e80..952765ee8c 100644
--- a/frontend/src/components/DatabaseSelect.vue
+++ b/frontend/src/components/DatabaseSelect.vue
@@ -174,9 +174,11 @@ export default defineComponent({
}
if (props.environmentId !== String(UNKNOWN_ID)) {
+ const environment = useEnvironmentV1Store().getEnvironmentByUID(
+ props.environmentId
+ );
list = list.filter(
- (db) =>
- db.instanceEntity.environmentEntity.uid === props.environmentId
+ (db) => db.effectiveEnvironment === environment.name
);
}
if (props.instanceId !== String(UNKNOWN_ID)) {
diff --git a/frontend/src/components/EnvironmentSelect.vue b/frontend/src/components/EnvironmentSelect.vue
index 7366904bda..1d19370827 100644
--- a/frontend/src/components/EnvironmentSelect.vue
+++ b/frontend/src/components/EnvironmentSelect.vue
@@ -8,7 +8,15 @@
@select-item="(env: Environment) => $emit('select-environment-id', env.uid)"
>
<template #menuItem="{ item: environment }">
- <EnvironmentV1Name :environment="environment" :link="false" />
+ <EnvironmentV1Name
+ :environment="environment"
+ :link="false"
+ :suffiux="
+ defaultEnvironment == environment.name
+ ? `(${$t('common.default')})`
+ : ''
+ "
+ />
</template>
</BBSelect>
</template>
@@ -40,6 +48,10 @@ export default defineComponent({
default: false,
type: Boolean,
},
+ defaultEnvironment: {
+ default: "",
+ type: String,
+ },
},
emits: ["select-environment-id"],
setup(props, { emit }) {
diff --git a/frontend/src/components/SchemaDesigner/BaselineSchemaSelector.vue b/frontend/src/components/SchemaDesigner/BaselineSchemaSelector.vue
index 950cdfee18..c554c09895 100644
--- a/frontend/src/components/SchemaDesigner/BaselineSchemaSelector.vue
+++ b/frontend/src/components/SchemaDesigner/BaselineSchemaSelector.vue
@@ -103,6 +103,7 @@ import {
useChangeHistoryStore,
useDBSchemaV1Store,
useDatabaseV1Store,
+ useEnvironmentV1Store,
} from "@/store";
import { UNKNOWN_ID } from "@/types";
import { Engine } from "@/types/proto/v1/common";
@@ -138,6 +139,7 @@ const state = reactive<LocalState>({});
const databaseStore = useDatabaseV1Store();
const dbSchemaStore = useDBSchemaV1Store();
const changeHistoryStore = useChangeHistoryStore();
+const environmentStore = useEnvironmentV1Store();
const fullViewChangeHistoryCache = ref<Map<string, ChangeHistory>>(new Map());
const database = computed(() => {
@@ -260,8 +262,11 @@ const handleDatabaseSelect = async (databaseId: string) => {
if (!database) {
return;
}
+ const environment = environmentStore.getEnvironmentByName(
+ database.effectiveEnvironment
+ );
state.projectId = database.projectEntity.uid;
- state.environmentId = database.instanceEntity.environmentEntity.uid;
+ state.environmentId = environment?.uid;
state.databaseId = databaseId;
dbSchemaStore.getOrFetchDatabaseMetadata(database.name);
}
diff --git a/frontend/src/components/TransferOutDatabaseForm/common.ts b/frontend/src/components/TransferOutDatabaseForm/common.ts
index 1a643f93aa..ff85e9744a 100644
--- a/frontend/src/components/TransferOutDatabaseForm/common.ts
+++ b/frontend/src/components/TransferOutDatabaseForm/common.ts
@@ -13,13 +13,14 @@ export const mapTreeOptions = (databaseList: ComposedDatabase[]) => {
const environmentV1Store = useEnvironmentV1Store();
const databaseListGroupByEnvironment = groupBy(
databaseList,
- (db) => db.instanceEntity.environmentEntity.uid
+ (db) => db.effectiveEnvironment
);
return Object.keys(databaseListGroupByEnvironment).map<
DatabaseTreeOption<"environment">
- >((environmentId) => {
- const environment = environmentV1Store.getEnvironmentByUID(environmentId);
- const group = databaseListGroupByEnvironment[environmentId];
+ >((environmentName) => {
+ const environment =
+ environmentV1Store.getEnvironmentByName(environmentName);
+ const group = databaseListGroupByEnvironment[environmentName];
const children = group.map<DatabaseTreeOption<"database">>((db) => ({
level: "database",
value: `database-${db.uid}`,
@@ -28,8 +29,8 @@ export const mapTreeOptions = (databaseList: ComposedDatabase[]) => {
}));
return {
level: "environment",
- value: `environment-${environmentId}`,
- label: environment.title,
+ value: `environment-${environment?.uid}`,
+ label: environment?.title,
children,
};
});
diff --git a/frontend/src/components/v2/Model/DatabaseV1Table.vue b/frontend/src/components/v2/Model/DatabaseV1Table.vue
index 3997f47b57..dc72b1fbd0 100644
--- a/frontend/src/components/v2/Model/DatabaseV1Table.vue
+++ b/frontend/src/components/v2/Model/DatabaseV1Table.vue
@@ -276,7 +276,7 @@ const mixedDataList = computed(() => {
}
return sortBy(dataList, (d) => {
if (isDatabase(d)) {
- return (d as ComposedDatabase).instanceEntity.environmentEntity.name;
+ return (d as ComposedDatabase).effectiveEnvironment;
} else {
return (d as ComposedDatabaseGroup).environment.name;
}
diff --git a/frontend/src/components/v2/Model/EnvironmentV1Name.vue b/frontend/src/components/v2/Model/EnvironmentV1Name.vue
index d354427e63..999d9dc393 100644
--- a/frontend/src/components/v2/Model/EnvironmentV1Name.vue
+++ b/frontend/src/components/v2/Model/EnvironmentV1Name.vue
@@ -5,7 +5,10 @@
class="inline-flex items-center gap-x-1"
:class="link && !plain && 'normal-link'"
>
- <span class="line-clamp-1">{{ environmentV1Name(environment) }}</span>
+ <span class="line-clamp-1">
+ {{ environmentV1Name(environment) }}
+ {{ suffiux }}
+ </span>
<ProductionEnvironmentV1Icon
:environment="environment"
:class="iconClass ?? '!text-current'"
@@ -28,6 +31,7 @@ const props = withDefaults(
plain?: boolean;
iconClass?: VueClass;
tooltip?: boolean;
+ suffiux?: string;
}>(),
{
tag: "span",
@@ -35,6 +39,7 @@ const props = withDefaults(
plain: false,
iconClass: undefined,
tooltip: false,
+ suffiux: "",
}
);
diff --git a/frontend/src/store/modules/v1/database.ts b/frontend/src/store/modules/v1/database.ts
index b2c13f7f47..ece3c289ed 100644
--- a/frontend/src/store/modules/v1/database.ts
+++ b/frontend/src/store/modules/v1/database.ts
@@ -95,7 +95,7 @@ export const useDatabaseV1Store = defineStore("database_v1", () => {
};
const databaseListByEnvironment = (environment: string) => {
return databaseList.value.filter(
- (db) => db.instanceEntity.environment === environment
+ (db) => db.effectiveEnvironment === environment
);
};
const getDatabaseByName = (name: string) => {
diff --git a/frontend/src/views/DatabaseDashboard.vue b/frontend/src/views/DatabaseDashboard.vue
index 2295b8d02d..e0df66a970 100644
--- a/frontend/src/views/DatabaseDashboard.vue
+++ b/frontend/src/views/DatabaseDashboard.vue
@@ -220,9 +220,7 @@ const filteredDatabaseList = computed(() => {
);
const environment = selectedEnvironment.value;
if (environment && environment.name !== `environments/${UNKNOWN_ID}`) {
- list = list.filter(
- (db) => db.instanceEntity.environment === environment.name
- );
+ list = list.filter((db) => db.effectiveEnvironment === environment.name);
}
if (state.instanceFilter !== String(UNKNOWN_ID)) {
list = list.filter(
diff --git a/frontend/src/views/DatabaseDetail.vue b/frontend/src/views/DatabaseDetail.vue
index 8a26329b93..27528263a2 100644
--- a/frontend/src/views/DatabaseDetail.vue
+++ b/frontend/src/views/DatabaseDetail.vue
@@ -20,7 +20,7 @@
{{ database.databaseName }}
<ProductionEnvironmentV1Icon
- :environment="database.instanceEntity.environmentEntity"
+ :environment="environment"
:tooltip="true"
class="w-5 h-5"
/>
@@ -45,9 +45,7 @@
>{{ $t("common.environment") }}&nbsp;-&nbsp;</span
>
<EnvironmentV1Name
- :environment="
- environment || database.instanceEntity.environmentEntity
- "
+ :environment="environment"
icon-class="textinfolabel"
/>
</dd>
@@ -277,7 +275,12 @@ import {
useGracefulRequest,
useEnvironmentV1Store,
} from "@/store";
-import { UNKNOWN_ID, DEFAULT_PROJECT_V1_NAME, ComposedDatabase } from "@/types";
+import {
+ UNKNOWN_ID,
+ DEFAULT_PROJECT_V1_NAME,
+ ComposedDatabase,
+ unknownEnvironment,
+} from "@/types";
import { State } from "@/types/proto/v1/common";
import { TenantMode } from "@/types/proto/v1/project_service";
import {
@@ -682,8 +685,10 @@ const syncDatabaseSchema = async () => {
};
const environment = computed(() => {
- return useEnvironmentV1Store().getEnvironmentByName(
- database.value.environment
+ return (
+ useEnvironmentV1Store().getEnvironmentByName(
+ database.value.effectiveEnvironment
+ ) ?? unknownEnvironment()
);
});
</script>
diff --git a/frontend/src/views/SyncDatabaseSchema/DatabaseSchemaSelector.vue b/frontend/src/views/SyncDatabaseSchema/DatabaseSchemaSelector.vue
index de60ec97a2..de7e900294 100644
--- a/frontend/src/views/SyncDatabaseSchema/DatabaseSchemaSelector.vue
+++ b/frontend/src/views/SyncDatabaseSchema/DatabaseSchemaSelector.vue
@@ -111,6 +111,7 @@ import {
useDBSchemaV1Store,
useDatabaseV1Store,
useSubscriptionV1Store,
+ useEnvironmentV1Store,
} from "@/store";
import { UNKNOWN_ID } from "@/types";
import { Engine } from "@/types/proto/v1/common";
@@ -144,6 +145,7 @@ const state = reactive<LocalState>({
const databaseStore = useDatabaseV1Store();
const dbSchemaStore = useDBSchemaV1Store();
const changeHistoryStore = useChangeHistoryStore();
+const environmentStore = useEnvironmentV1Store();
const fullViewChangeHistoryCache = ref<Map<string, ChangeHistory>>(new Map());
const database = computed(() => {
@@ -177,9 +179,12 @@ onMounted(async () => {
const database = await databaseStore.getOrFetchDatabaseByUID(
props.selectState.databaseId || ""
);
+ const environment = await environmentStore.getOrFetchEnvironmentByName(
+ database.effectiveEnvironment
+ );
state.projectId = props.selectState.projectId;
state.databaseId = database.uid;
- state.environmentId = database.instanceEntity.environmentEntity.uid;
+ state.environmentId = environment.uid;
state.changeHistory = props.selectState.changeHistory;
} catch (error) {
// do nothing.
@@ -251,8 +256,11 @@ const handleDatabaseSelect = async (databaseId: string) => {
if (!database) {
return;
}
+ const environment = environmentStore.getEnvironmentByName(
+ database.effectiveEnvironment
+ );
state.projectId = database.projectEntity.uid;
- state.environmentId = database.instanceEntity.environmentEntity.uid;
+ state.environmentId = environment?.uid;
state.databaseId = databaseId;
dbSchemaStore.getOrFetchDatabaseMetadata(database.name);
}
diff --git a/frontend/src/views/SyncDatabaseSchema/SelectTargetDatabasesView.vue b/frontend/src/views/SyncDatabaseSchema/SelectTargetDatabasesView.vue
index 1bd1e16266..8b222abc75 100644
--- a/frontend/src/views/SyncDatabaseSchema/SelectTargetDatabasesView.vue
+++ b/frontend/src/views/SyncDatabaseSchema/SelectTargetDatabasesView.vue
@@ -404,8 +404,11 @@ const previewSchemaChangeMessage = computed(() => {
if (!database) {
return "";
}
+ const environment = environmentV1Store.getEnvironmentByName(
+ database.effectiveEnvironment
+ );
return t("database.sync-schema.schema-change-preview", {
- database: `${database.databaseName} (${database.instanceEntity.environmentEntity.title} - ${database.instanceEntity.title})`,
+ database: `${database.databaseName} (${environment?.title} - ${database.instanceEntity.title})`,
});
});
const databaseListWithDiff = computed(() => {