mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 08:43:57 +00:00
db diff filter row
This commit is contained in:
@@ -36,30 +36,35 @@ export function computeDiffRowsCore(sourceList, targetList, testEqual) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
const COMPARE_DEFS = {
|
export const DbDiffCompareDefs = {
|
||||||
tables: {
|
tables: {
|
||||||
test: testEqualTables,
|
test: testEqualTables,
|
||||||
name: 'Table',
|
name: 'Table',
|
||||||
|
plural: 'Tables',
|
||||||
icon: 'img table',
|
icon: 'img table',
|
||||||
},
|
},
|
||||||
views: {
|
views: {
|
||||||
test: testEqualSqlObjects,
|
test: testEqualSqlObjects,
|
||||||
name: 'View',
|
name: 'View',
|
||||||
|
plural: 'Views',
|
||||||
icon: 'img view',
|
icon: 'img view',
|
||||||
},
|
},
|
||||||
matviews: {
|
matviews: {
|
||||||
test: testEqualSqlObjects,
|
test: testEqualSqlObjects,
|
||||||
name: 'Materialized view',
|
name: 'Materialized view',
|
||||||
|
plural: 'Materialized views',
|
||||||
icon: 'img view',
|
icon: 'img view',
|
||||||
},
|
},
|
||||||
procedures: {
|
procedures: {
|
||||||
test: testEqualSqlObjects,
|
test: testEqualSqlObjects,
|
||||||
name: 'Procedure',
|
name: 'Procedure',
|
||||||
|
plural: 'Procedures',
|
||||||
icon: 'img procedure',
|
icon: 'img procedure',
|
||||||
},
|
},
|
||||||
functions: {
|
functions: {
|
||||||
test: testEqualSqlObjects,
|
test: testEqualSqlObjects,
|
||||||
name: 'Function',
|
name: 'Function',
|
||||||
|
plural: 'Functions',
|
||||||
icon: 'img function',
|
icon: 'img function',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -74,7 +79,7 @@ export function computeDbDiffRows(
|
|||||||
|
|
||||||
const res = [];
|
const res = [];
|
||||||
for (const objectTypeField of ['tables', 'views', 'procedures', 'matviews', 'functions']) {
|
for (const objectTypeField of ['tables', 'views', 'procedures', 'matviews', 'functions']) {
|
||||||
const defs = COMPARE_DEFS[objectTypeField];
|
const defs = DbDiffCompareDefs[objectTypeField];
|
||||||
res.push(
|
res.push(
|
||||||
..._.sortBy(
|
..._.sortBy(
|
||||||
computeDiffRowsCore(sourceDb[objectTypeField], targetDb[objectTypeField], (a, b) =>
|
computeDiffRowsCore(sourceDb[objectTypeField], targetDb[objectTypeField], (a, b) =>
|
||||||
|
|||||||
28
packages/web/src/forms/RowsFilterSwitcher.svelte
Normal file
28
packages/web/src/forms/RowsFilterSwitcher.svelte
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import InlineButton from '../elements/InlineButton.svelte';
|
||||||
|
import FontIcon from '../icons/FontIcon.svelte';
|
||||||
|
|
||||||
|
export let icon;
|
||||||
|
export let label;
|
||||||
|
export let values;
|
||||||
|
export let field;
|
||||||
|
export let count;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#if count > 0}
|
||||||
|
<InlineButton
|
||||||
|
on:click={() => {
|
||||||
|
$values = { ...$values, [field]: !$values[field] };
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<FontIcon {icon} />
|
||||||
|
<span class="switch">{label} ({count})</span>
|
||||||
|
<FontIcon icon={$values && !$values[field] ? 'icon checkbox-marked' : 'icon checkbox-blank'} />
|
||||||
|
</InlineButton>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.switch {
|
||||||
|
margin-left: 5px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -64,6 +64,8 @@
|
|||||||
'icon preview': 'mdi mdi-file-find',
|
'icon preview': 'mdi mdi-file-find',
|
||||||
'icon eye': 'mdi mdi-eye',
|
'icon eye': 'mdi mdi-eye',
|
||||||
'icon check-all': 'mdi mdi-check-all',
|
'icon check-all': 'mdi mdi-check-all',
|
||||||
|
'icon checkbox-blank': 'mdi mdi-checkbox-blank-outline',
|
||||||
|
'icon checkbox-marked': 'mdi mdi-checkbox-marked-outline',
|
||||||
|
|
||||||
'icon run': 'mdi mdi-play',
|
'icon run': 'mdi mdi-play',
|
||||||
'icon chevron-down': 'mdi mdi-chevron-down',
|
'icon chevron-down': 'mdi mdi-chevron-down',
|
||||||
@@ -105,6 +107,11 @@
|
|||||||
'img yaml': 'mdi mdi-code-brackets color-icon-red',
|
'img yaml': 'mdi mdi-code-brackets color-icon-red',
|
||||||
'img compare': 'mdi mdi-compare color-icon-red',
|
'img compare': 'mdi mdi-compare color-icon-red',
|
||||||
|
|
||||||
|
'img add': 'mdi mdi-plus-circle color-icon-green',
|
||||||
|
'img minus': 'mdi mdi-minus-circle color-icon-red',
|
||||||
|
'img equal': 'mdi mdi-equal',
|
||||||
|
'img changed': 'mdi mdi-file-edit color-icon-yellow',
|
||||||
|
|
||||||
'img free-table': 'mdi mdi-table color-icon-green',
|
'img free-table': 'mdi mdi-table color-icon-green',
|
||||||
'img macro': 'mdi mdi-hammer-wrench',
|
'img macro': 'mdi mdi-hammer-wrench',
|
||||||
|
|
||||||
|
|||||||
@@ -79,6 +79,23 @@
|
|||||||
if (newObject) dmp.createSqlObject(newObject);
|
if (newObject) dmp.createSqlObject(newObject);
|
||||||
return { sql: dmp.s };
|
return { sql: dmp.s };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function filterDiffRows(rows, values, filter) {
|
||||||
|
let res = rows
|
||||||
|
.filter(row => filterName(filter, row.sourcePureName, row.targetPureName))
|
||||||
|
.filter(row => !values?.hideAdded || row.state != 'added')
|
||||||
|
.filter(row => !values?.hideRemoved || row.state != 'removed')
|
||||||
|
.filter(row => !values?.hideChanged || row.state != 'changed')
|
||||||
|
.filter(row => !values?.hideEqual || row.state != 'equal');
|
||||||
|
|
||||||
|
for (const objectTypeField of _.keys(DbDiffCompareDefs)) {
|
||||||
|
if (values && values[`hide_${objectTypeField}`]) {
|
||||||
|
res = res.filter(row => row.objectTypeField != objectTypeField);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
@@ -91,6 +108,8 @@
|
|||||||
computeTableDiffColumns,
|
computeTableDiffColumns,
|
||||||
getCreateObjectScript,
|
getCreateObjectScript,
|
||||||
modelCompareDbDiffOptions,
|
modelCompareDbDiffOptions,
|
||||||
|
filterName,
|
||||||
|
DbDiffCompareDefs,
|
||||||
} from 'dbgate-tools';
|
} from 'dbgate-tools';
|
||||||
|
|
||||||
import _, { startsWith } from 'lodash';
|
import _, { startsWith } from 'lodash';
|
||||||
@@ -99,12 +118,14 @@
|
|||||||
import DiffView from '../elements/DiffView.svelte';
|
import DiffView from '../elements/DiffView.svelte';
|
||||||
import InlineButton from '../elements/InlineButton.svelte';
|
import InlineButton from '../elements/InlineButton.svelte';
|
||||||
import ScrollableTableControl from '../elements/ScrollableTableControl.svelte';
|
import ScrollableTableControl from '../elements/ScrollableTableControl.svelte';
|
||||||
|
import SearchInput from '../elements/SearchInput.svelte';
|
||||||
import TabControl from '../elements/TabControl.svelte';
|
import TabControl from '../elements/TabControl.svelte';
|
||||||
import TableControl from '../elements/TableControl.svelte';
|
import TableControl from '../elements/TableControl.svelte';
|
||||||
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 FormSelectField from '../forms/FormSelectField.svelte';
|
||||||
|
import RowsFilterSwitcher from '../forms/RowsFilterSwitcher.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';
|
||||||
@@ -125,16 +146,10 @@
|
|||||||
export let tabid;
|
export let tabid;
|
||||||
|
|
||||||
let pairIndex = 0;
|
let pairIndex = 0;
|
||||||
|
let filter = '';
|
||||||
|
|
||||||
export const activator = createActivator('CompareModelTab', true);
|
export const activator = createActivator('CompareModelTab', true);
|
||||||
|
|
||||||
// let values = writable({
|
|
||||||
// sourceConid: null,
|
|
||||||
// sourceDatabase: null,
|
|
||||||
// targetConid: null,
|
|
||||||
// targetDatabase: null,
|
|
||||||
// });
|
|
||||||
|
|
||||||
$: dbDiffOptions = $values?.sourceConid == '__model' ? modelCompareDbDiffOptions : {};
|
$: dbDiffOptions = $values?.sourceConid == '__model' ? modelCompareDbDiffOptions : {};
|
||||||
|
|
||||||
$: sourceDbValue = useDatabaseInfo({ conid: $values?.sourceConid, database: $values?.sourceDatabase });
|
$: sourceDbValue = useDatabaseInfo({ conid: $values?.sourceConid, database: $values?.sourceDatabase });
|
||||||
@@ -147,7 +162,10 @@
|
|||||||
$: driver = findEngineDriver($connection, $extensions);
|
$: driver = findEngineDriver($connection, $extensions);
|
||||||
|
|
||||||
$: targetDbPaired = matchPairedObjects(sourceDb, targetDb, dbDiffOptions);
|
$: targetDbPaired = matchPairedObjects(sourceDb, targetDb, dbDiffOptions);
|
||||||
$: diffRows = _.sortBy(computeDbDiffRows(sourceDb, targetDbPaired, dbDiffOptions, driver), x => stateOrder(x.state));
|
$: diffRowsAll = _.sortBy(computeDbDiffRows(sourceDb, targetDbPaired, dbDiffOptions, driver), x =>
|
||||||
|
stateOrder(x.state)
|
||||||
|
);
|
||||||
|
$: diffRows = filterDiffRows(diffRowsAll, $values, filter);
|
||||||
$: diffColumns = computeTableDiffColumns(
|
$: diffColumns = computeTableDiffColumns(
|
||||||
diffRows[pairIndex]?.source,
|
diffRows[pairIndex]?.source,
|
||||||
diffRows[pairIndex]?.target,
|
diffRows[pairIndex]?.target,
|
||||||
@@ -339,6 +357,48 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="filters">
|
||||||
|
<SearchInput placeholder="Search tables or objects" bind:value={filter} />
|
||||||
|
|
||||||
|
<RowsFilterSwitcher
|
||||||
|
icon="img add"
|
||||||
|
label="Added"
|
||||||
|
{values}
|
||||||
|
field="hideAdded"
|
||||||
|
count={diffRowsAll.filter(x => x.state == 'added').length}
|
||||||
|
/>
|
||||||
|
<RowsFilterSwitcher
|
||||||
|
icon="img minus"
|
||||||
|
label="Removed"
|
||||||
|
{values}
|
||||||
|
field="hideRemoved"
|
||||||
|
count={diffRowsAll.filter(x => x.state == 'removed').length}
|
||||||
|
/>
|
||||||
|
<RowsFilterSwitcher
|
||||||
|
icon="img changed"
|
||||||
|
label="Changed"
|
||||||
|
{values}
|
||||||
|
field="hideChanged"
|
||||||
|
count={diffRowsAll.filter(x => x.state == 'changed').length}
|
||||||
|
/>
|
||||||
|
<RowsFilterSwitcher
|
||||||
|
icon="img equal"
|
||||||
|
label="Equal"
|
||||||
|
{values}
|
||||||
|
field="hideEqual"
|
||||||
|
count={diffRowsAll.filter(x => x.state == 'equal').length}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{#each _.keys(DbDiffCompareDefs) as objectTypeField}
|
||||||
|
<RowsFilterSwitcher
|
||||||
|
icon={DbDiffCompareDefs[objectTypeField].icon}
|
||||||
|
label={DbDiffCompareDefs[objectTypeField].plural}
|
||||||
|
{values}
|
||||||
|
field={'hide_' + objectTypeField}
|
||||||
|
count={diffRowsAll.filter(x => x.objectTypeField == objectTypeField).length}
|
||||||
|
/>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
</FormProviderCore>
|
</FormProviderCore>
|
||||||
|
|
||||||
<div class="tableWrapper">
|
<div class="tableWrapper">
|
||||||
@@ -468,4 +528,9 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.filters {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user