Skip to content

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

chore: add validate issue in prev editor (#6556)

boojack2dc11684fd26
diff --git a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
index 4b5ea38dc6..405861f2b6 100644
--- a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
@@ -565,7 +565,10 @@ const isUsingGhostMigration = async (databaseList: ComposedDatabase[]) => {
// Also works when single db selected.
const generateMultiDb = async () => {
- if (state.selectedDatabaseGroupName) {
+ if (
+ state.databaseSelectedTab === "DATABASE_GROUP" &&
+ state.selectedDatabaseGroupName
+ ) {
const databaseGroup = await dbGroupStore.getOrFetchDBGroupByName(
state.selectedDatabaseGroupName
);
@@ -698,7 +701,10 @@ const handleDatabaseGroupTabSelect = () => {
};
const generateTenant = async () => {
- if (state.selectedDatabaseGroupName) {
+ if (
+ state.databaseSelectedTab === "DATABASE_GROUP" &&
+ state.selectedDatabaseGroupName
+ ) {
const databaseGroup = await dbGroupStore.getOrFetchDBGroupByName(
state.selectedDatabaseGroupName
);
diff --git a/frontend/src/components/AlterSchemaPrepForm/DatabaseGroupPrevEditorModal.vue b/frontend/src/components/AlterSchemaPrepForm/DatabaseGroupPrevEditorModal.vue
index 172fbdd536..79b49a2fea 100644
--- a/frontend/src/components/AlterSchemaPrepForm/DatabaseGroupPrevEditorModal.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/DatabaseGroupPrevEditorModal.vue
@@ -75,8 +75,12 @@
import { computed, onMounted, PropType, reactive } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
-import { ComposedDatabaseGroup, ComposedSchemaGroup } from "@/types";
-import { useDBGroupStore, useNotificationStore } from "@/store";
+import {
+ ComposedDatabaseGroup,
+ ComposedSchemaGroup,
+ MigrationType,
+} from "@/types";
+import { useDBGroupStore, useNotificationStore, useIssueStore } from "@/store";
import ActionConfirmModal from "@/components/SchemaEditor/Modals/ActionConfirmModal.vue";
import { generateDatabaseGroupIssueRoute } from "@/utils/databaseGroup/issue";
@@ -106,6 +110,7 @@ const emit = defineEmits<{
const { t } = useI18n();
const router = useRouter();
+const issueStore = useIssueStore();
const dbGroupStore = useDBGroupStore();
const state = reactive<LocalState>({
editStatement: "",
@@ -143,7 +148,7 @@ const generateReferenceStatement = (schemaGroupList: ComposedSchemaGroup[]) => {
for (const schemaGroup of schemaGroupList) {
if (props.issueType === "bb.issue.database.schema.update") {
statementList.push(`-- Uncomment to batch change table group ${schemaGroup.tablePlaceholder}
--- ALTER TABLE ${schemaGroup.tablePlaceholder} ADD <<column>> <<datatype>>;`);
+-- ALTER TABLE ${schemaGroup.tablePlaceholder} ADD COLUMN <<column>> <<datatype>>;`);
} else {
statementList.push(`-- Uncomment to update data of table group ${schemaGroup.tablePlaceholder}
-- UPDATE ${schemaGroup.tablePlaceholder} SET <<column>> = <<value>> WHERE <<condition>>;`);
@@ -204,6 +209,34 @@ const handleUploadFile = (e: Event) => {
};
const handlePreviewIssue = async () => {
+ let migrationType: MigrationType = "MIGRATE";
+ if (props.issueType === "bb.issue.database.data.update") {
+ migrationType = "DATA";
+ }
+
+ try {
+ await issueStore.validateIssue({
+ name: "Validate only issue for grouping",
+ assigneeId: 1,
+ projectId: Number(props.databaseGroup.project.uid),
+ createContext: {
+ detailList: [
+ {
+ migrationType: migrationType,
+ databaseGroupName: props.databaseGroup.name,
+ statement: state.editStatement,
+ earliestAllowedTs: 0,
+ },
+ ],
+ },
+ payload: {},
+ type: props.issueType,
+ description: "",
+ });
+ } catch (error) {
+ return;
+ }
+
const issueRoute = generateDatabaseGroupIssueRoute(
props.issueType,
props.databaseGroup,
diff --git a/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue b/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
index fd32189037..c4f9a24ad7 100644
--- a/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
+++ b/frontend/src/components/DatabaseGroup/DatabaseGroupForm.vue
@@ -122,6 +122,7 @@ import {
} from "@/store/modules/v1/common";
import { projectNamePrefix } from "@/store/modules/v1/common";
import { ResourceIdField } from "../v2";
+import { head } from "lodash-es";
const props = defineProps<{
project: ComposedProject;
@@ -170,9 +171,18 @@ const resourceIdType = computed(() =>
);
onMounted(async () => {
- if (props.parentDatabaseGroup) {
- state.environmentId = props.parentDatabaseGroup.environment.uid;
- state.selectedDatabaseGroupId = props.parentDatabaseGroup.name;
+ if (isCreating.value && props.resourceType === "SCHEMA_GROUP") {
+ if (props.parentDatabaseGroup) {
+ state.environmentId = props.parentDatabaseGroup.environment.uid;
+ state.selectedDatabaseGroupId = props.parentDatabaseGroup.name;
+ } else {
+ const dbGroup = head(dbGroupStore.getAllDatabaseGroupList());
+ if (dbGroup) {
+ state.environmentId = dbGroup.environment.uid;
+ state.selectedDatabaseGroupId = dbGroup.name;
+ }
+ }
+ return;
}
const databaseGroup = props.databaseGroup;
diff --git a/frontend/src/store/modules/dbGroup.ts b/frontend/src/store/modules/dbGroup.ts
index 3971b8d48d..25eb43793b 100644
--- a/frontend/src/store/modules/dbGroup.ts
+++ b/frontend/src/store/modules/dbGroup.ts
@@ -154,6 +154,14 @@ export const useDBGroupStore = defineStore("db-group", () => {
throw new Error("Database group not found");
}
const updateMask: string[] = [];
+ if (
+ !isEqual(
+ rawDatabaseGroup.databasePlaceholder,
+ databaseGroup.databasePlaceholder
+ )
+ ) {
+ updateMask.push("database_placeholder");
+ }
if (!isEqual(rawDatabaseGroup.databaseExpr, databaseGroup.databaseExpr)) {
updateMask.push("database_expr");
}
@@ -242,6 +250,11 @@ export const useDBGroupStore = defineStore("db-group", () => {
throw new Error("Schema group not found");
}
const updateMask: string[] = [];
+ if (
+ !isEqual(rawSchemaGroup.tablePlaceholder, schemaGroup.tablePlaceholder)
+ ) {
+ updateMask.push("table_placeholder");
+ }
if (!isEqual(rawSchemaGroup.tableExpr, schemaGroup.tableExpr)) {
updateMask.push("table_expr");
}