mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-01 16:43:59 +00:00
columns diff
This commit is contained in:
@@ -19,7 +19,7 @@
|
|||||||
import SqlEditor from '../query/SqlEditor.svelte';
|
import SqlEditor from '../query/SqlEditor.svelte';
|
||||||
import useEditorData from '../query/useEditorData';
|
import useEditorData from '../query/useEditorData';
|
||||||
import { extensions } from '../stores';
|
import { extensions } from '../stores';
|
||||||
import { computeDiffRows } from '../utility/computeDiffRows';
|
import { computeDbDiffRows } from '../utility/computeDiffRows';
|
||||||
import { useConnectionInfo, useDatabaseInfo } from '../utility/metadataLoaders';
|
import { useConnectionInfo, useDatabaseInfo } from '../utility/metadataLoaders';
|
||||||
|
|
||||||
export let tabid;
|
export let tabid;
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
$: driver = findEngineDriver($connection, $extensions);
|
$: driver = findEngineDriver($connection, $extensions);
|
||||||
|
|
||||||
$: targetDbPaired = matchPairedObjects(sourceDb, targetDb, dbDiffOptions);
|
$: targetDbPaired = matchPairedObjects(sourceDb, targetDb, dbDiffOptions);
|
||||||
$: diffRows = computeDiffRows(sourceDb, targetDbPaired, dbDiffOptions, driver);
|
$: diffRows = computeDbDiffRows(sourceDb, targetDbPaired, dbDiffOptions, driver);
|
||||||
|
|
||||||
$: sqlPreview = getAlterTableScript(
|
$: sqlPreview = getAlterTableScript(
|
||||||
diffRows[pairIndex]?.source,
|
diffRows[pairIndex]?.source,
|
||||||
|
|||||||
@@ -1,21 +1,15 @@
|
|||||||
import { DbDiffOptions, testEqualTables } from 'dbgate-tools';
|
import { DbDiffOptions, testEqualColumns, testEqualTables } from 'dbgate-tools';
|
||||||
import { DatabaseInfo, EngineDriver } from 'dbgate-types';
|
import { DatabaseInfo, EngineDriver, TableInfo } from 'dbgate-types';
|
||||||
|
|
||||||
export function computeDiffRows(
|
export function computeDiffRowsCore(sourceList, targetList, testEqual) {
|
||||||
sourceDb: DatabaseInfo,
|
|
||||||
targetDb: DatabaseInfo,
|
|
||||||
opts: DbDiffOptions,
|
|
||||||
driver: EngineDriver
|
|
||||||
) {
|
|
||||||
if (!sourceDb || !targetDb || !driver) return [];
|
|
||||||
const res = [];
|
const res = [];
|
||||||
for (const obj of sourceDb.tables) {
|
for (const obj of sourceList) {
|
||||||
const paired = targetDb.tables.find(x => x.pairingId == obj.pairingId);
|
const paired = targetList.find(x => x.pairingId == obj.pairingId);
|
||||||
if (paired) {
|
if (paired) {
|
||||||
res.push({
|
res.push({
|
||||||
source: obj,
|
source: obj,
|
||||||
target: paired,
|
target: paired,
|
||||||
state: testEqualTables(obj, paired, opts, targetDb, driver) ? 'equal' : 'changed',
|
state: testEqual(obj, paired) ? 'equal' : 'changed',
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
res.push({
|
res.push({
|
||||||
@@ -24,8 +18,8 @@ export function computeDiffRows(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const obj of targetDb.tables) {
|
for (const obj of targetList) {
|
||||||
const paired = sourceDb.tables.find(x => x.pairingId == obj.pairingId);
|
const paired = sourceList.find(x => x.pairingId == obj.pairingId);
|
||||||
if (!paired) {
|
if (!paired) {
|
||||||
res.push({
|
res.push({
|
||||||
target: obj,
|
target: obj,
|
||||||
@@ -34,7 +28,19 @@ export function computeDiffRows(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.map(row => ({
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function computeDbDiffRows(
|
||||||
|
sourceDb: DatabaseInfo,
|
||||||
|
targetDb: DatabaseInfo,
|
||||||
|
opts: DbDiffOptions,
|
||||||
|
driver: EngineDriver
|
||||||
|
) {
|
||||||
|
if (!sourceDb || !targetDb || !driver) return [];
|
||||||
|
return computeDiffRowsCore(sourceDb.tables, targetDb.tables, (a, b) =>
|
||||||
|
testEqualTables(a, b, opts, targetDb, driver)
|
||||||
|
).map(row => ({
|
||||||
...row,
|
...row,
|
||||||
sourceSchemaName: row?.source?.schemaName,
|
sourceSchemaName: row?.source?.schemaName,
|
||||||
sourcePureName: row?.source?.pureName,
|
sourcePureName: row?.source?.pureName,
|
||||||
@@ -42,3 +48,23 @@ export function computeDiffRows(
|
|||||||
targetPureName: row?.target?.pureName,
|
targetPureName: row?.target?.pureName,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function computeTableDiffColumns(
|
||||||
|
sourceTable: TableInfo,
|
||||||
|
targetTable: TableInfo,
|
||||||
|
opts: DbDiffOptions,
|
||||||
|
driver: EngineDriver
|
||||||
|
) {
|
||||||
|
if (!sourceTable || !sourceTable || !driver) return [];
|
||||||
|
return computeDiffRowsCore(sourceTable.columns, targetTable.columns, (a, b) =>
|
||||||
|
testEqualColumns(a, b, true, true, opts)
|
||||||
|
).map(row => ({
|
||||||
|
...row,
|
||||||
|
sourceColumnName: row?.source?.columnName,
|
||||||
|
targetColumnName: row?.target?.columnName,
|
||||||
|
sourceDataType: row?.source?.dataType,
|
||||||
|
targetDataType: row?.target?.dataType,
|
||||||
|
sourceNotNull: row?.source?.notNull,
|
||||||
|
targetNotNull: row?.target?.notNull,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user