db diff with db model

This commit is contained in:
Jan Prochazka 2021-11-06 20:43:00 +01:00
parent 337ad2968f
commit a462a56a9d
5 changed files with 52 additions and 26 deletions

View File

@ -11,6 +11,7 @@ const {
generateDbPairingId,
matchPairedObjects,
extendDatabaseInfo,
modelCompareDbDiffOptions,
} = require('dbgate-tools');
const { html, parse } = require('diff2html');
const { handleProcessCommunication } = require('../utility/processComm');
@ -231,6 +232,11 @@ module.exports = {
structure_meta: 'get',
async structure({ conid, database }) {
if (conid == '__model') {
const model = await importDbModel(database);
return model;
}
const opened = await this.ensureOpened(conid, database);
return opened.structure;
// const existing = this.opened.find((x) => x.conid == conid && x.database == database);
@ -298,9 +304,7 @@ module.exports = {
// },
async getUnifiedDiff({ sourceConid, sourceDatabase, targetConid, targetDatabase }) {
const dbDiffOptions = {
// schemaMode: 'ignore',
};
const dbDiffOptions = sourceConid == '__model' ? modelCompareDbDiffOptions : {};
const sourceDb = generateDbPairingId(
extendDatabaseInfo(await this.structure({ conid: sourceConid, database: sourceDatabase }))

View File

@ -4,6 +4,7 @@ const {
matchPairedObjects,
databaseInfoFromYamlModel,
extendDatabaseInfo,
modelCompareDbDiffOptions,
} = require('dbgate-tools');
const importDbModel = require('../utility/importDbModel');
const requireEngineDriver = require('../utility/requireEngineDriver');
@ -28,9 +29,7 @@ async function generateDeploySql({
);
const currentModel = generateDbPairingId(extendDatabaseInfo(analysedStructure));
const opts = {
ignoreCase: true,
schemaMode: 'ignore',
ignoreConstraintNames: true,
...modelCompareDbDiffOptions,
noDropTable: true,
noDropColumn: true,

View File

@ -523,3 +523,9 @@ export function matchPairedObjects(db1: DatabaseInfo, db2: DatabaseInfo, opts: D
return res;
}
export const modelCompareDbDiffOptions: DbDiffOptions = {
ignoreCase: true,
schemaMode: 'ignore',
ignoreConstraintNames: true,
};

View File

@ -3,15 +3,19 @@
import FormSelectField from '../forms/FormSelectField.svelte';
import getConnectionLabel from '../utility/getConnectionLabel';
import { useConnectionList } from '../utility/metadataLoaders';
export let allowChooseModel = false;
$: connections = useConnectionList();
$: connectionOptions = _.sortBy(
($connections || []).map(conn => ({
value: conn._id,
label: getConnectionLabel(conn),
})),
'label'
);
$: connectionOptions = [
...(allowChooseModel ? [{ label: '(DB Model)', value: '__model' }] : []),
..._.sortBy(
($connections || []).map(conn => ({
value: conn._id,
label: getConnectionLabel(conn),
})),
'label'
),
];
</script>
<FormSelectField {...$$restProps} options={connectionOptions} />

View File

@ -76,6 +76,7 @@
computeDbDiffRows,
computeTableDiffColumns,
getCreateObjectScript,
modelCompareDbDiffOptions,
} from 'dbgate-tools';
import _, { startsWith } from 'lodash';
@ -89,6 +90,7 @@
import VerticalSplitter from '../elements/VerticalSplitter.svelte';
import FormFieldTemplateTiny from '../forms/FormFieldTemplateTiny.svelte';
import FormProviderCore from '../forms/FormProviderCore.svelte';
import FormSelectField from '../forms/FormSelectField.svelte';
import FontIcon from '../icons/FontIcon.svelte';
import FormConnectionSelect from '../impexp/FormConnectionSelect.svelte';
import FormDatabaseSelect from '../impexp/FormDatabaseSelect.svelte';
@ -102,7 +104,7 @@
import { changeTab } from '../utility/common';
import contextMenu, { getContextMenu, registerMenu } from '../utility/contextMenu';
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 { showSnackbarSuccess } from '../utility/snackbar';
@ -119,9 +121,7 @@
// targetDatabase: null,
// });
const dbDiffOptions: any = {
// schemaMode: 'ignore',
};
$: dbDiffOptions = $values?.sourceConid == '__model' ? modelCompareDbDiffOptions : {};
$: sourceDbValue = useDatabaseInfo({ conid: $values?.sourceConid, database: $values?.sourceDatabase });
$: targetDbValue = useDatabaseInfo({ conid: $values?.targetConid, database: $values?.targetDatabase });
@ -133,7 +133,7 @@
$: driver = findEngineDriver($connection, $extensions);
$: targetDbPaired = matchPairedObjects(sourceDb, targetDb, dbDiffOptions);
$: diffRows = computeDbDiffRows(sourceDb, targetDbPaired, dbDiffOptions, driver);
$: diffRows = _.sortBy(computeDbDiffRows(sourceDb, targetDbPaired, dbDiffOptions, driver), x => stateOrder(x.state));
$: diffColumns = computeTableDiffColumns(
diffRows[pairIndex]?.source,
diffRows[pairIndex]?.target,
@ -149,6 +149,8 @@
driver
).sql;
$: archiveFolders = useArchiveFolders();
$: changeTab(tabid, tab => ({
...tab,
title: $values?.targetDatabase,
@ -274,16 +276,27 @@
label="Source server"
templateProps={{ noMargin: true }}
isNative
allowChooseModel
/>
</div>
<div class="col-3">
<FormDatabaseSelect
conidName="sourceConid"
name="sourceDatabase"
label="Source database"
templateProps={{ noMargin: true }}
isNative
/>
{#if $values?.sourceConid == '__model'}
<FormSelectField
name="sourceDatabase"
label="Source DB model"
templateProps={{ noMargin: true }}
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 class="arrow">
<FontIcon icon="icon arrow-right-bold" />
@ -310,7 +323,7 @@
<div class="tableWrapper">
<ScrollableTableControl
rows={_.sortBy(diffRows, x => stateOrder(x.state))}
rows={diffRows}
bind:selectedIndex={pairIndex}
selectable
disableFocusOutline