mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-20 22:55:59 +00:00
db diff with db model
This commit is contained in:
@@ -11,6 +11,7 @@ const {
|
|||||||
generateDbPairingId,
|
generateDbPairingId,
|
||||||
matchPairedObjects,
|
matchPairedObjects,
|
||||||
extendDatabaseInfo,
|
extendDatabaseInfo,
|
||||||
|
modelCompareDbDiffOptions,
|
||||||
} = require('dbgate-tools');
|
} = require('dbgate-tools');
|
||||||
const { html, parse } = require('diff2html');
|
const { html, parse } = require('diff2html');
|
||||||
const { handleProcessCommunication } = require('../utility/processComm');
|
const { handleProcessCommunication } = require('../utility/processComm');
|
||||||
@@ -231,6 +232,11 @@ module.exports = {
|
|||||||
|
|
||||||
structure_meta: 'get',
|
structure_meta: 'get',
|
||||||
async structure({ conid, database }) {
|
async structure({ conid, database }) {
|
||||||
|
if (conid == '__model') {
|
||||||
|
const model = await importDbModel(database);
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
const opened = await this.ensureOpened(conid, database);
|
const opened = await this.ensureOpened(conid, database);
|
||||||
return opened.structure;
|
return opened.structure;
|
||||||
// const existing = this.opened.find((x) => x.conid == conid && x.database == database);
|
// const existing = this.opened.find((x) => x.conid == conid && x.database == database);
|
||||||
@@ -298,9 +304,7 @@ module.exports = {
|
|||||||
// },
|
// },
|
||||||
|
|
||||||
async getUnifiedDiff({ sourceConid, sourceDatabase, targetConid, targetDatabase }) {
|
async getUnifiedDiff({ sourceConid, sourceDatabase, targetConid, targetDatabase }) {
|
||||||
const dbDiffOptions = {
|
const dbDiffOptions = sourceConid == '__model' ? modelCompareDbDiffOptions : {};
|
||||||
// schemaMode: 'ignore',
|
|
||||||
};
|
|
||||||
|
|
||||||
const sourceDb = generateDbPairingId(
|
const sourceDb = generateDbPairingId(
|
||||||
extendDatabaseInfo(await this.structure({ conid: sourceConid, database: sourceDatabase }))
|
extendDatabaseInfo(await this.structure({ conid: sourceConid, database: sourceDatabase }))
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ const {
|
|||||||
matchPairedObjects,
|
matchPairedObjects,
|
||||||
databaseInfoFromYamlModel,
|
databaseInfoFromYamlModel,
|
||||||
extendDatabaseInfo,
|
extendDatabaseInfo,
|
||||||
|
modelCompareDbDiffOptions,
|
||||||
} = require('dbgate-tools');
|
} = require('dbgate-tools');
|
||||||
const importDbModel = require('../utility/importDbModel');
|
const importDbModel = require('../utility/importDbModel');
|
||||||
const requireEngineDriver = require('../utility/requireEngineDriver');
|
const requireEngineDriver = require('../utility/requireEngineDriver');
|
||||||
@@ -28,9 +29,7 @@ async function generateDeploySql({
|
|||||||
);
|
);
|
||||||
const currentModel = generateDbPairingId(extendDatabaseInfo(analysedStructure));
|
const currentModel = generateDbPairingId(extendDatabaseInfo(analysedStructure));
|
||||||
const opts = {
|
const opts = {
|
||||||
ignoreCase: true,
|
...modelCompareDbDiffOptions,
|
||||||
schemaMode: 'ignore',
|
|
||||||
ignoreConstraintNames: true,
|
|
||||||
|
|
||||||
noDropTable: true,
|
noDropTable: true,
|
||||||
noDropColumn: true,
|
noDropColumn: true,
|
||||||
|
|||||||
@@ -523,3 +523,9 @@ export function matchPairedObjects(db1: DatabaseInfo, db2: DatabaseInfo, opts: D
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const modelCompareDbDiffOptions: DbDiffOptions = {
|
||||||
|
ignoreCase: true,
|
||||||
|
schemaMode: 'ignore',
|
||||||
|
ignoreConstraintNames: true,
|
||||||
|
};
|
||||||
|
|||||||
@@ -3,15 +3,19 @@
|
|||||||
import FormSelectField from '../forms/FormSelectField.svelte';
|
import FormSelectField from '../forms/FormSelectField.svelte';
|
||||||
import getConnectionLabel from '../utility/getConnectionLabel';
|
import getConnectionLabel from '../utility/getConnectionLabel';
|
||||||
import { useConnectionList } from '../utility/metadataLoaders';
|
import { useConnectionList } from '../utility/metadataLoaders';
|
||||||
|
export let allowChooseModel = false;
|
||||||
|
|
||||||
$: connections = useConnectionList();
|
$: connections = useConnectionList();
|
||||||
$: connectionOptions = _.sortBy(
|
$: connectionOptions = [
|
||||||
($connections || []).map(conn => ({
|
...(allowChooseModel ? [{ label: '(DB Model)', value: '__model' }] : []),
|
||||||
value: conn._id,
|
..._.sortBy(
|
||||||
label: getConnectionLabel(conn),
|
($connections || []).map(conn => ({
|
||||||
})),
|
value: conn._id,
|
||||||
'label'
|
label: getConnectionLabel(conn),
|
||||||
);
|
})),
|
||||||
|
'label'
|
||||||
|
),
|
||||||
|
];
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<FormSelectField {...$$restProps} options={connectionOptions} />
|
<FormSelectField {...$$restProps} options={connectionOptions} />
|
||||||
|
|||||||
@@ -76,6 +76,7 @@
|
|||||||
computeDbDiffRows,
|
computeDbDiffRows,
|
||||||
computeTableDiffColumns,
|
computeTableDiffColumns,
|
||||||
getCreateObjectScript,
|
getCreateObjectScript,
|
||||||
|
modelCompareDbDiffOptions,
|
||||||
} from 'dbgate-tools';
|
} from 'dbgate-tools';
|
||||||
|
|
||||||
import _, { startsWith } from 'lodash';
|
import _, { startsWith } from 'lodash';
|
||||||
@@ -89,6 +90,7 @@
|
|||||||
import VerticalSplitter from '../elements/VerticalSplitter.svelte';
|
import VerticalSplitter from '../elements/VerticalSplitter.svelte';
|
||||||
import FormFieldTemplateTiny from '../forms/FormFieldTemplateTiny.svelte';
|
import FormFieldTemplateTiny from '../forms/FormFieldTemplateTiny.svelte';
|
||||||
import FormProviderCore from '../forms/FormProviderCore.svelte';
|
import FormProviderCore from '../forms/FormProviderCore.svelte';
|
||||||
|
import FormSelectField from '../forms/FormSelectField.svelte';
|
||||||
import FontIcon from '../icons/FontIcon.svelte';
|
import FontIcon from '../icons/FontIcon.svelte';
|
||||||
import FormConnectionSelect from '../impexp/FormConnectionSelect.svelte';
|
import FormConnectionSelect from '../impexp/FormConnectionSelect.svelte';
|
||||||
import FormDatabaseSelect from '../impexp/FormDatabaseSelect.svelte';
|
import FormDatabaseSelect from '../impexp/FormDatabaseSelect.svelte';
|
||||||
@@ -102,7 +104,7 @@
|
|||||||
import { changeTab } from '../utility/common';
|
import { changeTab } from '../utility/common';
|
||||||
import contextMenu, { getContextMenu, registerMenu } from '../utility/contextMenu';
|
import contextMenu, { getContextMenu, registerMenu } from '../utility/contextMenu';
|
||||||
import createActivator, { getActiveComponent } from '../utility/createActivator';
|
import createActivator, { getActiveComponent } from '../utility/createActivator';
|
||||||
import { useConnectionInfo, useDatabaseInfo } from '../utility/metadataLoaders';
|
import { useArchiveFolders, useConnectionInfo, useDatabaseInfo } from '../utility/metadataLoaders';
|
||||||
import resolveApi from '../utility/resolveApi';
|
import resolveApi from '../utility/resolveApi';
|
||||||
import { showSnackbarSuccess } from '../utility/snackbar';
|
import { showSnackbarSuccess } from '../utility/snackbar';
|
||||||
|
|
||||||
@@ -119,9 +121,7 @@
|
|||||||
// targetDatabase: null,
|
// targetDatabase: null,
|
||||||
// });
|
// });
|
||||||
|
|
||||||
const dbDiffOptions: any = {
|
$: dbDiffOptions = $values?.sourceConid == '__model' ? modelCompareDbDiffOptions : {};
|
||||||
// schemaMode: 'ignore',
|
|
||||||
};
|
|
||||||
|
|
||||||
$: sourceDbValue = useDatabaseInfo({ conid: $values?.sourceConid, database: $values?.sourceDatabase });
|
$: sourceDbValue = useDatabaseInfo({ conid: $values?.sourceConid, database: $values?.sourceDatabase });
|
||||||
$: targetDbValue = useDatabaseInfo({ conid: $values?.targetConid, database: $values?.targetDatabase });
|
$: targetDbValue = useDatabaseInfo({ conid: $values?.targetConid, database: $values?.targetDatabase });
|
||||||
@@ -133,7 +133,7 @@
|
|||||||
$: driver = findEngineDriver($connection, $extensions);
|
$: driver = findEngineDriver($connection, $extensions);
|
||||||
|
|
||||||
$: targetDbPaired = matchPairedObjects(sourceDb, targetDb, dbDiffOptions);
|
$: targetDbPaired = matchPairedObjects(sourceDb, targetDb, dbDiffOptions);
|
||||||
$: diffRows = computeDbDiffRows(sourceDb, targetDbPaired, dbDiffOptions, driver);
|
$: diffRows = _.sortBy(computeDbDiffRows(sourceDb, targetDbPaired, dbDiffOptions, driver), x => stateOrder(x.state));
|
||||||
$: diffColumns = computeTableDiffColumns(
|
$: diffColumns = computeTableDiffColumns(
|
||||||
diffRows[pairIndex]?.source,
|
diffRows[pairIndex]?.source,
|
||||||
diffRows[pairIndex]?.target,
|
diffRows[pairIndex]?.target,
|
||||||
@@ -149,6 +149,8 @@
|
|||||||
driver
|
driver
|
||||||
).sql;
|
).sql;
|
||||||
|
|
||||||
|
$: archiveFolders = useArchiveFolders();
|
||||||
|
|
||||||
$: changeTab(tabid, tab => ({
|
$: changeTab(tabid, tab => ({
|
||||||
...tab,
|
...tab,
|
||||||
title: $values?.targetDatabase,
|
title: $values?.targetDatabase,
|
||||||
@@ -274,16 +276,27 @@
|
|||||||
label="Source server"
|
label="Source server"
|
||||||
templateProps={{ noMargin: true }}
|
templateProps={{ noMargin: true }}
|
||||||
isNative
|
isNative
|
||||||
|
allowChooseModel
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-3">
|
<div class="col-3">
|
||||||
<FormDatabaseSelect
|
{#if $values?.sourceConid == '__model'}
|
||||||
conidName="sourceConid"
|
<FormSelectField
|
||||||
name="sourceDatabase"
|
name="sourceDatabase"
|
||||||
label="Source database"
|
label="Source DB model"
|
||||||
templateProps={{ noMargin: true }}
|
templateProps={{ noMargin: true }}
|
||||||
isNative
|
isNative
|
||||||
/>
|
options={($archiveFolders || []).map(x => ({ label: x.name, value: `archive:${x.name}` }))}
|
||||||
|
/>
|
||||||
|
{:else}
|
||||||
|
<FormDatabaseSelect
|
||||||
|
conidName="sourceConid"
|
||||||
|
name="sourceDatabase"
|
||||||
|
label="Source database"
|
||||||
|
templateProps={{ noMargin: true }}
|
||||||
|
isNative
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div class="arrow">
|
<div class="arrow">
|
||||||
<FontIcon icon="icon arrow-right-bold" />
|
<FontIcon icon="icon arrow-right-bold" />
|
||||||
@@ -310,7 +323,7 @@
|
|||||||
|
|
||||||
<div class="tableWrapper">
|
<div class="tableWrapper">
|
||||||
<ScrollableTableControl
|
<ScrollableTableControl
|
||||||
rows={_.sortBy(diffRows, x => stateOrder(x.state))}
|
rows={diffRows}
|
||||||
bind:selectedIndex={pairIndex}
|
bind:selectedIndex={pairIndex}
|
||||||
selectable
|
selectable
|
||||||
disableFocusOutline
|
disableFocusOutline
|
||||||
|
|||||||
Reference in New Issue
Block a user