Skip to content

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

chore: retire db name template (#8623)

Liu Ji227058ea4638
diff --git a/frontend/src/components/CreateDatabasePrepForm/CreateDatabasePrepForm.vue b/frontend/src/components/CreateDatabasePrepForm/CreateDatabasePrepForm.vue
index 18bc00ef18..823ce2e969 100644
--- a/frontend/src/components/CreateDatabasePrepForm/CreateDatabasePrepForm.vue
+++ b/frontend/src/components/CreateDatabasePrepForm/CreateDatabasePrepForm.vue
@@ -34,12 +34,6 @@
</template>
</i18n-t>
</span>
- <DatabaseNameTemplateTips
- v-if="isDbNameTemplateMode"
- :project="project"
- :name="state.databaseName"
- :labels="state.labels"
- />
</div>
<div v-if="selectedInstance.engine === Engine.MONGODB" class="w-full">
@@ -68,15 +62,6 @@
/>
</div>
- <!-- Providing more dropdowns for required labels as if they are normal required props of DB -->
- <DatabaseLabelForm
- v-if="isTenantProject"
- ref="labelForm"
- :project="project"
- :labels="state.labels"
- filter="required"
- />
-
<div class="w-full">
<label for="environment" class="textlabel">
{{ $t("common.environment") }} <span style="color: red">*</span>
@@ -129,15 +114,6 @@
/>
</div>
- <!-- Providing other dropdowns for optional labels as if they are normal optional props of DB -->
- <DatabaseLabelForm
- v-if="isTenantProject"
- class="w-full"
- :project="project"
- :labels="state.labels"
- filter="optional"
- />
-
<template v-if="showCollationAndCharacterSet">
<div class="w-full">
<label for="charset" class="textlabel">
@@ -208,7 +184,7 @@
import { isEmpty } from "lodash-es";
import { NInput } from "naive-ui";
import { v4 as uuidv4 } from "uuid";
-import { computed, reactive, PropType, ref, toRef } from "vue";
+import { computed, reactive, PropType } from "vue";
import { useRouter } from "vue-router";
import InstanceRoleSelect from "@/components/InstanceRoleSelect.vue";
import MemberSelect from "@/components/MemberSelect.vue";
@@ -255,11 +231,6 @@ import {
instanceV1HasCreateDatabase,
} from "@/utils";
import { trySetDefaultAssigneeByEnvironmentAndDeploymentType } from "../IssueV1/logic/initialize/assignee";
-import {
- DatabaseLabelForm,
- DatabaseNameTemplateTips,
- useDBNameTemplateInputState,
-} from "./";
interface LocalState {
projectId?: string;
@@ -348,31 +319,11 @@ const isTenantProject = computed((): boolean => {
return project.value.tenantMode === TenantMode.TENANT_MODE_ENABLED;
});
-// reference to <DatabaseLabelForm /> to call validate()
-const labelForm = ref<InstanceType<typeof DatabaseLabelForm> | null>(null);
-
-const isDbNameTemplateMode = computed((): boolean => {
- if (parseInt(project.value.uid, 10) === UNKNOWN_ID) return false;
-
- if (project.value.tenantMode !== TenantMode.TENANT_MODE_ENABLED) {
- return false;
- }
-
- // true if dbNameTemplate is not empty
- return !!project.value.dbNameTemplate;
-});
-
const allowCreate = computed(() => {
- // If we are not in template mode, none of labels are required
- // So we just treat this case as 'yes, valid'
- const isLabelValid = isDbNameTemplateMode.value
- ? labelForm.value?.validate()
- : true;
return (
!isEmpty(state.databaseName) &&
validDatabaseOwnerName.value &&
!isReservedName.value &&
- isLabelValid &&
state.projectId &&
state.environmentId &&
state.instanceId &&
@@ -417,11 +368,6 @@ const validDatabaseOwnerName = computed((): boolean => {
return state.instanceRole !== undefined;
});
-useDBNameTemplateInputState(project, {
- databaseName: toRef(state, "databaseName"),
- labels: toRef(state, "labels"),
-});
-
const selectProject = (projectId: string | undefined) => {
state.projectId = projectId;
};
@@ -498,9 +444,9 @@ const createV1 = async () => {
owner,
backup: "",
};
- const spec: Plan_Spec = {
+ const spec = Plan_Spec.fromPartial({
id: uuidv4(),
- };
+ });
specs.push(spec);
const issueCreate = Issue.fromJSON({
diff --git a/frontend/src/components/CreateDatabasePrepForm/DatabaseLabelForm.vue b/frontend/src/components/CreateDatabasePrepForm/DatabaseLabelForm.vue
deleted file mode 100644
index cbc4c49237..0000000000
--- a/frontend/src/components/CreateDatabasePrepForm/DatabaseLabelForm.vue
+++ /dev/null
@@ -1,112 +0,0 @@
-<template>
- <div
- v-for="item in filteredFormItemList"
- :key="item.label"
- class="w-full"
- v-bind="$attrs"
- >
- <div class="flex flex-row items-center space-x-1">
- <label for="instance" class="textlabel">
- {{ displayLabelKey(item.label) }}
- <span v-if="item.required" class="text-red-600">*</span>
- </label>
- </div>
- <div class="flex flex-col space-y-1">
- <NInput
- :value="getLabelValue(item.label)"
- :placeholder="getLabelPlaceholder(item.label)"
- class="text-sm"
- @input="(value) => setLabelValue(item.label, value)"
- />
- </div>
- </div>
-</template>
-
-<script lang="ts" setup>
-/* eslint-disable vue/no-mutating-props */
-
-import { NInput } from "naive-ui";
-import { capitalize } from "lodash-es";
-import { computed, defineComponent } from "vue";
-import type { Project } from "@/types/proto/v1/project_service";
-import {
- hidePrefix,
- validateLabelsWithTemplate,
- parseLabelListInTemplate,
- PRESET_LABEL_KEYS,
- displayLabelKey,
-} from "@/utils";
-
-const props = defineProps<{
- project: Project;
- labels: Record<string, string>;
- filter: "required" | "optional";
-}>();
-
-const isDbNameTemplateMode = computed((): boolean => {
- return !!props.project.dbNameTemplate;
-});
-
-const requiredLabelDict = computed((): Set<string> => {
- if (!isDbNameTemplateMode.value) {
- // all labels are optional if we have no template
- return new Set();
- }
-
- // otherwise parse the placeholders from the template
- const keys = parseLabelListInTemplate(props.project.dbNameTemplate);
- return new Set(keys);
-});
-
-const formItemList = computed((): { label: string; required: boolean }[] => {
- return PRESET_LABEL_KEYS.map((label) => {
- const required = requiredLabelDict.value.has(label);
- return {
- label,
- required,
- };
- });
-});
-
-const filteredFormItemList = computed(
- (): { label: string; required: boolean }[] => {
- return formItemList.value.filter((item) =>
- props.filter === "required" ? item.required : !item.required
- );
- }
-);
-
-const getLabelPlaceholder = (key: string): string => {
- // provide "Input Tenant" if Tenant is optional
- // provide "Input {{TENANT}}" if Tenant is required in the template
- key = requiredLabelDict.value.has(key)
- ? `{{${hidePrefix(key).toUpperCase()}}}`
- : capitalize(hidePrefix(key));
- return key;
-};
-
-const getLabelValue = (key: string): string => {
- return props.labels[key] ?? "";
-};
-
-const setLabelValue = (key: string, value: string) => {
- if (value) {
- props.labels[key] = value;
- } else {
- delete props.labels[key];
- }
-};
-
-defineExpose({
- // called by parent component
- validate: (): boolean => {
- return validateLabelsWithTemplate(props.labels, requiredLabelDict.value);
- },
-});
-</script>
-
-<script lang="ts">
-export default defineComponent({
- inheritAttrs: false,
-});
-</script>
diff --git a/frontend/src/components/CreateDatabasePrepForm/DatabaseNameTemplateTips.vue b/frontend/src/components/CreateDatabasePrepForm/DatabaseNameTemplateTips.vue
deleted file mode 100644
index 7bb393b83c..0000000000
--- a/frontend/src/components/CreateDatabasePrepForm/DatabaseNameTemplateTips.vue
+++ /dev/null
@@ -1,55 +0,0 @@
-<template>
- <div
- v-if="mode !== 'none'"
- class="space-y-1 mt-2 text-xs"
- :class="[
- mode === 'template-mismatch' && 'text-warning',
- mode === 'value-mismatch' && 'text-warning',
- ]"
- >
- <template v-if="mode === 'normal'">
- <p>{{ $t("database.should-follow-database-name-template") }}</p>
- <p>
- <code>{{ project.dbNameTemplate }}</code>
- </p>
- </template>
- <template v-if="mode === 'template-mismatch'">
- <p>{{ $t("database.doesnt-match-database-name-template") }}</p>
- <p>
- <code>{{ project.dbNameTemplate }}</code>
- </p>
- </template>
- <template v-else-if="mode === 'value-mismatch'">
- <p>{{ $t("database.doesnt-match-tenant-value") }}</p>
- </template>
- </div>
-</template>
-
-<script lang="ts" setup>
-import { computed } from "vue";
-import type { Project } from "@/types/proto/v1/project_service";
-import { buildDatabaseNameRegExpByTemplate } from "@/utils";
-
-type ViewMode = "none" | "normal" | "template-mismatch" | "value-mismatch";
-
-const props = defineProps<{
- name: string;
- project: Project;
- labels: Record<string, string>;
-}>();
-
-const mode = computed((): ViewMode => {
- const { project, name, labels } = props;
- if (!project.dbNameTemplate) return "none";
- if (!name) return "normal";
- const regex = buildDatabaseNameRegExpByTemplate(project.dbNameTemplate);
- const matches = name.match(regex);
- if (!matches) return "template-mismatch";
- const parsedTenant = matches.groups?.["TENANT"];
- const tenant = labels["tenant"] ?? "";
- if (parsedTenant && parsedTenant !== tenant) {
- return "value-mismatch";
- }
- return "none";
-});
-</script>
diff --git a/frontend/src/components/CreateDatabasePrepForm/index.ts b/frontend/src/components/CreateDatabasePrepForm/index.ts
index 765e662884..c2298c2533 100644
--- a/frontend/src/components/CreateDatabasePrepForm/index.ts
+++ b/frontend/src/components/CreateDatabasePrepForm/index.ts
@@ -1,16 +1,11 @@
import CreateDatabasePrepButtonGroup from "./CreateDatabasePrepButtonGroup.vue";
import CreateDatabasePrepForm from "./CreateDatabasePrepForm.vue";
import CreateDatabasePrepPanel from "./CreateDatabasePrepPanel.vue";
-import DatabaseLabelForm from "./DatabaseLabelForm.vue";
-import DatabaseNameTemplateTips from "./DatabaseNameTemplateTips.vue";
export {
- DatabaseLabelForm,
- DatabaseNameTemplateTips,
CreateDatabasePrepForm,
CreateDatabasePrepPanel,
CreateDatabasePrepButtonGroup,
};
-export * from "./logic";
export default CreateDatabasePrepForm;
diff --git a/frontend/src/components/CreateDatabasePrepForm/logic.ts b/frontend/src/components/CreateDatabasePrepForm/logic.ts
deleted file mode 100644
index d0dae9ac09..0000000000
--- a/frontend/src/components/CreateDatabasePrepForm/logic.ts
+++ /dev/null
@@ -1,49 +0,0 @@
-import { computed, unref, watch } from "vue";
-import { MaybeRef } from "@/types";
-import { type Project, TenantMode } from "@/types/proto/v1/project_service";
-import { parseDatabaseLabelValueByTemplate } from "@/utils";
-
-export const useDBNameTemplateInputState = (
- project: MaybeRef<Project>,
- values: {
- databaseName: MaybeRef<string>;
- labels: MaybeRef<Record<string, string>>;
- }
-) => {
- const TENANT_LABEL_KEY = "tenant";
- const TENANT_LABEL_REGEXP_GROUP_NAME = "TENANT";
-
- const tenantValue = computed(() => {
- return unref(values.labels)[TENANT_LABEL_KEY] ?? "";
- });
-
- const parsedTenantValue = computed(() => {
- return parseDatabaseLabelValueByTemplate(
- unref(project).dbNameTemplate,
- unref(values.databaseName),
- TENANT_LABEL_REGEXP_GROUP_NAME
- );
- });
-
- watch(
- parsedTenantValue,
- (newValue, oldValue) => {
- const proj = unref(project);
- if (proj.tenantMode !== TenantMode.TENANT_MODE_ENABLED) return;
- if (!proj.dbNameTemplate) return;
-
- const tenant = tenantValue.value;
- if (tenant && tenant !== oldValue) {
- // Tenant value has been changed by user manually, don't touch it.
- return;
- }
- const labels = unref(values.labels);
- if (newValue) {
- labels[TENANT_LABEL_KEY] = newValue;
- } else {
- delete labels[TENANT_LABEL_KEY];
- }
- },
- { immediate: true }
- );
-};
diff --git a/frontend/src/components/DatabaseDetail/CreatePITRDatabaseForm.vue b/frontend/src/components/DatabaseDetail/CreatePITRDatabaseForm.vue
index a8ec4a9525..c0adf4abb3 100644
--- a/frontend/src/components/DatabaseDetail/CreatePITRDatabaseForm.vue
+++ b/frontend/src/components/DatabaseDetail/CreatePITRDatabaseForm.vue
@@ -33,23 +33,7 @@
</template>
</i18n-t>
</span>
- <DatabaseNameTemplateTips
- v-if="isDbNameTemplateMode"
- :project="project"
- :name="state.context.databaseName"
- :labels="state.context.labels"
- />
</div>
-
- <!-- Providing more dropdowns for required labels as if they are normal required props of DB -->
- <DatabaseLabelForm
- v-if="isTenantProject"
- ref="labelForm"
- :project="project"
- :labels="state.context.labels"
- filter="required"
- />
-
<div class="space-y-2">
<label class="textlabel">
{{ $t("common.environment") }}
@@ -78,14 +62,6 @@
/>
</div>
- <!-- Providing other dropdowns for optional labels as if they are normal optional props of DB -->
- <DatabaseLabelForm
- v-if="isTenantProject"
- :project="project"
- :labels="state.context.labels"
- filter="optional"
- />
-
<div class="space-y-2">
<label class="textlabel w-full flex gap-1">
{{
@@ -125,26 +101,9 @@
<script lang="ts" setup>
import { cloneDeep, isEmpty } from "lodash-es";
-import {
- computed,
- onBeforeMount,
- PropType,
- reactive,
- ref,
- toRef,
- watch,
-} from "vue";
-import {
- DatabaseLabelForm,
- DatabaseNameTemplateTips,
- useDBNameTemplateInputState,
-} from "@/components/CreateDatabasePrepForm";
+import { computed, onBeforeMount, PropType, reactive, watch } from "vue";
import { isPITRAvailableOnInstanceV1 } from "@/plugins/pitr";
-import {
- useDBSchemaV1Store,
- useProjectV1ByUID,
- useInstanceV1Store,
-} from "@/store";
+import { useDBSchemaV1Store, useInstanceV1Store } from "@/store";
import {
ComposedInstance,
ComposedDatabase,
@@ -152,7 +111,6 @@ import {
defaultCollationOfEngineV1,
} from "@/types";
import { Engine } from "@/types/proto/v1/common";
-import { TenantMode } from "@/types/proto/v1/project_service";
import { CreatePITRDatabaseContext } from "./utils";
interface LocalState {
@@ -209,25 +167,10 @@ const state = reactive<LocalState>({
context: extractLocalContextFromProps(),
});
-const { project } = useProjectV1ByUID(computed(() => state.context.projectId));
-
const isReservedName = computed(() => {
return state.context.databaseName.toLowerCase() == "bytebase";
});
-const isTenantProject = computed((): boolean => {
- return project.value.tenantMode === TenantMode.TENANT_MODE_ENABLED;
-});
-
-// reference to <DatabaseLabelForm /> to call validate()
-const labelForm = ref<InstanceType<typeof DatabaseLabelForm> | null>(null);
-
-const isDbNameTemplateMode = computed((): boolean => {
- if (project.value.tenantMode !== TenantMode.TENANT_MODE_ENABLED) return false;
- // true if dbNameTemplate is not empty
- return !!project.value.dbNameTemplate;
-});
-
const selectedInstance = computed(() => {
return instanceV1Store.getInstanceByUID(state.context.instanceId);
});
@@ -236,11 +179,6 @@ const instanceFilter = (instance: ComposedInstance): boolean => {
return isPITRAvailableOnInstanceV1(instance);
};
-useDBNameTemplateInputState(project, {
- databaseName: toRef(state.context, "databaseName"),
- labels: toRef(state.context, "labels"),
-});
-
// Sync values from props when changes.
watch([() => props.database, () => props.context], () => {
state.context = extractLocalContextFromProps();
@@ -259,15 +197,9 @@ watch(
);
const validate = (): boolean => {
- // If we are not in template mode, none of labels are required
- // So we just treat this case as 'yes, valid'
- const isLabelValid = isDbNameTemplateMode.value
- ? labelForm.value?.validate()
- : true;
return (
!isEmpty(state.context.databaseName) &&
!isReservedName.value &&
- !!isLabelValid &&
!!state.context.projectId &&
!!state.context.environmentId &&
!!state.context.instanceId
diff --git a/frontend/src/components/Project/ProjectDBNameTemplateSettingPanel.vue b/frontend/src/components/Project/ProjectDBNameTemplateSettingPanel.vue
deleted file mode 100644
index 5c3c81b03f..0000000000
--- a/frontend/src/components/Project/ProjectDBNameTemplateSettingPanel.vue
+++ /dev/null
@@ -1,124 +0,0 @@
-<template>
- <div v-if="show">
- <div class="text-lg font-medium leading-7 text-main">
- {{ $t("project.db-name-template") }}
- </div>
- <div class="textinfolabel">
- <i18n-t keypath="label.db-name-template-tips">
- <template #placeholder>
- <!-- prettier-ignore -->
- <code v-pre class="text-xs font-mono bg-control-bg">{{DB_NAME}}__{{TENANT}}</code>
- </template>
- <template #link>
- <a
- class="normal-link inline-flex items-center"
- href="https://www.bytebase.com/docs/change-database/batch-change/#specify-database-name-template"
- target="__BLANK"
- >
- {{ $t("common.learn-more") }}
- <heroicons-outline:external-link class="w-4 h-4 ml-1" />
- </a>
- </template>
- </i18n-t>
- </div>
- <div class="mt-3 space-y-2">
- <div>
- <input
- v-model="state.dbNameTemplate"
- type="text"
- class="textfield w-full"
- :disabled="!state.isEditingDBNameTemplate"
- />
- </div>
- <div class="flex items-center justify-end gap-x-2">
- <button
- v-if="!state.isEditingDBNameTemplate"
- :disabled="!allowEdit"
- class="btn-normal"
- @click="beginEditDBNameTemplate"
- >
- {{ $t("common.edit") }}
- </button>
- <template v-if="state.isEditingDBNameTemplate">
- <button class="btn-normal" @click="cancelEditDBNameTemplate">
- {{ $t("common.cancel") }}
- </button>
- <button
- class="btn-primary"
- :disabled="!allowUpdateDBNameTemplate"
- @click="confirmEditDBNameTemplate"
- >
- {{ $t("common.update") }}
- </button>
- </template>
- </div>
- </div>
- </div>
-</template>
-
-<script setup lang="ts">
-import { cloneDeep } from "lodash-es";
-import { PropType, computed, reactive } from "vue";
-import { useI18n } from "vue-i18n";
-import { pushNotification, useProjectV1Store } from "@/store";
-import { Project, TenantMode } from "@/types/proto/v1/project_service";
-
-type LocalState = {
- isEditingDBNameTemplate: boolean;
- dbNameTemplate: string;
-};
-
-const props = defineProps({
- project: {
- required: true,
- type: Object as PropType<Project>,
- },
- allowEdit: {
- default: true,
- type: Boolean,
- },
-});
-
-const { t } = useI18n();
-
-const state = reactive<LocalState>({
- isEditingDBNameTemplate: false,
- dbNameTemplate: props.project.dbNameTemplate,
-});
-
-const show = computed(() => {
- return props.project.tenantMode === TenantMode.TENANT_MODE_ENABLED;
-});
-
-const allowUpdateDBNameTemplate = computed(() => {
- return state.dbNameTemplate !== props.project.dbNameTemplate;
-});
-
-const beginEditDBNameTemplate = () => {
- state.dbNameTemplate = props.project.dbNameTemplate;
- state.isEditingDBNameTemplate = true;
-};
-
-const cancelEditDBNameTemplate = () => {
- state.dbNameTemplate = props.project.dbNameTemplate;
- state.isEditingDBNameTemplate = false;
-};
-
-const confirmEditDBNameTemplate = async () => {
- try {
- const projectPatch = cloneDeep(props.project);
- projectPatch.dbNameTemplate = state.dbNameTemplate;
- const updateMask = ["db_name_template"];
- await useProjectV1Store().updateProject(projectPatch, updateMask);
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("project.successfully-updated-db-name-template"),
- });
- } catch {
- state.dbNameTemplate = props.project.dbNameTemplate;
- } finally {
- state.isEditingDBNameTemplate = false;
- }
-};
-</script>
diff --git a/frontend/src/components/Project/ProjectGeneralSettingPanel.vue b/frontend/src/components/Project/ProjectGeneralSettingPanel.vue
index 3b28fc373c..5eb0dbe759 100644
--- a/frontend/src/components/Project/ProjectGeneralSettingPanel.vue
+++ b/frontend/src/components/Project/ProjectGeneralSettingPanel.vue
@@ -102,7 +102,7 @@
</div>
<FeatureModal
- :open="state.requiredFeature"
+ :open="!!state.requiredFeature"
:feature="state.requiredFeature"
@cancel="state.requiredFeature = undefined"
/>
diff --git a/frontend/src/components/ProjectSettingPanel.vue b/frontend/src/components/ProjectSettingPanel.vue
index 9e1c897410..d7ee53feaf 100644
--- a/frontend/src/components/ProjectSettingPanel.vue
+++ b/frontend/src/components/ProjectSettingPanel.vue
@@ -2,11 +2,6 @@
<div class="max-w-3xl mx-auto space-y-4">
<div class="divide-y divide-block-border space-y-6">
<ProjectGeneralSettingPanel :project="project" :allow-edit="allowEdit" />
- <ProjectDBNameTemplateSettingPanel
- :project="project"
- :allow-edit="allowEdit"
- class="pt-4"
- />
</div>
<ProjectArchiveRestoreButton :project="project" />
</div>
@@ -16,7 +11,6 @@
import { PropType } from "vue";
import { ComposedProject } from "@/types";
import ProjectArchiveRestoreButton from "./Project/ProjectArchiveRestoreButton.vue";
-import ProjectDBNameTemplateSettingPanel from "./Project/ProjectDBNameTemplateSettingPanel.vue";
import ProjectGeneralSettingPanel from "./Project/ProjectGeneralSettingPanel.vue";
defineProps({
diff --git a/frontend/src/components/TransferDatabaseForm.vue b/frontend/src/components/TransferDatabaseForm.vue
index 7ecf10002b..e17ded9116 100644
--- a/frontend/src/components/TransferDatabaseForm.vue
+++ b/frontend/src/components/TransferDatabaseForm.vue
@@ -55,9 +55,7 @@ import {
ComposedDatabase,
} from "../types";
import {
- buildDatabaseNameRegExpByTemplate,
filterDatabaseV1ByKeyword,
- PRESET_LABEL_KEY_PLACEHOLDERS,
sortDatabaseV1List,
useWorkspacePermissionV1,
} from "../utils";
@@ -161,18 +159,11 @@ const filteredDatabaseList = computed(() => {
});
const transferDatabase = async (databaseList: ComposedDatabase[]) => {
- const transferOneDatabase = async (
- database: ComposedDatabase,
- labels?: Record<string, string>
- ) => {
+ const transferOneDatabase = async (database: ComposedDatabase) => {
const targetProject = useProjectV1Store().getProjectByUID(props.projectId);
const databasePatch = cloneDeep(database);
databasePatch.project = targetProject.name;
const updateMask = ["project"];
- if (labels) {
- databasePatch.labels = labels;
- updateMask.push("labels");
- }
const updated = await useDatabaseV1Store().updateDatabase({
database: databasePatch,
updateMask,
@@ -183,8 +174,7 @@ const transferDatabase = async (databaseList: ComposedDatabase[]) => {
try {
state.loading = true;
const requests = databaseList.map((db) => {
- const labels = parseLabelsIfNeeded(db);
- transferOneDatabase(db, labels);
+ transferOneDatabase(db);
});
await Promise.all(requests);
const displayDatabaseName =
@@ -202,24 +192,4 @@ const transferDatabase = async (databaseList: ComposedDatabase[]) => {
state.loading = false;
}
};
-
-const parseLabelsIfNeeded = (database: ComposedDatabase) => {
- const { dbNameTemplate } = project.value;
- if (!dbNameTemplate) return undefined;
-
- const regex = buildDatabaseNameRegExpByTemplate(dbNameTemplate);
- const match = database.name.match(regex);
- if (!match) return undefined;
-
- const labels: Record<string, string> = {};
-
- PRESET_LABEL_KEY_PLACEHOLDERS.forEach(([placeholder, key]) => {
- const value = match.groups?.[placeholder];
- if (value) {
- labels[key] = value;
- }
- });
-
- return labels;
-};
</script>
diff --git a/frontend/src/components/TransferDatabaseForm/SelectDatabaseLabel.vue b/frontend/src/components/TransferDatabaseForm/SelectDatabaseLabel.vue
deleted file mode 100644
index be57829420..0000000000
--- a/frontend/src/components/TransferDatabaseForm/SelectDatabaseLabel.vue
+++ /dev/null
@@ -1,150 +0,0 @@
-<template>
- <div
- v-if="targetProject.tenantMode === TenantMode.TENANT_MODE_ENABLED"
- class="space-y-4 flex flex-col justify-center items-center"
- >
- <div v-for="key in PRESET_LABEL_KEYS" :key="key" class="w-64">
- <label class="textlabel">
- {{ displayLabelKey(key) }}
- <span v-if="isRequiredLabel(key)" style="color: red">*</span>
- </label>
-
- <div class="flex flex-col space-y-1 w-64 mt-1">
- <NInput
- :value="getLabelValue(key)"
- :placeholder="getLabelPlaceholder(key)"
- @input="setLabelValue(key, $event)"
- />
- </div>
-
- <div v-if="isParsedLabel(key)" class="mt-2 textinfolabel">
- <i18n-t keypath="label.parsed-from-template">
- <template #name>{{ database.databaseName }}</template>
- <template #template>
- <code class="text-xs font-mono bg-control-bg">
- {{ targetProject.dbNameTemplate }}
- </code>
- </template>
- </i18n-t>
- </div>
- </div>
- </div>
-</template>
-
-<script lang="ts">
-export default {
- inheritAttrs: false,
-};
-</script>
-
-<script lang="ts" setup>
-import { computed, toRef, watch } from "vue";
-import { capitalize } from "lodash-es";
-import { useI18n } from "vue-i18n";
-import { NInput } from "naive-ui";
-
-import type { ComposedDatabase } from "@/types";
-import {
- buildDatabaseNameRegExpByTemplate,
- hidePrefix,
- parseLabelListInTemplate,
- PRESET_LABEL_KEYS,
- PRESET_LABEL_KEY_PLACEHOLDERS,
- displayLabelKey,
-} from "@/utils";
-import { useProjectV1ByUID } from "@/store";
-import { TenantMode } from "@/types/proto/v1/project_service";
-
-const props = defineProps<{
- database: ComposedDatabase;
- labels: Record<string, string>;
- targetProjectId: string;
-}>();
-const emit = defineEmits<{
- (event: "update:labels", labels: Record<string, string>): void;
-}>();
-
-const { t } = useI18n();
-
-const { project: targetProject } = useProjectV1ByUID(
- toRef(props, "targetProjectId")
-);
-
-const requiredLabelList = computed((): string[] => {
- const project = targetProject.value;
- if (!project.dbNameTemplate) return [];
-
- // for databases with dbNameTemplate, we need to parse required labels from its template
- return parseLabelListInTemplate(project.dbNameTemplate);
-});
-
-const dbNameMatchesTemplate = computed((): boolean => {
- const project = targetProject.value;
- if (!project.dbNameTemplate) {
- // no restrictions, because no template
- return true;
- }
- const regex = buildDatabaseNameRegExpByTemplate(project.dbNameTemplate);
- return regex.test(props.database.databaseName);
-});
-
-const isRequiredLabel = (key: string): boolean => {
- return requiredLabelList.value.includes(key);
-};
-
-const isParsedLabel = (key: string): boolean => {
- const parsed = labelsParsedFromTemplate.value;
- if (!parsed) return false;
- return key in parsed;
-};
-
-const labelsParsedFromTemplate = computed(() => {
- if (!dbNameMatchesTemplate.value) return undefined;
-
- const regex = buildDatabaseNameRegExpByTemplate(
- targetProject.value.dbNameTemplate
- );
- const match = props.database.name.match(regex);
- if (!match) return undefined;
-
- const parsedLabelList: Record<string, string> = {};
- PRESET_LABEL_KEY_PLACEHOLDERS.forEach(([placeholder, key]) => {
- const value = match.groups?.[placeholder];
- if (value) {
- parsedLabelList[key] = value;
- }
- });
-
- return parsedLabelList;
-});
-
-watch(labelsParsedFromTemplate, (labels) => {
- if (!labels) return;
- for (const key in labels) {
- setLabelValue(key, labels[key]);
- }
-});
-
-const getLabelPlaceholder = (key: string): string => {
- // provide "Input Tenant" if Tenant is optional
- // provide "Input {{TENANT}}" if Tenant is required in the template
- key = isRequiredLabel(key)
- ? `{{${hidePrefix(key).toUpperCase()}}}`
- : capitalize(hidePrefix(key));
- return t("create-db.input-label-value", { key });
-};
-
-const getLabelValue = (key: string) => {
- return props.labels[key] ?? "";
-};
-
-const setLabelValue = (key: string, value: string) => {
- const labels = { ...props.labels };
- if (value) {
- labels[key] = value;
- } else {
- delete labels[key];
- }
- emit("update:labels", labels);
-};
-</script>
diff --git a/frontend/src/components/TransferDatabaseForm/TransferSingleDatabase.vue b/frontend/src/components/TransferDatabaseForm/TransferSingleDatabase.vue
index b189a13431..10e6ad6ce2 100644
--- a/frontend/src/components/TransferDatabaseForm/TransferSingleDatabase.vue
+++ b/frontend/src/components/TransferDatabaseForm/TransferSingleDatabase.vue
@@ -16,11 +16,6 @@
@update:project="handleSelectProject"
/>
</div>
- <SelectDatabaseLabel
- v-model:labels="editingLabels"
- :database="database"
- :target-project-id="targetProject.uid"
- />
</div>
<div>
<div
@@ -66,9 +61,7 @@ import {
PresetRoleType,
UNKNOWN_ID,
} from "@/types";
-import { TenantMode } from "@/types/proto/v1/project_service";
import { hasWorkspacePermissionV1 } from "@/utils";
-import SelectDatabaseLabel from "./SelectDatabaseLabel.vue";
const props = defineProps<{
database: ComposedDatabase;
@@ -84,7 +77,6 @@ const currentUserV1 = useCurrentUserV1();
const transferring = ref(false);
const sourceProject = computed(() => props.database.projectEntity);
const targetProject = ref(sourceProject.value);
-const editingLabels = ref({ ...props.database.labels });
const allowTransfer = computed(() => {
return sourceProject.value.name !== targetProject.value.name;
@@ -123,10 +115,6 @@ const doTransfer = async () => {
const databasePatch = cloneDeep(props.database);
databasePatch.project = target.name;
const updateMask = ["project"];
- if (target.tenantMode === TenantMode.TENANT_MODE_ENABLED) {
- databasePatch.labels = { ...editingLabels.value };
- updateMask.push("labels");
- }
const updated = await useDatabaseV1Store().updateDatabase({
database: databasePatch,
updateMask,
@@ -148,17 +136,6 @@ const doTransfer = async () => {
}
};
-watch(
- () => props.database.labels,
- (labels) => (editingLabels.value = { ...labels }),
- { deep: true }
-);
-watch(targetProject, (tar) => {
- if (tar.tenantMode !== TenantMode.TENANT_MODE_ENABLED) {
- // Restore dirty value if need not to edit labels any more.
- editingLabels.value = { ...props.database.labels };
- }
-});
watch(sourceProject, (src) => {
targetProject.value = src;
});
diff --git a/frontend/src/components/TransferDatabaseForm/index.ts b/frontend/src/components/TransferDatabaseForm/index.ts
index cd923c4970..f12607c3ea 100644
--- a/frontend/src/components/TransferDatabaseForm/index.ts
+++ b/frontend/src/components/TransferDatabaseForm/index.ts
@@ -1,4 +1,3 @@
-import SelectDatabaseLabel from "./SelectDatabaseLabel.vue";
import TransferMultipleDatabaseForm from "./TransferMultipleDatabaseForm.vue";
import TransferSingleDatabase from "./TransferSingleDatabase.vue";
import TransferSourceSelector from "./TransferSourceSelector.vue";
@@ -6,7 +5,6 @@ import TransferSourceSelector from "./TransferSourceSelector.vue";
export * from "./utils";
export {
- SelectDatabaseLabel,
TransferMultipleDatabaseForm,
TransferSourceSelector,
TransferSingleDatabase,
diff --git a/frontend/src/components/v2/Select/EnvironmentSelect.vue b/frontend/src/components/v2/Select/EnvironmentSelect.vue
index 3248f8d0cd..6bd8924dcb 100644
--- a/frontend/src/components/v2/Select/EnvironmentSelect.vue
+++ b/frontend/src/components/v2/Select/EnvironmentSelect.vue
@@ -25,11 +25,12 @@ interface EnvironmentSelectOption extends SelectOption {
const props = withDefaults(
defineProps<{
- environment: string | undefined;
+ environment?: string | undefined;
includeArchived?: boolean;
filter?: (environment: Environment, index: number) => boolean;
}>(),
{
+ environment: undefined,
includeArchived: false,
filter: () => true,
}
diff --git a/frontend/src/components/v2/Select/InstanceSelect.vue b/frontend/src/components/v2/Select/InstanceSelect.vue
index a7c9795458..c6437ece64 100644
--- a/frontend/src/components/v2/Select/InstanceSelect.vue
+++ b/frontend/src/components/v2/Select/InstanceSelect.vue
@@ -31,7 +31,7 @@ interface InstanceSelectOption extends SelectOption {
const props = withDefaults(
defineProps<{
- instance: string | undefined;
+ instance?: string | undefined;
environment?: string;
allowedEngineList?: readonly Engine[];
includeAll?: boolean;
@@ -40,6 +40,7 @@ const props = withDefaults(
filter?: (instance: ComposedInstance, index: number) => boolean;
}>(),
{
+ instance: undefined,
environment: undefined,
allowedEngineList: () => supportedEngineV1List(),
includeAll: false,
diff --git a/frontend/src/utils/deployment.ts b/frontend/src/utils/deployment.ts
deleted file mode 100644
index 2a7d9f0586..0000000000
--- a/frontend/src/utils/deployment.ts
+++ /dev/null
@@ -1,35 +0,0 @@
-import { PRESET_DB_NAME_TEMPLATE_PLACEHOLDERS } from "./label";
-
-export const buildDatabaseNameRegExpByTemplate = (template: string): RegExp => {
- let regexpString = template;
-
- /*
- Rewrite the placeholder-based template to a big RegExp
- e.g. template = "{{DB_NAME}}__{{TENANT}}"
- here regex will be /^(?<DB_NAME>.+?)__(?<TENANT>.+?)$/
- */
- PRESET_DB_NAME_TEMPLATE_PLACEHOLDERS.forEach((placeholder) => {
- const pattern = `{{${placeholder}}}`;
- const groupRegExp = `(?<${placeholder}>.+?)`;
- regexpString = regexpString.replace(pattern, groupRegExp);
- });
-
- const regexp = new RegExp(`^${regexpString}$`);
- return regexp;
-};
-
-export const parseDatabaseLabelValueByTemplate = (
- template: string,
- name: string,
- group: "DB_NAME" | "TENANT"
-) => {
- if (!template) return "";
-
- const regex = buildDatabaseNameRegExpByTemplate(template);
- const matches = name.match(regex);
- if (!matches) return "";
-
- const value = matches.groups?.[group];
- if (!value) return "";
- return value;
-};
diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts
index 1ec40e252d..e8c9b95143 100644
--- a/frontend/src/utils/index.ts
+++ b/frontend/src/utils/index.ts
@@ -13,7 +13,6 @@ export * from "./table";
export * from "./types";
export * from "./util";
export * from "./label";
-export * from "./deployment";
export * from "./string";
export * from "./tab";
export * from "./task";
diff --git a/frontend/src/utils/label.ts b/frontend/src/utils/label.ts
index 13efcd98e8..50cc9a8f32 100644
--- a/frontend/src/utils/label.ts
+++ b/frontend/src/utils/label.ts
@@ -1,4 +1,4 @@
-import { capitalize, orderBy, uniq } from "lodash-es";
+import { orderBy, uniq } from "lodash-es";
import { useEnvironmentV1Store } from "@/store";
import { ComposedDatabase } from "@/types";
import {
@@ -141,10 +141,6 @@ export const displayLabelKey = (key: string) => {
return "Environment ID";
}
- if (key.startsWith("bb.")) {
- const word = key.split("bb.")[1];
- return capitalize(word);
- }
return key;
};