mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
save structure changes to jsonl file
This commit is contained in:
parent
edf0637a35
commit
3114a05c3b
@ -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;
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
|
@ -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}
|
||||
/>
|
||||
<svelte:fragment slot="toolstrip">
|
||||
<ToolStripCommandButton command="dataGrid.refresh" />
|
||||
|
Loading…
Reference in New Issue
Block a user