Skip to content

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

chore: move issue sql from url to local storage (#13759)

boojack18900973b2fe
diff --git a/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue b/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue
index 6074a5693e..dafe2337d6 100644
--- a/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/SchemaEditorModal.vue
@@ -131,6 +131,7 @@
<script lang="ts" setup>
import { cloneDeep, head, uniq } from "lodash-es";
import { NTabs, NCheckbox, NButton, NTabPane, useDialog } from "naive-ui";
+import { v4 as uuidv4 } from "uuid";
import type { PropType } from "vue";
import { computed, onMounted, h, reactive, ref, watch } from "vue";
import { I18nT, useI18n } from "vue-i18n";
@@ -452,12 +453,14 @@ const handlePreviewIssue = async () => {
}
if (state.selectedTab === "raw-sql") {
- query.sql = state.editStatement;
-
query.name = generateIssueTitle(
"bb.issue.database.schema.update",
databaseList.value.map((db) => db.databaseName)
);
+
+ const sqlStorageKey = `bb.issues.sql.${uuidv4()}`;
+ localStorage.setItem(sqlStorageKey, state.editStatement);
+ query.sqlStorageKey = sqlStorageKey;
} else {
query.name = generateIssueTitle(
"bb.issue.database.schema.update",
@@ -494,7 +497,9 @@ const handlePreviewIssue = async () => {
const sql = statementList[i];
sqlMap[db.name] = sql;
});
- query.sqlMap = JSON.stringify(sqlMap);
+ const sqlMapStorageKey = `bb.issues.sql-map.${uuidv4()}`;
+ localStorage.setItem(sqlMapStorageKey, JSON.stringify(sqlMap));
+ query.sqlMapStorageKey = sqlMapStorageKey;
const databaseNameList = databaseList.value.map((db) => db.databaseName);
query.name = generateIssueTitle(
"bb.issue.database.schema.update",
diff --git a/frontend/src/components/Branch/BranchDetailView.vue b/frontend/src/components/Branch/BranchDetailView.vue
index f1c9c09578..96d039b955 100644
--- a/frontend/src/components/Branch/BranchDetailView.vue
+++ b/frontend/src/components/Branch/BranchDetailView.vue
@@ -120,6 +120,7 @@ import { asyncComputed, computedAsync } from "@vueuse/core";
import { cloneDeep } from "lodash-es";
import { NButton, NCheckbox, NDivider, useDialog } from "naive-ui";
import { Status } from "nice-grpc-common";
+import { v4 as uuidv4 } from "uuid";
import { computed, nextTick, reactive, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
@@ -450,14 +451,16 @@ const handleApplyToDatabase = async (databaseNameList: string[]) => {
const targetDatabaseList = databaseNameList.map((name) =>
databaseStore.getDatabaseByName(name)
);
+ const sqlStorageKey = `bb.issues.sql.${uuidv4()}`;
+ localStorage.setItem(sqlStorageKey, result.statement);
const query: Record<string, any> = {
template: "bb.issue.database.schema.update",
mode: "normal",
ghost: undefined,
branch: branch.name,
+ sqlStorageKey,
};
query.databaseList = targetDatabaseList.map((db) => db.name).join(",");
- query.sql = result.statement;
query.name = generateIssueTitle(
"bb.issue.database.schema.update",
targetDatabaseList.map((db) => db.databaseName)
diff --git a/frontend/src/components/IssueV1/components/Sidebar/GhostSection/common.ts b/frontend/src/components/IssueV1/components/Sidebar/GhostSection/common.ts
index 6e1c5e0271..2e4d1fe2a9 100644
--- a/frontend/src/components/IssueV1/components/Sidebar/GhostSection/common.ts
+++ b/frontend/src/components/IssueV1/components/Sidebar/GhostSection/common.ts
@@ -1,4 +1,5 @@
import { uniqBy } from "lodash-es";
+import { v4 as uuidv4 } from "uuid";
import type { InjectionKey, Ref } from "vue";
import { computed, inject, provide, ref } from "vue";
import { useI18n } from "vue-i18n";
@@ -130,7 +131,9 @@ export const provideIssueGhostContext = () => {
const sheet = getLocalSheetByName(sheetName);
sqlMap[target] = getSheetStatement(sheet);
});
- overrides["sqlMap"] = JSON.stringify(sqlMap);
+ const sqlMapStorageKey = `bb.issues.sql-map.${uuidv4()}`;
+ localStorage.setItem(sqlMapStorageKey, JSON.stringify(sqlMap));
+ overrides["sqlMapStorageKey"] = sqlMapStorageKey;
await reInitialize(overrides);
};
diff --git a/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/TaskRollbackButton.vue b/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/TaskRollbackButton.vue
index 8827c691d4..e8110b1c1a 100644
--- a/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/TaskRollbackButton.vue
+++ b/frontend/src/components/IssueV1/components/Sidebar/PreBackupSection/TaskRollbackButton.vue
@@ -10,12 +10,14 @@
<script lang="ts" setup>
import { Undo2Icon } from "lucide-vue-next";
import { NButton } from "naive-ui";
+import { v4 as uuidv4 } from "uuid";
import { computed, ref } from "vue";
import { useRouter } from "vue-router";
import {
latestTaskRunForTask,
useIssueContext,
} from "@/components/IssueV1/logic";
+import { rolloutServiceClient } from "@/grpcweb";
import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";
import { pushNotification, useSheetV1Store } from "@/store";
import {
@@ -24,7 +26,6 @@ import {
sheetNameOfTaskV1,
} from "@/utils";
import { usePreBackupContext } from "./common";
-import { rolloutServiceClient } from "@/grpcweb";
const router = useRouter();
const { issue, selectedTask } = useIssueContext();
@@ -61,12 +62,14 @@ const createRestoreIssue = async () => {
});
isLoading.value = false;
+ const sqlStorageKey = `bb.issues.sql.${uuidv4()}`;
+ localStorage.setItem(sqlStorageKey, statement);
const query: Record<string, any> = {
template: "bb.issue.database.data.update",
name: `Rollback ${selectedTask.value.title} in issue#${extractIssueUID(issue.value.name)}`,
databaseList: selectedTask.value.target,
- sql: statement,
description: `This issue is created to rollback the data of ${selectedTask.value.title} in issue #${extractIssueUID(issue.value.name)}`,
+ sqlStorageKey,
};
router.push({
name: PROJECT_V1_ROUTE_ISSUE_DETAIL,
diff --git a/frontend/src/components/IssueV1/logic/initialize/create.ts b/frontend/src/components/IssueV1/logic/initialize/create.ts
index 9355e2afa9..d6e9f07e42 100644
--- a/frontend/src/components/IssueV1/logic/initialize/create.ts
+++ b/frontend/src/components/IssueV1/logic/initialize/create.ts
@@ -466,20 +466,6 @@ const maybeSetInitialDatabaseConfigForSpec = async (
const extractInitialSQLFromQuery = (
query: Record<string, string>
): InitialSQL => {
- const sqlMapJSON = query.sqlMap;
- if (sqlMapJSON && sqlMapJSON.startsWith("{") && sqlMapJSON.endsWith("}")) {
- try {
- const sqlMap = JSON.parse(sqlMapJSON) as Record<string, string>;
- const keys = Object.keys(sqlMap);
- if (keys.every((key) => typeof sqlMap[key] === "string")) {
- return {
- sqlMap,
- };
- }
- } catch {
- // Nothing
- }
- }
const sql = query.sql;
if (sql && typeof sql === "string") {
return {
@@ -493,6 +479,21 @@ const extractInitialSQLFromQuery = (
sql,
};
}
+ const sqlMapStorageKey = query.sqlMapStorageKey;
+ if (sqlMapStorageKey && typeof sqlMapStorageKey === "string") {
+ const sqlMapJSON = localStorage.getItem(sqlMapStorageKey) ?? "{}";
+ try {
+ const sqlMap = JSON.parse(sqlMapJSON) as Record<string, string>;
+ const keys = Object.keys(sqlMap);
+ if (keys.every((key) => typeof sqlMap[key] === "string")) {
+ return {
+ sqlMap,
+ };
+ }
+ } catch {
+ // Nothing
+ }
+ }
return {};
};
diff --git a/frontend/src/components/Plan/logic/initialize/create.ts b/frontend/src/components/Plan/logic/initialize/create.ts
index 10d76d4d8b..3b13399147 100644
--- a/frontend/src/components/Plan/logic/initialize/create.ts
+++ b/frontend/src/components/Plan/logic/initialize/create.ts
@@ -372,8 +372,22 @@ const maybeSetInitialDatabaseConfigForSpec = async (
const extractInitialSQLFromQuery = (
query: Record<string, string>
): InitialSQL => {
- const sqlMapJSON = query.sqlMap;
- if (sqlMapJSON && sqlMapJSON.startsWith("{") && sqlMapJSON.endsWith("}")) {
+ const sql = query.sql;
+ if (sql && typeof sql === "string") {
+ return {
+ sql,
+ };
+ }
+ const sqlStorageKey = query.sqlStorageKey;
+ if (sqlStorageKey && typeof sqlStorageKey === "string") {
+ const sql = localStorage.getItem(sqlStorageKey) ?? "";
+ return {
+ sql,
+ };
+ }
+ const sqlMapStorageKey = query.sqlMapStorageKey;
+ if (sqlMapStorageKey && typeof sqlMapStorageKey === "string") {
+ const sqlMapJSON = localStorage.getItem(sqlMapStorageKey) ?? "{}";
try {
const sqlMap = JSON.parse(sqlMapJSON) as Record<string, string>;
const keys = Object.keys(sqlMap);
@@ -386,12 +400,6 @@ const extractInitialSQLFromQuery = (
// Nothing
}
}
- const sql = query.sql;
- if (sql && typeof sql === "string") {
- return {
- sql,
- };
- }
return {};
};
diff --git a/frontend/src/components/SlowQuery/Panel/IndexAdvisor.vue b/frontend/src/components/SlowQuery/Panel/IndexAdvisor.vue
index 6fa093d2d8..68619a6bd5 100644
--- a/frontend/src/components/SlowQuery/Panel/IndexAdvisor.vue
+++ b/frontend/src/components/SlowQuery/Panel/IndexAdvisor.vue
@@ -56,6 +56,7 @@
<script lang="ts" setup>
import { NButton } from "naive-ui";
import { Status } from "nice-grpc-common";
+import { v4 as uuidv4 } from "uuid";
import { computed, reactive, watch } from "vue";
import { useRouter } from "vue-router";
import { BBSpin } from "@/bbkit";
@@ -113,15 +114,17 @@ const showIndexAdvisor = computed(() => {
});
const handleCreateIndex = () => {
+ const sqlStorageKey = `bb.issues.sql.${uuidv4()}`;
+ localStorage.setItem(sqlStorageKey, state.createIndexStatement);
const query: Record<string, any> = {
template: "bb.issue.database.schema.update",
name: generateIssueTitle("bb.issue.database.schema.update", [
database.value.databaseName,
]),
databaseList: database.value.name,
- sql: state.createIndexStatement,
mode: "normal",
description: `Create index for database ${database.value.databaseName}`,
+ sqlStorageKey,
};
const routeInfo = {
diff --git a/frontend/src/components/SyncDatabaseSchema/index.vue b/frontend/src/components/SyncDatabaseSchema/index.vue
index e52f4fb85e..5a458c30df 100644
--- a/frontend/src/components/SyncDatabaseSchema/index.vue
+++ b/frontend/src/components/SyncDatabaseSchema/index.vue
@@ -65,6 +65,7 @@
import { isUndefined } from "lodash-es";
import type { ButtonProps } from "naive-ui";
import { NRadioGroup, NRadio, useDialog } from "naive-ui";
+import { v4 as uuidv4 } from "uuid";
import { computed, reactive, ref } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
@@ -238,7 +239,9 @@ const tryFinishSetup = async () => {
const diff = targetDatabaseViewRef.value!.databaseDiffCache[db.name];
sqlMap[db.name] = diff.edited;
});
- query.sqlMap = JSON.stringify(sqlMap);
+ const sqlMapStorageKey = `bb.issues.sql-map.${uuidv4()}`;
+ localStorage.setItem(sqlMapStorageKey, JSON.stringify(sqlMap));
+ query.sqlMapStorageKey = sqlMapStorageKey;
query.name = generateIssueTitle(
"bb.issue.database.schema.update",
targetDatabaseList.map((db) => db.databaseName)
diff --git a/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue b/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue
index b25812cbfd..b63960d43a 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue
@@ -60,6 +60,7 @@
<script lang="ts" setup>
import { computedAsync } from "@vueuse/core";
import { NAlert, NButton } from "naive-ui";
+import { v4 as uuidv4 } from "uuid";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
@@ -163,7 +164,8 @@ const gotoCreateIssue = () => {
emit("close");
const db = useDatabaseV1Store().getDatabaseByName(database);
-
+ const sqlStorageKey = `bb.issues.sql.${uuidv4()}`;
+ localStorage.setItem(sqlStorageKey, statement.value);
const route = router.resolve({
name: PROJECT_V1_ROUTE_ISSUE_DETAIL,
params: {
@@ -176,7 +178,7 @@ const gotoCreateIssue = () => {
isDDL.value ? "Edit schema" : "Change Data"
}`,
databaseList: db.name,
- sql: statement.value,
+ sqlStorageKey,
},
});
window.open(route.fullPath, "_blank");
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
index c317e30ea6..7c1bb1e1dd 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
@@ -445,7 +445,7 @@ const handleRequestExport = async () => {
const database = props.database;
const project = database.projectEntity;
const issueType = "bb.issue.database.data.export";
- const sqlStorageKey = `bb.sql-editor.export.${uuidv4()}`;
+ const sqlStorageKey = `bb.issues.sql.${uuidv4()}`;
localStorage.setItem(sqlStorageKey, props.result.statement);
const query: Record<string, any> = {
template: issueType,