mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-25 01:45:59 +00:00
db sync - alter table preview
This commit is contained in:
@@ -391,6 +391,8 @@ export function createAlterTablePlan(
|
|||||||
const plan = new AlterPlan(db, driver.dialect, opts);
|
const plan = new AlterPlan(db, driver.dialect, opts);
|
||||||
if (oldTable == null) {
|
if (oldTable == null) {
|
||||||
plan.createTable(newTable);
|
plan.createTable(newTable);
|
||||||
|
} else if (newTable == null) {
|
||||||
|
plan.dropTable(oldTable);
|
||||||
} else {
|
} else {
|
||||||
planAlterTable(plan, oldTable, newTable, opts);
|
planAlterTable(plan, oldTable, newTable, opts);
|
||||||
}
|
}
|
||||||
@@ -452,6 +454,10 @@ export function getAlterTableScript(
|
|||||||
db: DatabaseInfo,
|
db: DatabaseInfo,
|
||||||
driver: EngineDriver
|
driver: EngineDriver
|
||||||
) {
|
) {
|
||||||
|
if ((!oldTable && !newTable) || !driver) {
|
||||||
|
return { sql: '', recreates: [] };
|
||||||
|
}
|
||||||
|
|
||||||
const plan = createAlterTablePlan(oldTable, newTable, opts, db, driver);
|
const plan = createAlterTablePlan(oldTable, newTable, opts, db, driver);
|
||||||
const dmp = driver.createDumper();
|
const dmp = driver.createDumper();
|
||||||
if (!driver.dialect.disableExplicitTransaction) dmp.beginTransaction();
|
if (!driver.dialect.disableExplicitTransaction) dmp.beginTransaction();
|
||||||
|
|||||||
@@ -122,6 +122,7 @@
|
|||||||
tbody tr.clickable:hover {
|
tbody tr.clickable:hover {
|
||||||
background: var(--theme-bg-hover);
|
background: var(--theme-bg-hover);
|
||||||
}
|
}
|
||||||
|
|
||||||
thead td {
|
thead td {
|
||||||
border: 1px solid var(--theme-border);
|
border: 1px solid var(--theme-border);
|
||||||
background-color: var(--theme-bg-1);
|
background-color: var(--theme-bg-1);
|
||||||
|
|||||||
@@ -3,10 +3,11 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { findEngineDriver, generateDbPairingId, matchPairedObjects } from 'dbgate-tools';
|
import { findEngineDriver, generateDbPairingId, getAlterTableScript, matchPairedObjects } from 'dbgate-tools';
|
||||||
|
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { derived, writable } from 'svelte/store';
|
import { derived, writable } from 'svelte/store';
|
||||||
|
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';
|
||||||
@@ -14,6 +15,7 @@
|
|||||||
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';
|
||||||
|
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 { computeDiffRows } from '../utility/computeDiffRows';
|
||||||
@@ -46,6 +48,14 @@
|
|||||||
$: targetDbPaired = matchPairedObjects(sourceDb, targetDb, dbDiffOptions);
|
$: targetDbPaired = matchPairedObjects(sourceDb, targetDb, dbDiffOptions);
|
||||||
$: diffRows = computeDiffRows(sourceDb, targetDbPaired, dbDiffOptions, driver);
|
$: diffRows = computeDiffRows(sourceDb, targetDbPaired, dbDiffOptions, driver);
|
||||||
|
|
||||||
|
$: sqlPreview = getAlterTableScript(
|
||||||
|
diffRows[pairIndex]?.source,
|
||||||
|
diffRows[pairIndex]?.target,
|
||||||
|
dbDiffOptions,
|
||||||
|
targetDb,
|
||||||
|
driver
|
||||||
|
).sql;
|
||||||
|
|
||||||
const { editorState, editorValue, setEditorData } = useEditorData({
|
const { editorState, editorValue, setEditorData } = useEditorData({
|
||||||
tabid,
|
tabid,
|
||||||
// onInitialData: value => {
|
// onInitialData: value => {
|
||||||
@@ -123,7 +133,24 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<svelte:fragment slot="2" />
|
<svelte:fragment slot="2">
|
||||||
|
<TabControl
|
||||||
|
tabs={[
|
||||||
|
{
|
||||||
|
label: 'SQL script',
|
||||||
|
slot: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Columns',
|
||||||
|
slot: 2,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<svelte:fragment slot="1">
|
||||||
|
<SqlEditor readOnly value={sqlPreview} />
|
||||||
|
</svelte:fragment>
|
||||||
|
</TabControl>
|
||||||
|
</svelte:fragment>
|
||||||
</VerticalSplitter>
|
</VerticalSplitter>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user