mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-29 09:48:32 +08:00
- 扩展数据同步目标端 schema 选择与元数据加载,覆盖 SQL Server、IRIS、DuckDB 等独立 schema 场景 - 修正同步链路中的目标表 schema 归一化与 query/apply 表名解析,避免落到错误模式 - 补充前后端回归测试与多语言文案,覆盖 schema 选择、别名识别和结果预览路径 Fixes #571
101 lines
2.8 KiB
TypeScript
101 lines
2.8 KiB
TypeScript
export type SourceDatasetMode = 'table' | 'query';
|
|
|
|
type SyncContent = 'data' | 'schema' | 'both';
|
|
type TargetTableStrategy = 'existing_only' | 'auto_create_if_missing' | 'smart';
|
|
|
|
type BuildDataSyncRequestParams = {
|
|
sourceConfig: any;
|
|
targetConfig: any;
|
|
sourceDatabase?: string;
|
|
targetDatabase?: string;
|
|
targetSchema?: string;
|
|
selectedTables: string[];
|
|
sourceDatasetMode: SourceDatasetMode;
|
|
sourceQuery: string;
|
|
syncContent: SyncContent;
|
|
syncMode: string;
|
|
autoAddColumns: boolean;
|
|
targetTableStrategy: TargetTableStrategy;
|
|
createIndexes: boolean;
|
|
mongoCollectionName: string;
|
|
jobId?: string;
|
|
tableOptions?: Record<string, any>;
|
|
};
|
|
|
|
type ValidateDataSyncSelectionParams = {
|
|
sourceDatasetMode: SourceDatasetMode;
|
|
selectedTables: string[];
|
|
sourceQuery: string;
|
|
syncContent: SyncContent;
|
|
};
|
|
|
|
export type DataSyncSelectionErrorKey =
|
|
| 'data_sync.validation.source_query_required'
|
|
| 'data_sync.validation.single_target_table_required'
|
|
| 'data_sync.validation.query_mode_data_only'
|
|
| 'data_sync.validation.select_at_least_one_table';
|
|
|
|
export const validateDataSyncSelection = ({
|
|
sourceDatasetMode,
|
|
selectedTables,
|
|
sourceQuery,
|
|
syncContent,
|
|
}: ValidateDataSyncSelectionParams): DataSyncSelectionErrorKey | null => {
|
|
if (sourceDatasetMode === 'query') {
|
|
if (!String(sourceQuery || '').trim()) {
|
|
return 'data_sync.validation.source_query_required';
|
|
}
|
|
if (selectedTables.length !== 1) {
|
|
return 'data_sync.validation.single_target_table_required';
|
|
}
|
|
if (syncContent !== 'data') {
|
|
return 'data_sync.validation.query_mode_data_only';
|
|
}
|
|
return null;
|
|
}
|
|
|
|
if (selectedTables.length === 0) {
|
|
return 'data_sync.validation.select_at_least_one_table';
|
|
}
|
|
return null;
|
|
};
|
|
|
|
export const buildDataSyncRequest = ({
|
|
sourceConfig,
|
|
targetConfig,
|
|
sourceDatabase,
|
|
targetDatabase,
|
|
targetSchema,
|
|
selectedTables,
|
|
sourceDatasetMode,
|
|
sourceQuery,
|
|
syncContent,
|
|
syncMode,
|
|
autoAddColumns,
|
|
targetTableStrategy,
|
|
createIndexes,
|
|
mongoCollectionName,
|
|
jobId,
|
|
tableOptions,
|
|
}: BuildDataSyncRequestParams) => {
|
|
const isQueryMode = sourceDatasetMode === 'query';
|
|
|
|
return {
|
|
sourceConfig,
|
|
targetConfig,
|
|
sourceDatabase: String(sourceDatabase || '').trim(),
|
|
targetDatabase: String(targetDatabase || '').trim(),
|
|
targetSchema: String(targetSchema || '').trim(),
|
|
tables: selectedTables,
|
|
sourceQuery: isQueryMode ? String(sourceQuery || '').trim() : undefined,
|
|
content: isQueryMode ? 'data' : syncContent,
|
|
mode: syncMode,
|
|
autoAddColumns: isQueryMode ? false : autoAddColumns,
|
|
targetTableStrategy: isQueryMode ? 'existing_only' : targetTableStrategy,
|
|
createIndexes: isQueryMode ? false : createIndexes,
|
|
mongoCollectionName: String(mongoCollectionName || '').trim(),
|
|
...(jobId ? { jobId } : {}),
|
|
...(tableOptions ? { tableOptions } : {}),
|
|
};
|
|
};
|