Skip to content

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

chore: update preview database group issue (#12196)

boojackfd771593f185
diff --git a/backend/common/resource_name.go b/backend/common/resource_name.go
index f18a667080..15126db376 100644
--- a/backend/common/resource_name.go
+++ b/backend/common/resource_name.go
@@ -35,7 +35,6 @@ const (
SheetIDPrefix = "sheets/"
WorksheetIDPrefix = "worksheets/"
DatabaseGroupNamePrefix = "databaseGroups/"
- SchemaGroupNamePrefix = "schemaGroups/"
SchemaNamePrefix = "schemas/"
TableNamePrefix = "tables/"
ChangeHistoryPrefix = "changeHistories/"
@@ -74,15 +73,6 @@ func GetProjectIDDatabaseGroupID(name string) (string, string, error) {
return tokens[0], tokens[1], nil
}
-// GetProjectIDDatabaseGroupIDSchemaGroupID returns the project ID, database group ID, and schema group ID from a resource name.
-func GetProjectIDDatabaseGroupIDSchemaGroupID(name string) (string, string, string, error) {
- tokens, err := GetNameParentTokens(name, ProjectNamePrefix, DatabaseGroupNamePrefix, SchemaGroupNamePrefix)
- if err != nil {
- return "", "", "", err
- }
- return tokens[0], tokens[1], tokens[2], nil
-}
-
// GetSchemaTableName returns the schema and table names from a resource name.
func GetSchemaTableName(name string) (string, string, error) {
tokens, err := GetNameParentTokens(name, SchemaNamePrefix, TableNamePrefix)
diff --git a/backend/legacyapi/task.go b/backend/legacyapi/task.go
index d58aa0d7c8..8037c7def3 100644
--- a/backend/legacyapi/task.go
+++ b/backend/legacyapi/task.go
@@ -91,9 +91,8 @@ type TaskDatabaseSchemaUpdatePayload struct {
SkippedReason string `json:"skippedReason,omitempty"`
SpecID string `json:"specId,omitempty"`
- SheetID int `json:"sheetId,omitempty"`
- SchemaVersion string `json:"schemaVersion,omitempty"`
- SchemaGroupName string `json:"schemaGroupName,omitempty"`
+ SheetID int `json:"sheetId,omitempty"`
+ SchemaVersion string `json:"schemaVersion,omitempty"`
}
// TaskDatabaseSchemaUpdateSDLPayload is the task payload for database schema update (SDL).
@@ -183,8 +182,6 @@ type TaskDatabaseDataUpdatePayload struct {
// RollbackFromTaskID is the task ID from which the rollback SQL statement is generated for this task.
RollbackFromTaskID int `json:"rollbackFromTaskId,omitempty"`
PreUpdateBackupDetail PreUpdateBackupDetail `json:"preUpdateBackupDetail,omitempty"`
-
- SchemaGroupName string `json:"schemaGroupName,omitempty"`
}
type PreUpdateBackupDetail struct {
diff --git a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
index 2d8963db1f..f81dfea20d 100644
--- a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
@@ -259,14 +259,6 @@
:plan-only="state.planOnly"
@close="state.showSchemaEditorModal = false"
/>
-
- <DatabaseGroupPrevEditorModal
- v-if="state.showDatabaseGroupPrevModal"
- :issue-type="type"
- :database-group-name="state.selectedDatabaseGroupName!"
- :plan-only="state.planOnly"
- @close="state.showDatabaseGroupPrevModal = false"
- />
</template>
<script lang="ts" setup>
@@ -300,10 +292,7 @@ import {
useProjectV1Store,
useDBGroupStore,
} from "@/store";
-import type {
- ComposedDatabase,
- FeatureType,
-} from "@/types";
+import type { ComposedDatabase, FeatureType } from "@/types";
import { UNKNOWN_ID, DEFAULT_PROJECT_V1_NAME } from "@/types";
import { State } from "@/types/proto/v1/common";
import { TenantMode } from "@/types/proto/v1/project_service";
@@ -319,10 +308,10 @@ import {
extractProjectResourceName,
isDev,
} from "@/utils";
+import { generateDatabaseGroupIssueRoute } from "@/utils/databaseGroup/issue";
import AdvancedSearch from "../AdvancedSearch";
import { useCommonSearchScopeOptions } from "../AdvancedSearch/useCommonSearchScopeOptions";
import { DatabaseLabelFilter, DrawerContent } from "../v2";
-import DatabaseGroupPrevEditorModal from "./DatabaseGroupPrevEditorModal.vue";
import ProjectStandardView from "./ProjectStandardView.vue";
import ProjectTenantView from "./ProjectTenantView.vue";
import SchemaEditorModal from "./SchemaEditorModal.vue";
@@ -337,7 +326,6 @@ type LocalState = {
selectedDatabaseUidList: Set<string>;
showSchemaEditorModal: boolean;
selectedDatabaseGroupName?: string;
- showDatabaseGroupPrevModal: boolean;
params: SearchParams;
// planOnly is used to indicate whether only to create plan.
planOnly: boolean;
@@ -387,7 +375,6 @@ const state = reactive<LocalState>({
showSchemaLessDatabaseList: false,
showSchemaEditorModal: false,
selectedLabels: [],
- showDatabaseGroupPrevModal: false,
params: {
query: "",
scopes: [],
@@ -590,13 +577,37 @@ const allowGenerateMultiDb = computed(() => {
}
});
+const previewDatabaseGroupIssue = () => {
+ if (!state.selectedDatabaseGroupName) {
+ // Should not reach here.
+ return;
+ }
+
+ const databaseGroup = dbGroupStore.getDBGroupByName(
+ state.selectedDatabaseGroupName
+ );
+ if (!databaseGroup) {
+ console.error("Database group not found");
+ return;
+ }
+
+ router.push(
+ generateDatabaseGroupIssueRoute(
+ props.type,
+ databaseGroup,
+ "",
+ state.planOnly
+ )
+ );
+};
+
// Also works when single db selected.
const generateMultiDb = async () => {
if (
state.databaseSelectedTab === "DATABASE_GROUP" &&
state.selectedDatabaseGroupName
) {
- state.showDatabaseGroupPrevModal = true;
+ previewDatabaseGroupIssue();
return;
}
@@ -668,23 +679,11 @@ const handleDatabaseGroupsSelectionChanged = (
): void => {
const databaseGroupName = head(Array.from(databaseGroupNames));
if (!databaseGroupName) return;
- selectDatabaseGroup(databaseGroupName, true);
-};
-
-const selectDatabaseGroup = async (
- databaseGroupName: string,
- showModal = false
-) => {
if (!hasDatabaseGroupFeature.value) {
featureModalContext.value.feature = "bb.feature.database-grouping";
return;
}
-
state.selectedDatabaseGroupName = databaseGroupName;
-
- if (showModal) {
- state.showDatabaseGroupPrevModal = true;
- }
};
const generateTenant = async () => {
@@ -692,7 +691,7 @@ const generateTenant = async () => {
state.databaseSelectedTab === "DATABASE_GROUP" &&
state.selectedDatabaseGroupName
) {
- state.showDatabaseGroupPrevModal = true;
+ previewDatabaseGroupIssue();
return;
}
diff --git a/frontend/src/components/AlterSchemaPrepForm/DatabaseGroupPrevEditorModal.vue b/frontend/src/components/AlterSchemaPrepForm/DatabaseGroupPrevEditorModal.vue
deleted file mode 100644
index 5c91d00b6e..0000000000
--- a/frontend/src/components/AlterSchemaPrepForm/DatabaseGroupPrevEditorModal.vue
+++ /dev/null
@@ -1,149 +0,0 @@
-<template>
- <BBModal
- :title="title"
- class="w-auto h-auto overflow-auto"
- @close="dismissModal"
- >
- <div
- class="w-192 h-auto flex flex-col justify-start items-start overflow-y-auto gap-y-2"
- >
- <div
- class="w-full h-auto shrink-0 flex flex-row justify-between items-center space-x-4 my-2"
- >
- <div class="textinfolabel">
- {{ $t("database-group.prev-editor.description") }}
- <LearnMoreLink
- url="https://www.bytebase.com/docs/change-database/batch-change/#change-databases-from-database-groups?source=console"
- class="ml-1"
- />
- </div>
- <div class="flex flex-row justify-end items-center shrink-0">
- <SQLUploadButton
- @update:sql="(statement) => (state.editStatement = statement)"
- >
- {{ $t("issue.upload-sql") }}
- </SQLUploadButton>
- </div>
- </div>
- <div class="relative w-full h-96 border rounded overflow-clip">
- <MonacoEditor
- v-model:content="state.editStatement"
- class="w-full min-h-full"
- />
- </div>
- </div>
- <div class="w-full flex flex-row justify-end items-center mt-4">
- <div class="flex justify-end items-center gap-x-3">
- <NCheckbox v-if="isDev()" v-model:checked="state.planOnly">
- {{ $t("issue.sql-review-only") }}
- </NCheckbox>
- <NButton @click="dismissModal">
- {{ $t("common.cancel") }}
- </NButton>
- <NButton
- type="primary"
- :disabled="!allowPreviewIssue"
- @click="handlePreviewIssue"
- >
- {{ $t("schema-editor.preview-issue") }}
- </NButton>
- </div>
- </div>
- </BBModal>
-
- <!-- Close modal confirm dialog -->
- <ActionConfirmModal
- v-model:show="state.showActionConfirmModal"
- :title="$t('schema-editor.confirm-to-close.title')"
- :description="$t('schema-editor.confirm-to-close.description')"
- @confirm="emit('close')"
- />
-</template>
-
-<script lang="ts" setup>
-import { NButton, NCheckbox } from "naive-ui";
-import type { PropType } from "vue";
-import { computed, reactive } from "vue";
-import { useI18n } from "vue-i18n";
-import { useRouter } from "vue-router";
-import { MonacoEditor } from "@/components/MonacoEditor";
-import { ActionConfirmModal } from "@/components/SchemaEditorLite";
-import SQLUploadButton from "@/components/misc/SQLUploadButton.vue";
-import { useDBGroupStore } from "@/store";
-import type { ComposedDatabaseGroup } from "@/types";
-import { isDev } from "@/utils";
-import { generateDatabaseGroupIssueRoute } from "@/utils/databaseGroup/issue";
-
-interface LocalState {
- editStatement: string;
- showActionConfirmModal: boolean;
- // planOnly is used to indicate whether only to create plan.
- planOnly: boolean;
-}
-
-const props = defineProps({
- databaseGroupName: {
- type: String,
- required: true,
- },
- issueType: {
- type: String as PropType<
- "bb.issue.database.schema.update" | "bb.issue.database.data.update"
- >,
- required: true,
- },
- planOnly: {
- type: Boolean,
- default: false,
- },
-});
-
-const emit = defineEmits<{
- (event: "close"): void;
-}>();
-
-const { t } = useI18n();
-const router = useRouter();
-const dbGroupStore = useDBGroupStore();
-const state = reactive<LocalState>({
- editStatement: "",
- showActionConfirmModal: false,
- planOnly: props.planOnly,
-});
-
-const databaseGroup = computed(() => {
- return dbGroupStore.getDBGroupByName(
- props.databaseGroupName
- ) as ComposedDatabaseGroup;
-});
-
-const allowPreviewIssue = computed(() => {
- return state.editStatement !== "";
-});
-
-const title = computed(() => {
- if (props.issueType === "bb.issue.database.schema.update") {
- return t("database.edit-schema");
- } else {
- return t("database.change-data");
- }
-});
-
-const dismissModal = () => {
- if (allowPreviewIssue.value) {
- state.showActionConfirmModal = true;
- } else {
- emit("close");
- }
-};
-
-const handlePreviewIssue = async () => {
- const issueRoute = generateDatabaseGroupIssueRoute(
- props.issueType,
- databaseGroup.value,
- state.editStatement,
- state.planOnly
- );
- router.push(issueRoute);
-};
-</script>
diff --git a/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue b/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue
index 315ac3d801..8947aa0aad 100644
--- a/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue
+++ b/frontend/src/components/DatabaseGroup/ProjectDatabaseGroupPanel.vue
@@ -15,7 +15,6 @@
<DatabaseGroupPanel
:show="state.showDatabaseGroupPanel"
:project="project"
- :resource-type="'DATABASE_GROUP'"
:database-group="state.editingDatabaseGroup"
@close="state.showDatabaseGroupPanel = false"
/>
diff --git a/frontend/src/components/DatabaseGroup/utils.ts b/frontend/src/components/DatabaseGroup/utils.ts
index 8d94484d61..6a88d6642f 100644
--- a/frontend/src/components/DatabaseGroup/utils.ts
+++ b/frontend/src/components/DatabaseGroup/utils.ts
@@ -6,8 +6,6 @@ import {
extractInstanceResourceName,
} from "@/utils";
-export type ResourceType = "DATABASE_GROUP";
-
export const FactorList: Factor[] = [
"resource.environment_name",
"resource.database_name",
diff --git a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
index f6d71d17ae..d94822c6eb 100644
--- a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
+++ b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
@@ -332,10 +332,6 @@ const allowEditStatementWhenCreating = computed(() => {
// E.g., rollback DML
return false;
}
- if (route.query.databaseGroupName) {
- // Not allowed to edit SQL for grouping changes.
- return false;
- }
if (selectedTask.value.type === Task_Type.DATABASE_SCHEMA_BASELINE) {
// A baseline issue has actually no SQL statement.
// "-- Establish baseline using current schema" is just a comment.
diff --git a/frontend/src/components/IssueV1/logic/initialize/create.ts b/frontend/src/components/IssueV1/logic/initialize/create.ts
index 7d32537133..e197976c2c 100644
--- a/frontend/src/components/IssueV1/logic/initialize/create.ts
+++ b/frontend/src/components/IssueV1/logic/initialize/create.ts
@@ -438,16 +438,10 @@ const maybeWrapStatementsAsSheets = (
const { tasks } = stage;
for (let j = 0; j < tasks.length; j++) {
const task = tasks[j];
- // For database group changes, tasks returned by previewRollout
- // have `sheet` fields actually generated SQL statements instead
- // of sheet names.
- // So we create a local sheet for each task and set the statement
- // to the local task.
- const statement = sheetNameOfTaskV1(task);
const sheetName = `${params.project.name}/sheets/${nextUID()}`;
const sheet = getLocalSheetByName(sheetName);
sheet.database = task.target;
- setSheetStatement(sheet, statement);
+ setSheetStatement(sheet, getSheetStatement(sheet));
setSheetNameForTask(task, sheetName);
}
}
diff --git a/frontend/src/components/RepositoryForm.vue b/frontend/src/components/RepositoryForm.vue
index ac636929de..ca2cad1ee7 100644
--- a/frontend/src/components/RepositoryForm.vue
+++ b/frontend/src/components/RepositoryForm.vue
@@ -110,7 +110,6 @@
<DatabaseGroupPanel
:show="showDatabaseGroupPanel"
:project="project"
- :resource-type="'DATABASE_GROUP'"
:redirect-to-detail-page="false"
@close="showDatabaseGroupPanel = false"
/>
diff --git a/frontend/src/store/modules/dbGroup.ts b/frontend/src/store/modules/dbGroup.ts
index 94004be3bd..dde80c7e46 100644
--- a/frontend/src/store/modules/dbGroup.ts
+++ b/frontend/src/store/modules/dbGroup.ts
@@ -18,9 +18,7 @@ import type {
} from "@/types";
import { ParsedExpr } from "@/types/proto/google/api/expr/v1alpha1/syntax";
import { Expr } from "@/types/proto/google/type/expr";
-import type {
- DatabaseGroup,
-} from "@/types/proto/v1/project_service";
+import type { DatabaseGroup } from "@/types/proto/v1/project_service";
import {
DatabaseGroupView,
TenantMode,
@@ -147,7 +145,9 @@ export const useDBGroupStore = defineStore("db-group", () => {
);
};
- const getDBGroupByName = (name: string) => {
+ const getDBGroupByName = (
+ name: string
+ ): ComposedDatabaseGroup | undefined => {
return dbGroupMapByName.value.get(name);
};
diff --git a/frontend/src/types/dbGroup.ts b/frontend/src/types/dbGroup.ts
index 4b5ed4f31a..b028c87631 100644
--- a/frontend/src/types/dbGroup.ts
+++ b/frontend/src/types/dbGroup.ts
@@ -1,8 +1,6 @@
import type { ConditionGroupExpr } from "@/plugins/cel";
import type { ComposedProject } from "@/types";
-import type {
- DatabaseGroup,
-} from "./proto/v1/project_service";
+import type { DatabaseGroup } from "./proto/v1/project_service";
export interface ComposedDatabaseGroup extends DatabaseGroup {
databaseGroupName: string;
diff --git a/frontend/src/views/DatabaseGroupDetail.vue b/frontend/src/views/DatabaseGroupDetail.vue
index ffb846068e..7b6143c7d6 100644
--- a/frontend/src/views/DatabaseGroupDetail.vue
+++ b/frontend/src/views/DatabaseGroupDetail.vue
@@ -47,13 +47,15 @@
</NButton>
<NButton
v-if="hasPermissionToCreateIssue"
- @click="createMigration('bb.issue.database.schema.update')"
+ @click="
+ previewDatabaseGroupIssue('bb.issue.database.schema.update')
+ "
>
{{ $t("database.edit-schema") }}
</NButton>
<NButton
v-if="hasPermissionToCreateIssue"
- @click="createMigration('bb.issue.database.data.update')"
+ @click="previewDatabaseGroupIssue('bb.issue.database.data.update')"
>
{{ $t("database.change-data") }}
</NButton>
@@ -99,20 +101,13 @@
:parent-database-group="editState.parentDatabaseGroup"
@close="editState.showConfigurePanel = false"
/>
-
- <DatabaseGroupPrevEditorModal
- v-if="issueType"
- :issue-type="issueType"
- :database-group-name="databaseGroup.name"
- @close="issueType = undefined"
- />
</template>
<script lang="ts" setup>
import { useDebounceFn } from "@vueuse/core";
import { NButton } from "naive-ui";
import { onMounted, reactive, computed, watch, ref } from "vue";
-import DatabaseGroupPrevEditorModal from "@/components/AlterSchemaPrepForm/DatabaseGroupPrevEditorModal.vue";
+import { useRouter } from "vue-router";
import DatabaseGroupPanel from "@/components/DatabaseGroup/DatabaseGroupPanel.vue";
import MatchedDatabaseView from "@/components/DatabaseGroup/MatchedDatabaseView.vue";
import { FactorList } from "@/components/DatabaseGroup/utils";
@@ -128,18 +123,12 @@ import {
useProjectV1Store,
useSubscriptionV1Store,
} from "@/store";
-import {
- databaseGroupNamePrefix,
-} from "@/store/modules/v1/common";
+import { databaseGroupNamePrefix } from "@/store/modules/v1/common";
import { projectNamePrefix } from "@/store/modules/v1/common";
-import type {
- ComposedDatabase,
- ComposedDatabaseGroup,
-} from "@/types";
-import type {
- DatabaseGroup,
-} from "@/types/proto/v1/project_service";
+import type { ComposedDatabase, ComposedDatabaseGroup } from "@/types";
+import type { DatabaseGroup } from "@/types/proto/v1/project_service";
import { hasPermissionToCreateChangeDatabaseIssueInProject } from "@/utils";
+import { generateDatabaseGroupIssueRoute } from "@/utils/databaseGroup/issue";
interface LocalState {
isLoaded: boolean;
@@ -158,6 +147,7 @@ const props = defineProps<{
allowEdit: boolean;
}>();
+const router = useRouter();
const projectStore = useProjectV1Store();
const dbGroupStore = useDBGroupStore();
const subscriptionV1Store = useSubscriptionV1Store();
@@ -169,11 +159,6 @@ const state = reactive<LocalState>({
const editState = reactive<EditDatabaseGroupState>({
showConfigurePanel: false,
});
-const issueType = ref<
- | "bb.issue.database.schema.update"
- | "bb.issue.database.data.update"
- | undefined
->();
const project = computed(() => {
return projectStore.getProjectByName(
`${projectNamePrefix}${props.projectId}`
@@ -203,10 +188,11 @@ const handleEditDatabaseGroup = () => {
editState.showConfigurePanel = true;
};
-const createMigration = (
+const previewDatabaseGroupIssue = (
type: "bb.issue.database.schema.update" | "bb.issue.database.data.update"
) => {
- issueType.value = type;
+ const issueRoute = generateDatabaseGroupIssueRoute(type, databaseGroup.value);
+ router.push(issueRoute);
};
watch(