mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-28 08:26:29 +00:00
fixed adding column
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { DatabaseInfo } from 'dbgate-types';
|
import { DatabaseInfo, TableInfo } from 'dbgate-types';
|
||||||
import _flatten from 'lodash/flatten';
|
import _flatten from 'lodash/flatten';
|
||||||
|
|
||||||
export function addTableDependencies(db: DatabaseInfo): DatabaseInfo {
|
export function addTableDependencies(db: DatabaseInfo): DatabaseInfo {
|
||||||
@@ -12,50 +12,54 @@ export function addTableDependencies(db: DatabaseInfo): DatabaseInfo {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function fillTableExtendedInfo(db: DatabaseInfo): DatabaseInfo {
|
export function extendTableInfo(table: TableInfo): TableInfo {
|
||||||
return {
|
return {
|
||||||
...db,
|
...table,
|
||||||
tables: (db.tables || []).map(obj => ({
|
|
||||||
...obj,
|
|
||||||
objectTypeField: 'tables',
|
objectTypeField: 'tables',
|
||||||
columns: (obj.columns || []).map(column => ({
|
columns: (table.columns || []).map(column => ({
|
||||||
pureName: obj.pureName,
|
pureName: table.pureName,
|
||||||
schemaName: obj.schemaName,
|
schemaName: table.schemaName,
|
||||||
...column,
|
...column,
|
||||||
})),
|
})),
|
||||||
primaryKey: obj.primaryKey
|
primaryKey: table.primaryKey
|
||||||
? {
|
? {
|
||||||
...obj.primaryKey,
|
...table.primaryKey,
|
||||||
pureName: obj.pureName,
|
pureName: table.pureName,
|
||||||
schemaName: obj.schemaName,
|
schemaName: table.schemaName,
|
||||||
constraintType: 'primaryKey',
|
constraintType: 'primaryKey',
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
foreignKeys: (obj.foreignKeys || []).map(cnt => ({
|
foreignKeys: (table.foreignKeys || []).map(cnt => ({
|
||||||
...cnt,
|
...cnt,
|
||||||
pureName: obj.pureName,
|
pureName: table.pureName,
|
||||||
schemaName: obj.schemaName,
|
schemaName: table.schemaName,
|
||||||
constraintType: 'foreignKey',
|
constraintType: 'foreignKey',
|
||||||
})),
|
})),
|
||||||
indexes: (obj.indexes || []).map(cnt => ({
|
indexes: (table.indexes || []).map(cnt => ({
|
||||||
...cnt,
|
...cnt,
|
||||||
pureName: obj.pureName,
|
pureName: table.pureName,
|
||||||
schemaName: obj.schemaName,
|
schemaName: table.schemaName,
|
||||||
constraintType: 'index',
|
constraintType: 'index',
|
||||||
})),
|
})),
|
||||||
checks: (obj.checks || []).map(cnt => ({
|
checks: (table.checks || []).map(cnt => ({
|
||||||
...cnt,
|
...cnt,
|
||||||
pureName: obj.pureName,
|
pureName: table.pureName,
|
||||||
schemaName: obj.schemaName,
|
schemaName: table.schemaName,
|
||||||
constraintType: 'check',
|
constraintType: 'check',
|
||||||
})),
|
})),
|
||||||
uniques: (obj.uniques || []).map(cnt => ({
|
uniques: (table.uniques || []).map(cnt => ({
|
||||||
...cnt,
|
...cnt,
|
||||||
pureName: obj.pureName,
|
pureName: table.pureName,
|
||||||
schemaName: obj.schemaName,
|
schemaName: table.schemaName,
|
||||||
constraintType: 'unique',
|
constraintType: 'unique',
|
||||||
})),
|
})),
|
||||||
})),
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function fillDatabaseExtendedInfo(db: DatabaseInfo): DatabaseInfo {
|
||||||
|
return {
|
||||||
|
...db,
|
||||||
|
tables: (db.tables || []).map(extendTableInfo),
|
||||||
collections: (db.collections || []).map(obj => ({
|
collections: (db.collections || []).map(obj => ({
|
||||||
...obj,
|
...obj,
|
||||||
objectTypeField: 'collections',
|
objectTypeField: 'collections',
|
||||||
@@ -84,5 +88,5 @@ function fillTableExtendedInfo(db: DatabaseInfo): DatabaseInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function extendDatabaseInfo(db: DatabaseInfo): DatabaseInfo {
|
export function extendDatabaseInfo(db: DatabaseInfo): DatabaseInfo {
|
||||||
return fillTableExtendedInfo(addTableDependencies(db));
|
return fillDatabaseExtendedInfo(addTableDependencies(db));
|
||||||
}
|
}
|
||||||
|
|||||||
2
packages/types/dbinfo.d.ts
vendored
2
packages/types/dbinfo.d.ts
vendored
@@ -62,12 +62,12 @@ export interface DatabaseObjectInfo extends NamedObjectInfo {
|
|||||||
createDate?: string;
|
createDate?: string;
|
||||||
modifyDate?: string;
|
modifyDate?: string;
|
||||||
hashCode?: string;
|
hashCode?: string;
|
||||||
|
objectTypeField?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SqlObjectInfo extends DatabaseObjectInfo {
|
export interface SqlObjectInfo extends DatabaseObjectInfo {
|
||||||
createSql?: string;
|
createSql?: string;
|
||||||
requiresFormat?: boolean; // SQL is human unreadable, requires formatting (eg. MySQL views)
|
requiresFormat?: boolean; // SQL is human unreadable, requires formatting (eg. MySQL views)
|
||||||
objectTypeField?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TableInfo extends DatabaseObjectInfo {
|
export interface TableInfo extends DatabaseObjectInfo {
|
||||||
|
|||||||
@@ -28,7 +28,13 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { fillConstraintNames, findEngineDriver, generateTablePairingId, getAlterTableScript } from 'dbgate-tools';
|
import {
|
||||||
|
fillConstraintNames,
|
||||||
|
extendTableInfo,
|
||||||
|
findEngineDriver,
|
||||||
|
generateTablePairingId,
|
||||||
|
getAlterTableScript,
|
||||||
|
} from 'dbgate-tools';
|
||||||
|
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import registerCommand from '../commands/registerCommand';
|
import registerCommand from '../commands/registerCommand';
|
||||||
@@ -38,7 +44,6 @@
|
|||||||
import ForeignKeyObjectListControl from '../elements/ForeignKeyObjectListControl.svelte';
|
import ForeignKeyObjectListControl from '../elements/ForeignKeyObjectListControl.svelte';
|
||||||
|
|
||||||
import { extensions } from '../stores';
|
import { extensions } from '../stores';
|
||||||
import ObjectListControl from '../elements/ObjectListControl.svelte';
|
|
||||||
import useEditorData from '../query/useEditorData';
|
import useEditorData from '../query/useEditorData';
|
||||||
import TableEditor from '../tableeditor/TableEditor.svelte';
|
import TableEditor from '../tableeditor/TableEditor.svelte';
|
||||||
import createActivator, { getActiveComponent } from '../utility/createActivator';
|
import createActivator, { getActiveComponent } from '../utility/createActivator';
|
||||||
@@ -102,9 +107,10 @@
|
|||||||
|
|
||||||
function doSave(createTableName) {
|
function doSave(createTableName) {
|
||||||
const driver = findEngineDriver($connection, $extensions);
|
const driver = findEngineDriver($connection, $extensions);
|
||||||
|
|
||||||
const { sql, recreates } = getAlterTableScript(
|
const { sql, recreates } = getAlterTableScript(
|
||||||
$editorValue.base,
|
$editorValue.base,
|
||||||
fillConstraintNames($editorValue.current, driver.dialect),
|
extendTableInfo(fillConstraintNames($editorValue.current, driver.dialect)),
|
||||||
{},
|
{},
|
||||||
$dbInfo,
|
$dbInfo,
|
||||||
driver
|
driver
|
||||||
|
|||||||
Reference in New Issue
Block a user