fix(export): honor database name setting in table SQL export
This commit is contained in:
1 parent
a55466f578
commit
87546f8e4f
6 files changed
+191
-6
No files matched your search
@@ -81,7 +81,7 @@ import { codeMirrorSqlDialect, connectionObjectTreeNodeSchema, connectionTableSq
|
||||
import { getTableMetadataCapabilities, type TableMetadataCapabilities } from "@/lib/table/tableMetadataCapabilities";
|
||||
import { findTableStatistics } from "@/lib/dataGrid/tableInfoOverview";
|
||||
import { constraintsForConstraintsTab } from "@/lib/table/constraintPresentation";
|
||||
import { buildTableSelectSql } from "@/lib/table/tableSelectSql";
|
||||
import { buildTableSelectSql, dropsSchemaQualifier } from "@/lib/table/tableSelectSql";
|
||||
import { PARTITION_TREE_INDENT_PX } from "@/lib/table/pgPartitionPresentation";
|
||||
import {
|
||||
buildDropObjectSql,
|
||||
@@ -2460,7 +2460,14 @@ async function exportTableData(row: ObjectBrowserRow, format: "csv" | "xlsx" | "
|
||||
tableName: row.name,
|
||||
filePath,
|
||||
format,
|
||||
...(format === "sql" ? { insertMode, insertDialect, splitMaxMb } : {}),
|
||||
...(format === "sql"
|
||||
? {
|
||||
insertMode,
|
||||
insertDialect,
|
||||
splitMaxMb,
|
||||
omitDatabaseQualifier: dropsSchemaQualifier(effectiveDatabaseType.value, settingsStore.editorSettings.generateSqlIncludeDatabaseName, props.catalog),
|
||||
}
|
||||
: {}),
|
||||
csvQuoteMode: settingsStore.editorSettings.csvQuoteMode,
|
||||
nullLiteral: csvNullLiteralForMode(settingsStore.editorSettings.csvNullMode),
|
||||
columns,
|
||||
|
||||
@@ -68,6 +68,7 @@ function exportSettings() {
|
||||
exportBatchSize: 128,
|
||||
exportRowLimit: 500,
|
||||
exportRowLimitEnabled: true,
|
||||
generateSqlIncludeDatabaseName: false,
|
||||
dataGridExtractorOptions: DEFAULT_DATA_GRID_EXTRACTOR_OPTIONS,
|
||||
},
|
||||
};
|
||||
@@ -607,6 +608,33 @@ describe("useSidebarTreeExportRuntime", () => {
|
||||
expect(apiMock.startTableExport).toHaveBeenCalledWith(expect.objectContaining({ tableName: "users", filePath: "users.csv" }), expect.any(Function));
|
||||
});
|
||||
|
||||
it("follows the include-database-name setting for SQL INSERT exports", async () => {
|
||||
const activeNode = shallowRef({ id: "table-1", type: "table", label: "events", connectionId: "conn-1", database: "warehouse", schema: "warehouse", children: [] } as TreeNode);
|
||||
const settingsStore = exportSettings();
|
||||
const connectionStore = {
|
||||
ensureConnected: vi.fn(),
|
||||
getConfig: vi.fn(() => ({ db_type: "mysql" })),
|
||||
connectionIdentifierQuote: vi.fn(() => "`"),
|
||||
treeNodes: [],
|
||||
selectedTreeNodeIds: [],
|
||||
};
|
||||
const runtime = useSidebarTreeExportRuntime({
|
||||
activeNode,
|
||||
connectionStore: connectionStore as never,
|
||||
settingsStore: settingsStore as never,
|
||||
acceptedSelectionIds: () => null,
|
||||
});
|
||||
|
||||
// 设置关闭(默认):INSERT 目标省略库名,恢复脚本不受目标库影响 (#10771)。
|
||||
await runtime.exportData("sql");
|
||||
expect(apiMock.startTableExport).toHaveBeenLastCalledWith(expect.objectContaining({ format: "sql", omitDatabaseQualifier: true }), expect.any(Function));
|
||||
|
||||
// 设置开启:保留限定名。
|
||||
settingsStore.editorSettings.generateSqlIncludeDatabaseName = true;
|
||||
await runtime.exportData("sql");
|
||||
expect(apiMock.startTableExport).toHaveBeenLastCalledWith(expect.objectContaining({ format: "sql", omitDatabaseQualifier: false }), expect.any(Function));
|
||||
});
|
||||
|
||||
it.each([
|
||||
["source", undefined],
|
||||
["standard", "standard"],
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useI18n } from "vue-i18n";
|
||||
import { useDataGridExtractor } from "@/composables/useDataGridExtractor";
|
||||
import { isTauriRuntime } from "@/lib/backend/tauriRuntime";
|
||||
import { saveTextFile, sanitizeExportBaseName, compactLocalTimestamp } from "@/lib/export/saveTextFile";
|
||||
import { dropsSchemaQualifier } from "@/lib/table/tableSelectSql";
|
||||
import * as api from "@/lib/backend/api";
|
||||
import { type CellSelectionMatrix, type CellSelectionRange, type SelectionData } from "@/lib/dataGrid/gridSelection";
|
||||
import { DEFAULT_DATA_GRID_EXTRACTOR_OPTIONS, type DataGridCopyExtractorId, type DataGridExtractRequest, type DataGridExtractorOptions } from "@/lib/dataGrid/dataGridCopyExtractor";
|
||||
@@ -1381,7 +1382,14 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
|
||||
tableName: meta.tableName,
|
||||
filePath: outputPath,
|
||||
format,
|
||||
...(format === "sql" && sqlExportOptions ? { insertMode: sqlExportOptions.insertMode, splitMaxMb: sqlExportOptions.splitMaxMb, selectedColumns: sqlExportOptions.selectedColumns } : {}),
|
||||
...(format === "sql" && sqlExportOptions
|
||||
? {
|
||||
insertMode: sqlExportOptions.insertMode,
|
||||
splitMaxMb: sqlExportOptions.splitMaxMb,
|
||||
selectedColumns: sqlExportOptions.selectedColumns,
|
||||
omitDatabaseQualifier: dropsSchemaQualifier(databaseType.value, options.includeDatabaseName?.value, meta.catalog),
|
||||
}
|
||||
: {}),
|
||||
csvQuoteMode: editorSettings.csvQuoteMode,
|
||||
nullLiteral: csvNullLiteralForMode(editorSettings.csvNullMode),
|
||||
columns: format === "sql" ? effectiveColumns(sourceColumns.value, columns.value).map((column, index) => column ?? columns.value[index]!) : columns.value,
|
||||
|
||||
@@ -16,6 +16,7 @@ import { joinExportedDdls } from "@/lib/export/ddlExport";
|
||||
import { translateBackendError } from "@/i18n/backend-errors";
|
||||
import { sidebarStructureExportTargets, sidebarTableDataExportTargets } from "@/lib/sidebar/sidebarExportRuntime";
|
||||
import { fetchTableDataForExport } from "@/lib/table/tableDataExport";
|
||||
import { dropsSchemaQualifier } from "@/lib/table/tableSelectSql";
|
||||
import XlsxHeaderDialog from "@/components/export/XlsxHeaderDialog.vue";
|
||||
import { buildXlsxHeaderOverrides, hasXlsxHeaderComments, type XlsxExportOptions, type XlsxHeaderMode } from "@/lib/export/xlsxHeader";
|
||||
import {
|
||||
@@ -504,7 +505,12 @@ export function useSidebarTreeExportRuntime(options: SidebarTreeExportRuntimeOpt
|
||||
tableName: target.tableName,
|
||||
filePath: outputPath,
|
||||
format,
|
||||
...(format === "sql" ? { insertDialect } : {}),
|
||||
...(format === "sql"
|
||||
? {
|
||||
insertDialect,
|
||||
omitDatabaseQualifier: dropsSchemaQualifier(target.databaseType, settingsStore.editorSettings.generateSqlIncludeDatabaseName, target.catalog),
|
||||
}
|
||||
: {}),
|
||||
csvQuoteMode: target.csvQuoteMode,
|
||||
nullLiteral: target.nullLiteral,
|
||||
columns: queryColumns,
|
||||
|
||||
@@ -5963,6 +5963,11 @@ export interface TableExportRequest {
|
||||
numericColumnRightAlign?: boolean;
|
||||
autoFilter?: boolean;
|
||||
splitMaxMb?: number;
|
||||
/**
|
||||
* SQL 导出时省略 INSERT 目标的库/模式限定(前端按「生成 SQL 时包含数据库名」设置 +
|
||||
* `dropsSchemaQualifier` 引擎规则解析;仅影响 INSERT 目标,读取 SQL 不变)。
|
||||
*/
|
||||
omitDatabaseQualifier?: boolean;
|
||||
}
|
||||
|
||||
export interface TableCsvExportOptions {
|
||||
|
||||
Reference in new issue
Block a user