diff --git a/packages/api/src/shell/modifyJsonLinesReader.js b/packages/api/src/shell/modifyJsonLinesReader.js index d76ed8c8a..bb5c6b1ed 100644 --- a/packages/api/src/shell/modifyJsonLinesReader.js +++ b/packages/api/src/shell/modifyJsonLinesReader.js @@ -2,7 +2,7 @@ const fs = require('fs'); const _ = require('lodash'); const stream = require('stream'); const byline = require('byline'); -const { getLogger } = require('dbgate-tools'); +const { getLogger, processJsonDataUpdateCommands, removeTablePairingId } = require('dbgate-tools'); const logger = getLogger('modifyJsonLinesReader'); const stableStringify = require('json-stable-stringify'); @@ -11,6 +11,7 @@ class ParseStream extends stream.Transform { super({ objectMode: true }); this.limitRows = limitRows; this.changeSet = changeSet; + this.wasHeader = false; this.currentRowIndex = 0; if (mergeMode == 'merge') { if (mergedRows && mergeKey) { @@ -28,12 +29,28 @@ class ParseStream extends stream.Transform { _transform(chunk, encoding, done) { let obj = JSON.parse(chunk); if (obj.__isStreamHeader) { - this.push(obj); + if (this.changeSet && this.changeSet.structure) { + this.push({ + ...removeTablePairingId(this.changeSet.structure), + __isStreamHeader: true, + }); + } else { + this.push(obj); + } + this.wasHeader = true; done(); return; } if (this.changeSet) { + if (!this.wasHeader && this.changeSet.structure) { + this.push({ + ...removeTablePairingId(this.changeSet.structure), + __isStreamHeader: true, + }); + this.wasHeader = true; + } + if (!this.limitRows || this.currentRowIndex < this.limitRows) { if (this.changeSet.deletes.find(x => x.existingRowIndex == this.currentRowIndex)) { obj = null; @@ -48,6 +65,9 @@ class ParseStream extends stream.Transform { } if (obj) { + if (this.changeSet.dataUpdateCommands) { + obj = processJsonDataUpdateCommands(obj, this.changeSet.dataUpdateCommands); + } this.push(obj); } this.currentRowIndex += 1; diff --git a/packages/tools/src/diffTools.ts b/packages/tools/src/diffTools.ts index ecda30151..01081f663 100644 --- a/packages/tools/src/diffTools.ts +++ b/packages/tools/src/diffTools.ts @@ -72,6 +72,34 @@ export function generateTablePairingId(table: TableInfo): TableInfo { return table; } +export function removeTablePairingId(table: TableInfo): TableInfo { + if (!table) return table; + return { + ...table, + columns: table.columns?.map(col => ({ + ...col, + pairingId: undefined, + })), + foreignKeys: table.foreignKeys?.map(cnt => ({ + ...cnt, + pairingId: undefined, + })), + checks: table.checks?.map(cnt => ({ + ...cnt, + pairingId: undefined, + })), + indexes: table.indexes?.map(cnt => ({ + ...cnt, + pairingId: undefined, + })), + uniques: table.uniques?.map(cnt => ({ + ...cnt, + pairingId: undefined, + })), + pairingId: undefined, + }; +} + function generateObjectPairingId(obj) { if (obj.objectTypeField) return { @@ -346,7 +374,13 @@ function createPairs(oldList, newList, additionalCondition = null) { function planTablePreload(plan: AlterPlan, oldTable: TableInfo, newTable: TableInfo) { const key = newTable.preloadedRowsKey || newTable.primaryKey?.columns?.map(x => x.columnName); if (newTable.preloadedRows?.length > 0 && key?.length > 0) { - plan.fillPreloadedRows(newTable, oldTable?.preloadedRows, newTable.preloadedRows, key, newTable.preloadedRowsInsertOnly); + plan.fillPreloadedRows( + newTable, + oldTable?.preloadedRows, + newTable.preloadedRows, + key, + newTable.preloadedRowsInsertOnly + ); } } diff --git a/packages/web/src/datagrid/JslDataGrid.svelte b/packages/web/src/datagrid/JslDataGrid.svelte index bdc4ddbcb..b430151e8 100644 --- a/packages/web/src/datagrid/JslDataGrid.svelte +++ b/packages/web/src/datagrid/JslDataGrid.svelte @@ -18,11 +18,12 @@ export let dispatchChangeSet = null; export let allowChangeChangeSetStructure = false; + export let infoLoadCounter = 0; let loadedRows; let infoCounter = 0; - $: info = useApiCall('jsldata/get-info', { jslid, infoCounter }, {}); + $: info = useApiCall('jsldata/get-info', { jslid, infoCounter, infoLoadCounter }, {}); // $: columns = ($info && $info.columns) || []; const config = writable(createGridConfig()); diff --git a/packages/web/src/tabs/ArchiveFileTab.svelte b/packages/web/src/tabs/ArchiveFileTab.svelte index 0f6441919..7ce9a347d 100644 --- a/packages/web/src/tabs/ArchiveFileTab.svelte +++ b/packages/web/src/tabs/ArchiveFileTab.svelte @@ -42,6 +42,7 @@ export let jslid = undefined; export let tabid; + let infoLoadCounter = 0; const quickExportHandlerRef = createQuickExportHandlerRef(); @@ -73,7 +74,11 @@ file: archiveFile, changeSet: $changeSetStore.value, }); + const structureChanged = !!$changeSetStore.value?.structure; dispatchChangeSet({ type: 'reset', value: createChangeSet() }); + if (structureChanged) { + infoLoadCounter += 1; + } await tick(); runCommand('dataGrid.refresh'); } @@ -92,6 +97,7 @@ focusOnVisible {changeSetStore} {dispatchChangeSet} + {infoLoadCounter} />