Skip to content

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

chore: unify build plan methods (#16240)

boojack60aff1c0d67a
diff --git a/frontend/src/components/DatabaseAndGroupSelector/DatabaseAndGroupSelector.vue b/frontend/src/components/DatabaseAndGroupSelector/DatabaseAndGroupSelector.vue
index 646d2c2a40..6c96a3bf64 100644
--- a/frontend/src/components/DatabaseAndGroupSelector/DatabaseAndGroupSelector.vue
+++ b/frontend/src/components/DatabaseAndGroupSelector/DatabaseAndGroupSelector.vue
@@ -1,5 +1,9 @@
<template>
- <NTabs v-model:value="databaseSelectState.changeSource" type="card">
+ <NTabs
+ v-model:value="databaseSelectState.changeSource"
+ type="card"
+ size="small"
+ >
<NTabPane name="DATABASE" :tab="$t('common.databases')">
<AdvancedSearch
v-model:params="searchParams"
@@ -14,6 +18,7 @@
:custom-click="true"
:parent="project.name"
:filter="filter"
+ :size="'small'"
v-model:selected-database-names="
databaseSelectState.selectedDatabaseNameList
"
diff --git a/frontend/src/components/DatabaseGroup/DatabaseGroupDataTable.vue b/frontend/src/components/DatabaseGroup/DatabaseGroupDataTable.vue
index 8143a08966..cc98051bb7 100644
--- a/frontend/src/components/DatabaseGroup/DatabaseGroupDataTable.vue
+++ b/frontend/src/components/DatabaseGroup/DatabaseGroupDataTable.vue
@@ -1,5 +1,6 @@
<template>
<NDataTable
+ v-bind="$attrs"
size="small"
:columns="columnList"
:data="data"
diff --git a/frontend/src/components/IssueV1/DataExportIssueDetailPage.vue b/frontend/src/components/IssueV1/DataExportIssueDetailPage.vue
index 220f5e60b2..2322a2ae9e 100644
--- a/frontend/src/components/IssueV1/DataExportIssueDetailPage.vue
+++ b/frontend/src/components/IssueV1/DataExportIssueDetailPage.vue
@@ -132,7 +132,11 @@ providePlanSQLCheckContext({
project,
plan: computed(() => issue.value.planEntity as Plan),
selectedSpec: computed(
- () => specForTask(issue.value.planEntity, selectedTask.value) as Plan_Spec
+ () =>
+ specForTask(
+ issue.value.planEntity as Plan,
+ selectedTask.value
+ ) as Plan_Spec
),
selectedTask: selectedTask,
});
diff --git a/frontend/src/components/IssueV1/IssueDetailPage.vue b/frontend/src/components/IssueV1/IssueDetailPage.vue
index 7786021e1f..dc48ea365b 100644
--- a/frontend/src/components/IssueV1/IssueDetailPage.vue
+++ b/frontend/src/components/IssueV1/IssueDetailPage.vue
@@ -136,7 +136,11 @@ providePlanSQLCheckContext({
project,
plan: computed(() => issue.value.planEntity as Plan),
selectedSpec: computed(
- () => specForTask(issue.value.planEntity, selectedTask.value) as Plan_Spec
+ () =>
+ specForTask(
+ issue.value.planEntity as Plan,
+ selectedTask.value
+ ) as Plan_Spec
),
selectedTask: selectedTask,
});
diff --git a/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportOptionSection.vue b/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportOptionSection.vue
index 49b960af5a..5b8c2515ed 100644
--- a/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportOptionSection.vue
+++ b/frontend/src/components/IssueV1/components/DataExportSection/ExportOptionSection/ExportOptionSection.vue
@@ -64,7 +64,6 @@ import { computed, watch, reactive, ref } from "vue";
import { useI18n } from "vue-i18n";
import {
allowUserToEditStatementForTask,
- notifyNotEditableLegacyIssue,
useIssueContext,
} from "@/components/IssueV1/logic";
import ErrorList from "@/components/misc/ErrorList.vue";
@@ -127,8 +126,8 @@ const handleCancelEdit = () => {
const handleSaveEdit = async () => {
const planPatch = cloneDeep(issue.value.planEntity);
if (!planPatch) {
- notifyNotEditableLegacyIssue();
- return;
+ // Should not reach here.
+ throw new Error("Plan is not defined. Cannot update export options.");
}
const distinctSpecIds = new Set([spec.value.id]);
diff --git a/frontend/src/components/IssueV1/components/DescriptionSection/DescriptionSection.vue b/frontend/src/components/IssueV1/components/DescriptionSection/DescriptionSection.vue
index 08f2ffae41..6ce1d392aa 100644
--- a/frontend/src/components/IssueV1/components/DescriptionSection/DescriptionSection.vue
+++ b/frontend/src/components/IssueV1/components/DescriptionSection/DescriptionSection.vue
@@ -88,7 +88,7 @@ type LocalState = {
};
const { t } = useI18n();
-const { isCreating, issue, allowEditIssue } = useIssueContext();
+const { isCreating, issue, allowChange: allowEditIssue } = useIssueContext();
const { project } = useCurrentProjectV1();
const contentPreviewArea = ref<HTMLIFrameElement>();
diff --git a/frontend/src/components/IssueV1/components/HeaderSection/Title.vue b/frontend/src/components/IssueV1/components/HeaderSection/Title.vue
index de498a59a6..190e319516 100644
--- a/frontend/src/components/IssueV1/components/HeaderSection/Title.vue
+++ b/frontend/src/components/IssueV1/components/HeaderSection/Title.vue
@@ -30,7 +30,7 @@ import { useIssueContext } from "../../logic";
type ViewMode = "EDIT" | "VIEW";
const { t } = useI18n();
-const { isCreating, issue, allowEditIssue } = useIssueContext();
+const { isCreating, issue, allowChange: allowEditIssue } = useIssueContext();
const state = reactive({
isEditing: false,
diff --git a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckSection.vue b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckSection.vue
index defe13c95c..49c5f52341 100644
--- a/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckSection.vue
+++ b/frontend/src/components/IssueV1/components/PlanCheckSection/PlanCheckSection.vue
@@ -22,8 +22,7 @@ import { useCurrentUserV1, extractUserId, useCurrentProjectV1 } from "@/store";
import { hasProjectPermissionV2, isValidTaskName } from "@/utils";
const currentUser = useCurrentUserV1();
-const { issue, selectedTask, getPlanCheckRunsForTask } =
- useIssueContext();
+const { issue, selectedTask, getPlanCheckRunsForTask } = useIssueContext();
const { project } = useCurrentProjectV1();
const show = computed(() => {
diff --git a/frontend/src/components/IssueV1/components/Sidebar/IssueLabels.vue b/frontend/src/components/IssueV1/components/Sidebar/IssueLabels.vue
index f27ece3c63..0d3c4e284d 100644
--- a/frontend/src/components/IssueV1/components/Sidebar/IssueLabels.vue
+++ b/frontend/src/components/IssueV1/components/Sidebar/IssueLabels.vue
@@ -21,7 +21,7 @@ import { issueServiceClient } from "@/grpcweb";
import { pushNotification } from "@/store";
import { Issue } from "@/types/proto/v1/issue_service";
-const { isCreating, issue, allowEditIssue } = useIssueContext();
+const { isCreating, issue, allowChange: allowEditIssue } = useIssueContext();
const { t } = useI18n();
const onLablesUpdate = async (labels: string[]) => {
diff --git a/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/PreBackupSection.vue b/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/PreBackupSection.vue
index ae899b941b..409815964c 100644
--- a/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/PreBackupSection.vue
+++ b/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/PreBackupSection.vue
@@ -10,10 +10,10 @@ import {
specForTask,
useIssueContext,
} from "@/components/IssueV1/logic";
-import { useCurrentProjectV1 } from "@/store";
import { PreBackupSection } from "@/components/Plan/components/Sidebar";
import { providePreBackupSettingContext } from "@/components/Plan/components/Sidebar/PreBackupSection/context";
import { databaseForTask } from "@/components/Rollout/RolloutDetail";
+import { useCurrentProjectV1 } from "@/store";
import type { Plan } from "@/types/proto/v1/plan_service";
import { TaskRun_Status } from "@/types/proto/v1/rollout_service";
import TaskRollbackSection from "./TaskRollbackSection.vue";
@@ -30,7 +30,7 @@ const {
project,
plan: computed(() => issue.value.planEntity as Plan),
selectedSpec: computed(() =>
- specForTask(issue.value.planEntity, selectedTask.value)
+ specForTask(issue.value.planEntity as Plan, selectedTask.value)
),
selectedTask,
issue,
diff --git a/frontend/src/components/IssueV1/components/Sidebar/Sidebar.vue b/frontend/src/components/IssueV1/components/Sidebar/Sidebar.vue
index 8302448a68..d057339ed7 100644
--- a/frontend/src/components/IssueV1/components/Sidebar/Sidebar.vue
+++ b/frontend/src/components/IssueV1/components/Sidebar/Sidebar.vue
@@ -16,9 +16,9 @@
import { computed } from "vue";
import { GhostSection } from "@/components/Plan/components/Sidebar";
import { provideGhostSettingContext } from "@/components/Plan/components/Sidebar/GhostSection/context";
+import { useCurrentProjectV1 } from "@/store";
import type { Plan } from "@/types/proto/v1/plan_service";
import { specForTask, useIssueContext } from "../../logic";
-import { useCurrentProjectV1 } from "@/store";
import IssueLabels from "./IssueLabels.vue";
import PreBackupSection from "./PreBackupSection";
import ReleaseInfo from "./ReleaseInfo.vue";
@@ -34,7 +34,7 @@ const { shouldShow: shouldShowGhostSection, events: ghostEvents } =
project,
plan: computed(() => issue.value.planEntity as Plan),
selectedSpec: computed(() =>
- specForTask(issue.value.planEntity, selectedTask.value)
+ specForTask(issue.value.planEntity as Plan, selectedTask.value)
),
selectedTask: selectedTask,
issue,
diff --git a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
index bf5995b655..7bf265a72d 100644
--- a/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
+++ b/frontend/src/components/IssueV1/components/StatementSection/EditorView/EditorView.vue
@@ -206,7 +206,6 @@ import {
stageForTask,
isTaskEditable,
specForTask,
- notifyNotEditableLegacyIssue,
isGroupingChangeTaskV1,
databaseEngineForSpec,
} from "@/components/IssueV1/logic";
@@ -218,7 +217,12 @@ import DownloadSheetButton from "@/components/Sheet/DownloadSheetButton.vue";
import SQLUploadButton from "@/components/misc/SQLUploadButton.vue";
import { planServiceClient } from "@/grpcweb";
import { emitWindowEvent } from "@/plugins";
-import { hasFeature, pushNotification, useSheetV1Store, useCurrentProjectV1 } from "@/store";
+import {
+ hasFeature,
+ pushNotification,
+ useSheetV1Store,
+ useCurrentProjectV1,
+} from "@/store";
import type { SQLDialect } from "@/types";
import {
EMPTY_ID,
@@ -599,8 +603,8 @@ const handleUpdateStatement = async (statement: string, filename: string) => {
const updateStatement = async (statement: string) => {
const planPatch = cloneDeep(issue.value.planEntity);
if (!planPatch) {
- notifyNotEditableLegacyIssue();
- return;
+ // Should not reach here.
+ throw new Error("Plan is not defined. Cannot update statement.");
}
const specsIdList: string[] = [];
@@ -629,8 +633,8 @@ const updateStatement = async (statement: string) => {
specsIdList.filter((id) => id && id !== String(EMPTY_ID))
);
if (distinctSpecsIds.size === 0) {
- notifyNotEditableLegacyIssue();
- return;
+ // Should not reach here.
+ throw new Error("No valid specs found for the selected task(s).");
}
const specsToPatch = planPatch.steps
diff --git a/frontend/src/components/IssueV1/components/TaskListSection/TaskCard.vue b/frontend/src/components/IssueV1/components/TaskListSection/TaskCard.vue
index c57963a999..d92401d089 100644
--- a/frontend/src/components/IssueV1/components/TaskListSection/TaskCard.vue
+++ b/frontend/src/components/IssueV1/components/TaskListSection/TaskCard.vue
@@ -58,13 +58,13 @@ import { twMerge } from "tailwind-merge";
import { computed } from "vue";
import { databaseForTask } from "@/components/Rollout/RolloutDetail";
import { InstanceV1Name } from "@/components/v2";
+import { useCurrentProjectV1 } from "@/store";
import { isValidDatabaseName } from "@/types";
import { Plan_ChangeDatabaseConfig_Type } from "@/types/proto/v1/plan_service";
import { Task } from "@/types/proto/v1/rollout_service";
import { Task_Type, task_StatusToJSON } from "@/types/proto/v1/rollout_service";
import { databaseV1Url, extractSchemaVersionFromTask, isDev } from "@/utils";
import { useInstanceForTask, specForTask, useIssueContext } from "../../logic";
-import { useCurrentProjectV1 } from "@/store";
import TaskStatusIcon from "../TaskStatusIcon.vue";
import TaskExtraActionsButton from "./TaskExtraActionsButton.vue";
diff --git a/frontend/src/components/IssueV1/logic/context.ts b/frontend/src/components/IssueV1/logic/context.ts
index 0b0a1e2cc6..42fd642372 100644
--- a/frontend/src/components/IssueV1/logic/context.ts
+++ b/frontend/src/components/IssueV1/logic/context.ts
@@ -44,13 +44,13 @@ export type IssueContext = {
ready: Ref<boolean>;
issue: Ref<ComposedIssue>;
phase: Ref<IssuePhase>;
- // The release candidates of the issue.
- // Format: users/{email}
- releaserCandidates: Ref<string[]>;
- allowEditIssue: ComputedRef<boolean>;
+ allowChange: ComputedRef<boolean>;
// review status
reviewContext: ReviewContext;
+ // The release candidates of the issue.
+ // Format: users/{email}
+ releaserCandidates: Ref<string[]>;
// UI status
selectedStage: Ref<Stage>;
diff --git a/frontend/src/components/IssueV1/logic/initialize/create.ts b/frontend/src/components/IssueV1/logic/initialize/create.ts
index dfbd15488e..202f6f09ed 100644
--- a/frontend/src/components/IssueV1/logic/initialize/create.ts
+++ b/frontend/src/components/IssueV1/logic/initialize/create.ts
@@ -1,65 +1,28 @@
-import { cloneDeep, groupBy, orderBy } from "lodash-es";
-import { v4 as uuidv4 } from "uuid";
import { reactive } from "vue";
import { useRoute } from "vue-router";
import {
+ buildPlan,
extractInitialSQLFromQuery,
getLocalSheetByName,
+ type CreatePlanParams,
} from "@/components/Plan";
-import { getArchiveDatabase } from "@/components/Plan/components/Sidebar/PreBackupSection/utils";
import { rolloutServiceClient } from "@/grpcweb";
-import {
- useChangelistStore,
- useCurrentUserV1,
- useDatabaseV1Store,
- useEnvironmentV1Store,
- useProjectV1Store,
- useSheetV1Store,
- batchGetOrFetchDatabases,
-} from "@/store";
-import {
- databaseNamePrefix,
- projectNamePrefix,
-} from "@/store/modules/v1/common";
-import type { ComposedProject, IssueType } from "@/types";
-import {
- emptyIssue,
- isValidDatabaseName,
- TaskTypeListWithStatement,
-} from "@/types";
+import { useCurrentUserV1, useProjectV1Store, useSheetV1Store } from "@/store";
+import { projectNamePrefix } from "@/store/modules/v1/common";
+import type { IssueType } from "@/types";
+import { emptyIssue, TaskTypeListWithStatement } from "@/types";
import { IssueStatus, Issue_Type } from "@/types/proto/v1/issue_service";
-import {
- Plan,
- Plan_ChangeDatabaseConfig,
- Plan_ChangeDatabaseConfig_Type,
- Plan_ExportDataConfig,
- Plan_Spec,
- Plan_Step,
-} from "@/types/proto/v1/plan_service";
+import { Plan } from "@/types/proto/v1/plan_service";
import type { Stage } from "@/types/proto/v1/rollout_service";
import { Rollout, Task_Type } from "@/types/proto/v1/rollout_service";
import {
extractProjectResourceName,
extractSheetUID,
- generateSQLForChangeToDatabase,
getSheetStatement,
hasProjectPermissionV2,
- setSheetStatement,
sheetNameOfTaskV1,
} from "@/utils";
import { nextUID } from "../base";
-import { databaseEngineForSpec, sheetNameForSpec } from "../plan";
-
-export type InitialSQL = {
- sqlMap?: Record<string, string>;
- sql?: string;
-};
-
-type CreateIssueParams = {
- project: ComposedProject;
- query: Record<string, string>;
- initialSQL: InitialSQL;
-};
export const createIssueSkeleton = async (
route: ReturnType<typeof useRoute>,
@@ -69,7 +32,7 @@ export const createIssueSkeleton = async (
const project = await useProjectV1Store().getOrFetchProjectByName(
`${projectNamePrefix}${projectName}`
);
- const params: CreateIssueParams = {
+ const params: CreatePlanParams = {
project,
query,
initialSQL: await extractInitialSQLFromQuery(query),
@@ -93,7 +56,7 @@ export const createIssueSkeleton = async (
return issue;
};
-const buildIssue = async (params: CreateIssueParams) => {
+const buildIssue = async (params: CreatePlanParams) => {
const { project, query } = params;
const issue = emptyIssue();
const me = useCurrentUserV1();
@@ -116,247 +79,9 @@ const buildIssue = async (params: CreateIssueParams) => {
return issue;
};
-export const buildPlan = async (params: CreateIssueParams) => {
- const { project, query } = params;
- const databaseNameList = (query.databaseList ?? "").split(",");
- const plan = Plan.fromPartial({
- name: `${project.name}/plans/${nextUID()}`,
- });
- if (query.changelist) {
- // build plan for changelist
- plan.steps = await buildStepsViaChangelist(
- databaseNameList,
- query.changelist,
- params
- );
- } else if (query.databaseGroupName) {
- plan.steps = await buildStepsForDatabaseGroup(
- params,
- query.databaseGroupName
- );
- } else {
- // build standard plan
- // Use dedicated sheets if sqlMap is specified.
- // Share ONE sheet if otherwise.
- const sheetUID = hasInitialSQL(params.initialSQL) ? undefined : nextUID();
- plan.steps = await buildSteps(databaseNameList, params, sheetUID);
- }
- return plan;
-};
-
-export const buildSteps = async (
- databaseNameList: string[],
- params: CreateIssueParams,
- sheetUID?: string // if specified, all tasks will share the same sheet
-) => {
- await batchGetOrFetchDatabases(databaseNameList);
- const databaseStore = useDatabaseV1Store();
- const databaseList = databaseNameList.map((name) =>
- databaseStore.getDatabaseByName(name)
- );
-
- const databaseListGroupByEnvironment = groupBy(
- databaseList,
- (db) => db.effectiveEnvironment
- );
- const stageList = orderBy(
- Object.keys(databaseListGroupByEnvironment).map((env) => {
- const environment = useEnvironmentV1Store().getEnvironmentByName(env);
- const databases = databaseListGroupByEnvironment[env];
- return {
- environment,
- databases,
- };
- }),
- [(stage) => stage.environment?.order],
- ["asc"]
- );
-
- const steps: Plan_Step[] = [];
- for (let i = 0; i < stageList.length; i++) {
- const step = Plan_Step.fromJSON({});
- const { databases } = stageList[i];
- for (let j = 0; j < databases.length; j++) {
- const db = databases[j];
- const spec = await buildSpecForTarget(db.name, params, sheetUID);
- step.specs.push(spec);
- maybeSetInitialSQLForSpec(spec, db.name, params);
- }
- steps.push(step);
- }
- return steps;
-};
-
-export const buildStepsForDatabaseGroup = async (
- params: CreateIssueParams,
- databaseGroupName: string
-) => {
- // Create a local sheet for editing during preview
- // apply sql from URL if needed
- const sql = params.initialSQL.sql ?? "";
- const sheetUID = nextUID();
- const sheetName = `${params.project.name}/sheets/${sheetUID}`;
- const sheet = getLocalSheetByName(sheetName);
- sheet.engine = await databaseEngineForSpec(databaseGroupName);
- setSheetStatement(sheet, sql);
-
- const spec = await buildSpecForTarget(
- databaseGroupName,
- params,
- extractSheetUID(sheet.name)
- );
- const step = Plan_Step.fromJSON({
- specs: [spec],
- });
- return [step];
-};
-
-export const buildStepsViaChangelist = async (
- databaseNameList: string[],
- changelistResourceName: string,
- params: CreateIssueParams
-) => {
- const changelist = await useChangelistStore().getOrFetchChangelistByName(
- changelistResourceName
- );
- const { changes } = changelist;
-
- await batchGetOrFetchDatabases(databaseNameList);
- const databaseStore = useDatabaseV1Store();
- const databaseList = databaseNameList.map((name) =>
- databaseStore.getDatabaseByName(name)
- );
-
- const databaseListGroupByEnvironment = groupBy(
- databaseList,
- (db) => db.effectiveEnvironment
- );
- const stageList = orderBy(
- Object.keys(databaseListGroupByEnvironment).map((env) => {
- const environment = useEnvironmentV1Store().getEnvironmentByName(env);
- const databases = databaseListGroupByEnvironment[env];
- return {
- environment,
- databases,
- };
- }),
- [(stage) => stage.environment?.order],
- ["asc"]
- );
-
- const steps: Plan_Step[] = [];
- for (let i = 0; i < stageList.length; i++) {
- const step = Plan_Step.fromJSON({});
- const { databases } = stageList[i];
- for (let j = 0; j < databases.length; j++) {
- const db = databases[j];
- for (let k = 0; k < changes.length; k++) {
- const change = changes[k];
- const statement = await generateSQLForChangeToDatabase(change, db);
- const sheetUID = nextUID();
- const sheetName = `${params.project.name}/sheets/${sheetUID}`;
- const sheet = getLocalSheetByName(sheetName);
- setSheetStatement(sheet, statement);
- const spec = await buildSpecForTarget(
- db.name,
- params,
- sheetUID,
- change.version
- );
- step.specs.push(spec);
- }
- }
- steps.push(step);
- }
-
- return steps;
-};
-
-export const buildSpecForTarget = async (
- target: string,
- { project, query }: CreateIssueParams,
- sheetUID?: string,
- version?: string
-) => {
- const sheet = `${project.name}/sheets/${sheetUID ?? nextUID()}`;
- const template = query.template as IssueType | undefined;
- const spec = Plan_Spec.fromJSON({
- id: uuidv4(),
- });
- if (template === "bb.issue.database.data.update") {
- spec.changeDatabaseConfig = Plan_ChangeDatabaseConfig.fromJSON({
- target,
- type: Plan_ChangeDatabaseConfig_Type.DATA,
- });
- if (query.sheetId) {
- const sheet = await useSheetV1Store().getOrFetchSheetByUID(
- query.sheetId,
- "FULL"
- );
- if (sheet) {
- spec.changeDatabaseConfig.sheet = sheet.name;
- }
- }
- if (!spec.changeDatabaseConfig.sheet) {
- spec.changeDatabaseConfig.sheet = sheet;
- }
- if (version) {
- spec.changeDatabaseConfig.schemaVersion = version;
- }
- const database =
- await useDatabaseV1Store().getOrFetchDatabaseByName(target);
- if (isValidDatabaseName(database.name)) {
- // Set default backup behavior for the database.
- if (project.autoEnableBackup) {
- spec.changeDatabaseConfig.preUpdateBackupDetail = {
- database: `${database.instance}/${databaseNamePrefix}${getArchiveDatabase(database.instanceResource.engine)}`,
- };
- }
- }
- }
- if (template === "bb.issue.database.schema.update") {
- const type = Plan_ChangeDatabaseConfig_Type.MIGRATE;
- spec.changeDatabaseConfig = Plan_ChangeDatabaseConfig.fromJSON({
- target,
- type,
- sheet,
- });
-
- if (query.sheetId) {
- const remoteSheet = await useSheetV1Store().getOrFetchSheetByUID(
- query.sheetId,
- "FULL"
- );
- if (remoteSheet) {
- // make a local copy for remote sheet for further editing
- console.debug(
- "copy remote sheet to local for further editing",
- remoteSheet
- );
- const localSheet = getLocalSheetByName(sheet);
- localSheet.payload = cloneDeep(remoteSheet.payload);
- const statement = getSheetStatement(remoteSheet);
- setSheetStatement(localSheet, statement);
- }
- }
-
- if (version) {
- spec.changeDatabaseConfig.schemaVersion = version;
- }
- }
- if (template === "bb.issue.database.data.export") {
- spec.exportDataConfig = Plan_ExportDataConfig.fromJSON({
- target,
- sheet,
- });
- }
-
- return spec;
-};
-
-export const generateRolloutFromPlan = async (
+const generateRolloutFromPlan = async (
plan: Plan,
- params: CreateIssueParams
+ params: CreatePlanParams
) => {
const project = await useProjectV1Store().getOrFetchProjectByName(
`projects/${extractProjectResourceName(plan.name)}`
@@ -381,39 +106,6 @@ export const generateRolloutFromPlan = async (
return reactive(rollout);
};
-const maybeSetInitialSQLForSpec = (
- spec: Plan_Spec,
- key: string,
- params: CreateIssueParams
-) => {
- const sheet = sheetNameForSpec(spec);
- if (!sheet) return;
- const uid = extractSheetUID(sheet);
- if (!uid.startsWith("-")) {
- // If the sheet is a remote sheet, ignore initial SQL in URL query
- return;
- }
- // Priority: sqlMap[key] -> sql -> nothing
- const sql = params.initialSQL.sqlMap?.[key] ?? params.initialSQL.sql ?? "";
- if (sql) {
- const sheetEntity = getLocalSheetByName(sheet);
- setSheetStatement(sheetEntity, sql);
- }
-};
-
-const hasInitialSQL = (initialSQL?: InitialSQL) => {
- if (!initialSQL) {
- return false;
- }
- if (typeof initialSQL.sql === "string") {
- return true;
- }
- if (typeof initialSQL.sqlMap === "object") {
- return true;
- }
- return false;
-};
-
export const isValidStage = (stage: Stage): boolean => {
for (const task of stage.tasks) {
if (task.type === Task_Type.DATABASE_SCHEMA_BASELINE) {
diff --git a/frontend/src/components/IssueV1/logic/initialize/index.ts b/frontend/src/components/IssueV1/logic/initialize/index.ts
index a6a13b1997..9a829cfefb 100644
--- a/frontend/src/components/IssueV1/logic/initialize/index.ts
+++ b/frontend/src/components/IssueV1/logic/initialize/index.ts
@@ -90,7 +90,7 @@ export function useInitializeIssue(
}
};
- const allowEditIssue = computed(() => {
+ const allowChange = computed(() => {
if (isCreating.value) {
return hasProjectPermissionV2(unref(project), "bb.issues.create");
}
@@ -107,7 +107,7 @@ export function useInitializeIssue(
return hasProjectPermissionV2(unref(project), "bb.issues.update");
});
- return { isCreating, issue, isInitializing, reInitialize, allowEditIssue };
+ return { isCreating, issue, isInitializing, reInitialize, allowChange };
}
export const convertRouterQuery = (query: LocationQuery) => {
diff --git a/frontend/src/components/IssueV1/logic/plan-check.ts b/frontend/src/components/IssueV1/logic/plan-check.ts
index 73b941d63a..7afab991e6 100644
--- a/frontend/src/components/IssueV1/logic/plan-check.ts
+++ b/frontend/src/components/IssueV1/logic/plan-check.ts
@@ -7,7 +7,12 @@ import {
} from "@/types/proto/v1/plan_service";
import type { Task } from "@/types/proto/v1/rollout_service";
import { Task_Status } from "@/types/proto/v1/rollout_service";
-import { sheetNameForSpec, specForTask, useIssueContext, projectOfIssue } from ".";
+import {
+ sheetNameForSpec,
+ specForTask,
+ useIssueContext,
+ projectOfIssue,
+} from ".";
export const planSpecHasPlanChecks = (spec: Plan_Spec) => {
if (spec.createDatabaseConfig) {
diff --git a/frontend/src/components/IssueV1/logic/rollout.ts b/frontend/src/components/IssueV1/logic/rollout.ts
index 2648b2775e..a328d55a7f 100644
--- a/frontend/src/components/IssueV1/logic/rollout.ts
+++ b/frontend/src/components/IssueV1/logic/rollout.ts
@@ -16,7 +16,7 @@ import { specForTask, projectOfIssue } from ".";
export const isGroupingChangeTaskV1 = (issue: ComposedIssue, task: Task) => {
const spec = specForTask(issue.planEntity, task);
if (!spec) {
- return false; // Not sure actually, but doesn't matter.
+ return false;
}
const databaseGroup = extractDatabaseGroupName(
spec.changeDatabaseConfig?.target ?? ""
diff --git a/frontend/src/components/IssueV1/logic/utils.ts b/frontend/src/components/IssueV1/logic/utils.ts
index ab3d5b627f..3375e7e11c 100644
--- a/frontend/src/components/IssueV1/logic/utils.ts
+++ b/frontend/src/components/IssueV1/logic/utils.ts
@@ -2,7 +2,6 @@ import { NButton } from "naive-ui";
import { h } from "vue";
import { t } from "@/plugins/i18n";
import {
- pushNotification,
useDatabaseV1Store,
useEnvironmentV1Store,
useInstanceResourceByName,
@@ -142,14 +141,6 @@ export const stageForTask = (issue: ComposedIssue, task: Task) => {
);
};
-export const notifyNotEditableLegacyIssue = () => {
- pushNotification({
- module: "bytebase",
- style: "CRITICAL",
- title: t("issue.not-editable-legacy-issue"),
- });
-};
-
export const chooseUpdateTarget = (
issue: ComposedIssue,
selectedTask: Task,
diff --git a/frontend/src/components/Plan/components/SpecListSection/SpecListSection.vue b/frontend/src/components/Plan/components/SpecListSection/SpecListSection.vue
index 6b1204ce0e..9df20ed326 100644
--- a/frontend/src/components/Plan/components/SpecListSection/SpecListSection.vue
+++ b/frontend/src/components/Plan/components/SpecListSection/SpecListSection.vue
@@ -66,7 +66,7 @@ import {
} from "@/store";
import { DEBOUNCE_SEARCH_DELAY } from "@/types";
import type { Advice_Status } from "@/types/proto/v1/sql_service";
-import { isDev } from "@/utils";
+import { flattenSpecList, isDev } from "@/utils";
import {
databaseForSpec,
isDatabaseChangeSpec,
@@ -106,7 +106,7 @@ const state = reactive<LocalState>({
const specBar = ref<HTMLDivElement>();
const specBarScrollState = useVerticalScrollState(specBar, MAX_LIST_HEIGHT);
-const specList = computed(() => plan.value.steps.flatMap((step) => step.specs));
+const specList = computed(() => flattenSpecList(plan.value));
const filteredSpecList = computed(() => {
return specList.value.filter((spec) => {
diff --git a/frontend/src/components/Plan/logic/initialize/create.ts b/frontend/src/components/Plan/logic/initialize/create.ts
index f7c495a616..53f6e63e40 100644
--- a/frontend/src/components/Plan/logic/initialize/create.ts
+++ b/frontend/src/components/Plan/logic/initialize/create.ts
@@ -1,13 +1,10 @@
-import { cloneDeep, groupBy, orderBy } from "lodash-es";
+import { cloneDeep } from "lodash-es";
import { v4 as uuidv4 } from "uuid";
import { useRoute } from "vue-router";
import {
useChangelistStore,
- useDatabaseV1Store,
- useEnvironmentV1Store,
useProjectV1Store,
useSheetV1Store,
- batchGetOrFetchDatabases,
} from "@/store";
import { projectNamePrefix } from "@/store/modules/v1/common";
import { composePlan } from "@/store/modules/v1/plan";
@@ -35,8 +32,7 @@ export type InitialSQL = {
sql?: string;
};
-type CreatePlanParams = {
- databaseNameList: string[];
+export type CreatePlanParams = {
project: ComposedProject;
query: Record<string, string>;
initialSQL: InitialSQL;
@@ -57,9 +53,7 @@ export const createPlanSkeleton = async (
const project = await useProjectV1Store().getOrFetchProjectByName(
`${projectNamePrefix}${projectName}`
);
- const databaseNameList = (query.databaseList ?? "").split(",");
const params: CreatePlanParams = {
- databaseNameList,
project,
query,
initialSQL: await extractInitialSQLFromQuery(query),
@@ -69,8 +63,8 @@ export const createPlanSkeleton = async (
};
export const buildPlan = async (params: CreatePlanParams) => {
- const { databaseNameList, project, query } = params;
-
+ const { project, query } = params;
+ const databaseNameList = (query.databaseList ?? "").split(",");
const plan = Plan.fromJSON({
name: `${project.name}/plans/${nextUID()}`,
title: query.name,
@@ -98,53 +92,23 @@ export const buildPlan = async (params: CreatePlanParams) => {
return await composePlan(plan);
};
-export const buildSteps = async (
+const buildSteps = async (
databaseNameList: string[],
params: CreatePlanParams,
sheetUID?: string // if specified, all specs will share the same sheet
) => {
- await batchGetOrFetchDatabases(databaseNameList);
- const databaseStore = useDatabaseV1Store();
- const databaseList = databaseNameList.map((name) =>
- databaseStore.getDatabaseByName(name)
- );
-
- const databaseListGroupByEnvironment = groupBy(
- databaseList,
- (db) => db.effectiveEnvironment
- );
- const stepList = orderBy(
- Object.keys(databaseListGroupByEnvironment).map((env) => {
- const environment = useEnvironmentV1Store().getEnvironmentByName(env);
- const databases = databaseListGroupByEnvironment[env];
- return {
- environment,
- databases,
- };
- }),
- [(step) => step.environment?.order],
- ["asc"]
- );
-
- const steps: Plan_Step[] = [];
- for (let i = 0; i < stepList.length; i++) {
- const { environment, databases } = stepList[i];
- const step = Plan_Step.fromJSON({
- // Use environment title as step title.
- title: environment?.title,
- });
- for (let j = 0; j < databases.length; j++) {
- const db = databases[j];
- const spec = await buildSpecForTarget(db.name, params, sheetUID);
- step.specs.push(spec);
- maybeSetInitialSQLForSpec(spec, db.name, params);
- }
- steps.push(step);
+ const step = Plan_Step.fromPartial({
+ specs: [],
+ });
+ for (const db of databaseNameList) {
+ const spec = await buildSpecForTarget(db, params, sheetUID);
+ step.specs.push(spec);
+ maybeSetInitialSQLForSpec(spec, db, params);
}
- return steps;
+ return [step];
};
-export const buildStepsForDatabaseGroup = async (
+const buildStepsForDatabaseGroup = async (
params: CreatePlanParams,
databaseGroupName: string
) => {
@@ -172,7 +136,7 @@ export const buildStepsForDatabaseGroup = async (
return [step];
};
-export const buildStepsViaChangelist = async (
+const buildStepsViaChangelist = async (
databaseNameList: string[],
changelistResourceName: string,
params: CreatePlanParams
@@ -181,59 +145,29 @@ export const buildStepsViaChangelist = async (
changelistResourceName
);
const { changes } = changelist;
-
- await batchGetOrFetchDatabases(databaseNameList);
- const databaseStore = useDatabaseV1Store();
- const databaseList = databaseNameList.map((name) =>
- databaseStore.getDatabaseByName(name)
- );
-
- const databaseListGroupByEnvironment = groupBy(
- databaseList,
- (db) => db.effectiveEnvironment
- );
- const stepList = orderBy(
- Object.keys(databaseListGroupByEnvironment).map((env) => {
- const environment = useEnvironmentV1Store().getEnvironmentByName(env);
- const databases = databaseListGroupByEnvironment[env];
- return {
- environment,
- databases,
- };
- }),
- [(step) => step.environment?.order],
- ["asc"]
- );
-
- const steps: Plan_Step[] = [];
- for (let i = 0; i < stepList.length; i++) {
- const step = Plan_Step.fromJSON({});
- const { databases } = stepList[i];
- for (let j = 0; j < databases.length; j++) {
- const db = databases[j];
- for (let k = 0; k < changes.length; k++) {
- const change = changes[k];
- const statement = await generateSQLForChangeToDatabase(change, db);
- const sheetUID = nextUID();
- const sheetName = `${params.project.name}/sheets/${sheetUID}`;
- const sheet = getLocalSheetByName(sheetName);
- setSheetStatement(sheet, statement);
- const spec = await buildSpecForTarget(
- db.name,
- params,
- sheetUID,
- change.version
- );
- step.specs.push(spec);
- }
+ const step = Plan_Step.fromPartial({
+ specs: [],
+ });
+ for (const db of databaseNameList) {
+ for (const change of changes) {
+ const statement = await generateSQLForChangeToDatabase(change);
+ const sheetUID = nextUID();
+ const sheetName = `${params.project.name}/sheets/${sheetUID}`;
+ const sheet = getLocalSheetByName(sheetName);
+ setSheetStatement(sheet, statement);
+ const spec = await buildSpecForTarget(
+ db,
+ params,
+ sheetUID,
+ change.version
+ );
+ step.specs.push(spec);
}
- steps.push(step);
}
-
- return steps;
+ return [step];
};
-export const buildSpecForTarget = async (
+const buildSpecForTarget = async (
target: string,
{ project, query }: CreatePlanParams,
sheetUID?: string,
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index bfcd23da15..b96f8a110c 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -916,7 +916,6 @@
"current-change-will-apply-to-all-tasks-in-batch-mode": "In batch mode, current change will be applied to all tasks.",
"current-change-will-apply-to-all-tasks": "Current change will be applied to all tasks."
},
- "not-editable-legacy-issue": "This issue is not editable because it was created in an old version of Bytebase",
"action-anyway": "{action} anyway",
"sql-check": {
"sql-checks": "SQL checks",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 3ccd32c15a..f66b345d26 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -916,7 +916,6 @@
"current-change-will-apply-to-all-tasks-in-batch-mode": "En el modo por lotes, el cambio actual se aplicará a todas las tareas.",
"current-change-will-apply-to-all-tasks": "El cambio actual se aplicará a todas las tareas."
},
- "not-editable-legacy-issue": "Este problema no es editable porque se creó en una versión anterior de Bytebase",
"action-anyway": "{action} de todos modos",
"sql-check": {
"sql-checks": "Comprobaciones SQL",
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 4ba7615309..7f0da4f188 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -916,7 +916,6 @@
"current-change-will-apply-to-all-tasks-in-batch-mode": "バッチ モードでは、現在の変更がすべてのタスクに適用されます。",
"current-change-will-apply-to-all-tasks": "現在の変更はすべてのタスクに適用されます。"
},
- "not-editable-legacy-issue": "このイシューは古いバージョンの Bytebase で作成されたため編集できません。",
"action-anyway": "まだ {action} が必要です",
"sql-check": {
"sql-checks": "SQLチェック項目",
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index f38592ca93..26bba1e498 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -916,7 +916,6 @@
"current-change-will-apply-to-all-tasks-in-batch-mode": "Trong chế độ hàng loạt, thay đổi hiện tại sẽ được áp dụng cho tất cả các tác vụ.",
"current-change-will-apply-to-all-tasks": "Thay đổi hiện tại sẽ được áp dụng cho tất cả các tác vụ."
},
- "not-editable-legacy-issue": "Vấn đề này không thể chỉnh sửa vì nó được tạo trong phiên bản cũ của Bytebase",
"action-anyway": "{action} bằng mọi cách",
"sql-check": {
"sql-checks": "Kiểm tra SQL",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 9cc22b6b0a..997bb1325e 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -916,7 +916,6 @@
"current-change-will-apply-to-all-tasks-in-batch-mode": "在批量模式下,当前更改将应用​​于所有任务。",
"current-change-will-apply-to-all-tasks": "当前更改将应用​​于所有任务。"
},
- "not-editable-legacy-issue": "这个工单不可编辑,因为它是在旧版本的 Bytebase 中创建的。",
"action-anyway": "仍要{action}",
"sql-check": {
"sql-checks": "SQL 检查项",
diff --git a/frontend/src/store/modules/v1/plan.ts b/frontend/src/store/modules/v1/plan.ts
index 9d7c621507..841277afdd 100644
--- a/frontend/src/store/modules/v1/plan.ts
+++ b/frontend/src/store/modules/v1/plan.ts
@@ -1,5 +1,5 @@
import dayjs from "dayjs";
-import { orderBy } from "lodash-es";
+import { orderBy, uniq } from "lodash-es";
import { defineStore } from "pinia";
import { planServiceClient } from "@/grpcweb";
import { EMPTY_ID, UNKNOWN_ID } from "@/types";
@@ -16,6 +16,7 @@ import {
hasProjectPermissionV2,
type SearchParams,
} from "@/utils";
+import { useUserStore } from "../user";
import { useProjectV1Store } from "./project";
export interface PlanFind {
@@ -107,6 +108,9 @@ export const usePlanStore = defineStore("plan", () => {
const composedPlans = await Promise.all(
resp.plans.map((plan) => composePlan(plan))
);
+ // Preprare creator for the plans.
+ const users = uniq(composedPlans.map((plan) => plan.creator));
+ await useUserStore().batchGetUsers(users);
return {
nextPageToken: resp.nextPageToken,
plans: composedPlans,
diff --git a/frontend/src/utils/v1/changelist.ts b/frontend/src/utils/v1/changelist.ts
index 334aa158a9..91987729c6 100644
--- a/frontend/src/utils/v1/changelist.ts
+++ b/frontend/src/utils/v1/changelist.ts
@@ -1,5 +1,5 @@
import { useSheetV1Store } from "@/store";
-import type { Changelist_Change_Source, ComposedDatabase } from "@/types";
+import type { Changelist_Change_Source } from "@/types";
import type { Changelist_Change as Change } from "@/types/proto/v1/changelist_service";
import { getSheetStatement } from "./sheet";
@@ -23,10 +23,7 @@ export const getChangelistChangeSourceType = (
}
};
-export const generateSQLForChangeToDatabase = async (
- change: Change,
- _database: ComposedDatabase
-) => {
+export const generateSQLForChangeToDatabase = async (change: Change) => {
const sheet = await useSheetV1Store().getOrFetchSheetByName(
change.sheet,
"FULL"
diff --git a/frontend/src/views/project/ProjectIssueDetail.vue b/frontend/src/views/project/ProjectIssueDetail.vue
index 538db14828..53dffda26d 100644
--- a/frontend/src/views/project/ProjectIssueDetail.vue
+++ b/frontend/src/views/project/ProjectIssueDetail.vue
@@ -65,7 +65,7 @@ const { project, ready: projectReady } = useProjectByName(
computed(() => `${projectNamePrefix}${props.projectId}`)
);
-const { isCreating, issue, isInitializing, reInitialize, allowEditIssue } =
+const { isCreating, issue, isInitializing, reInitialize, allowChange } =
useInitializeIssue(toRef(props, "issueSlug"), project);
const ready = computed(() => {
return !isInitializing.value && !!issue.value && projectReady.value;
@@ -84,7 +84,7 @@ provideIssueContext(
issue,
ready,
reInitialize,
- allowEditIssue,
+ allowChange,
...issueBaseContext,
},
true /* root */