mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-05-03 15:13:57 +00:00
clickhouse: sorting key editor support
This commit is contained in:
@@ -266,6 +266,10 @@ export function editorDeleteConstraint(table: TableInfo, constraint: ConstraintI
|
|||||||
res.primaryKey = null;
|
res.primaryKey = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (constraint.constraintType == 'sortingKey') {
|
||||||
|
res.sortingKey = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (constraint.constraintType == 'foreignKey') {
|
if (constraint.constraintType == 'foreignKey') {
|
||||||
res.foreignKeys = table.foreignKeys.filter(x => x.pairingId != constraint.pairingId);
|
res.foreignKeys = table.foreignKeys.filter(x => x.pairingId != constraint.pairingId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,14 @@ export function extendTableInfo(table: TableInfo): TableInfo {
|
|||||||
constraintType: 'primaryKey',
|
constraintType: 'primaryKey',
|
||||||
}
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
|
sortingKey: table.sortingKey
|
||||||
|
? {
|
||||||
|
...table.sortingKey,
|
||||||
|
pureName: table.pureName,
|
||||||
|
schemaName: table.schemaName,
|
||||||
|
constraintType: 'sortingKey',
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
foreignKeys: (table.foreignKeys || []).map(cnt => ({
|
foreignKeys: (table.foreignKeys || []).map(cnt => ({
|
||||||
...cnt,
|
...cnt,
|
||||||
pureName: table.pureName,
|
pureName: table.pureName,
|
||||||
|
|||||||
2
packages/types/dbinfo.d.ts
vendored
2
packages/types/dbinfo.d.ts
vendored
@@ -15,7 +15,7 @@ export interface ColumnReference {
|
|||||||
export interface ConstraintInfo extends NamedObjectInfo {
|
export interface ConstraintInfo extends NamedObjectInfo {
|
||||||
pairingId?: string;
|
pairingId?: string;
|
||||||
constraintName?: string;
|
constraintName?: string;
|
||||||
constraintType: 'primaryKey' | 'foreignKey' | 'index' | 'check' | 'unique';
|
constraintType: 'primaryKey' | 'foreignKey' | 'sortingKey' | 'index' | 'check' | 'unique';
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ColumnsConstraintInfo extends ConstraintInfo {
|
export interface ColumnsConstraintInfo extends ConstraintInfo {
|
||||||
|
|||||||
3
packages/types/dialect.d.ts
vendored
3
packages/types/dialect.d.ts
vendored
@@ -35,6 +35,9 @@ export interface SqlDialect {
|
|||||||
dropCheck?: boolean;
|
dropCheck?: boolean;
|
||||||
|
|
||||||
specificNullabilityImplementation?: boolean;
|
specificNullabilityImplementation?: boolean;
|
||||||
|
omitForeignKeys?: boolean;
|
||||||
|
omitUniqueConstraints?: boolean;
|
||||||
|
sortingKeys?: boolean;
|
||||||
|
|
||||||
// syntax for create column: ALTER TABLE table ADD COLUMN column
|
// syntax for create column: ALTER TABLE table ADD COLUMN column
|
||||||
createColumnWithColumnKeyword?: boolean;
|
createColumnWithColumnKeyword?: boolean;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
export let collection;
|
export let collection;
|
||||||
export let title;
|
export let title;
|
||||||
export let clickable;
|
export let clickable = false;
|
||||||
export let onRemove = null;
|
export let onRemove = null;
|
||||||
export let onAddNew = null;
|
export let onAddNew = null;
|
||||||
export let emptyMessage = null;
|
export let emptyMessage = null;
|
||||||
|
|||||||
@@ -5,12 +5,14 @@
|
|||||||
export let setTableInfo;
|
export let setTableInfo;
|
||||||
export let tableInfo;
|
export let tableInfo;
|
||||||
|
|
||||||
|
export let constraintLabel = 'primary key';
|
||||||
|
export let constraintType = 'primaryKey';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ColumnsConstraintEditorModal
|
<ColumnsConstraintEditorModal
|
||||||
{...$$restProps}
|
{...$$restProps}
|
||||||
constraintLabel="primary key"
|
{constraintLabel}
|
||||||
constraintType="primaryKey"
|
{constraintType}
|
||||||
{constraintInfo}
|
{constraintInfo}
|
||||||
{setTableInfo}
|
{setTableInfo}
|
||||||
{tableInfo}
|
{tableInfo}
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { editorDeleteConstraint } from 'dbgate-tools';
|
||||||
|
|
||||||
|
import _ from 'lodash';
|
||||||
|
import ConstraintLabel from '../elements/ConstraintLabel.svelte';
|
||||||
|
import Link from '../elements/Link.svelte';
|
||||||
|
|
||||||
|
import ObjectListControl from '../elements/ObjectListControl.svelte';
|
||||||
|
import { showModal } from '../modals/modalTools';
|
||||||
|
|
||||||
|
import PrimaryKeyEditorModal from './PrimaryKeyEditorModal.svelte';
|
||||||
|
|
||||||
|
export let tableInfo;
|
||||||
|
export let setTableInfo;
|
||||||
|
export let isWritable;
|
||||||
|
|
||||||
|
export let constraintLabel = 'primary key';
|
||||||
|
export let constraintType = 'primaryKey';
|
||||||
|
|
||||||
|
$: columns = tableInfo?.columns;
|
||||||
|
$: keyConstraint = tableInfo?.[constraintType];
|
||||||
|
|
||||||
|
function addKeyConstraint() {
|
||||||
|
showModal(PrimaryKeyEditorModal, {
|
||||||
|
setTableInfo,
|
||||||
|
tableInfo,
|
||||||
|
constraintLabel,
|
||||||
|
constraintType,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<ObjectListControl
|
||||||
|
collection={_.compact([keyConstraint])}
|
||||||
|
title={_.startCase(constraintLabel)}
|
||||||
|
emptyMessage={isWritable ? `No ${constraintLabel} defined` : null}
|
||||||
|
onAddNew={isWritable && !keyConstraint && columns?.length > 0 ? addKeyConstraint : null}
|
||||||
|
clickable
|
||||||
|
on:clickrow={e =>
|
||||||
|
showModal(PrimaryKeyEditorModal, {
|
||||||
|
constraintInfo: e.detail,
|
||||||
|
tableInfo,
|
||||||
|
setTableInfo,
|
||||||
|
constraintLabel,
|
||||||
|
constraintType,
|
||||||
|
})}
|
||||||
|
columns={[
|
||||||
|
{
|
||||||
|
fieldName: 'columns',
|
||||||
|
header: 'Columns',
|
||||||
|
slot: 0,
|
||||||
|
},
|
||||||
|
isWritable
|
||||||
|
? {
|
||||||
|
fieldName: 'actions',
|
||||||
|
sortable: true,
|
||||||
|
slot: 1,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<svelte:fragment slot="name" let:row><ConstraintLabel {...row} /></svelte:fragment>
|
||||||
|
<svelte:fragment slot="0" let:row>{row?.columns.map(x => x.columnName).join(', ')}</svelte:fragment>
|
||||||
|
<svelte:fragment slot="1" let:row
|
||||||
|
><Link
|
||||||
|
onClick={e => {
|
||||||
|
e.stopPropagation();
|
||||||
|
setTableInfo(tbl => editorDeleteConstraint(tbl, row));
|
||||||
|
}}>Remove</Link
|
||||||
|
></svelte:fragment
|
||||||
|
>
|
||||||
|
</ObjectListControl>
|
||||||
@@ -82,6 +82,7 @@
|
|||||||
import PrimaryKeyEditorModal from './PrimaryKeyEditorModal.svelte';
|
import PrimaryKeyEditorModal from './PrimaryKeyEditorModal.svelte';
|
||||||
import UniqueEditorModal from './UniqueEditorModal.svelte';
|
import UniqueEditorModal from './UniqueEditorModal.svelte';
|
||||||
import ObjectFieldsEditor from '../elements/ObjectFieldsEditor.svelte';
|
import ObjectFieldsEditor from '../elements/ObjectFieldsEditor.svelte';
|
||||||
|
import PrimaryKeyLikeListControl from './PrimaryKeyLikeListControl.svelte';
|
||||||
|
|
||||||
export const activator = createActivator('TableEditor', true);
|
export const activator = createActivator('TableEditor', true);
|
||||||
|
|
||||||
@@ -262,55 +263,16 @@
|
|||||||
<svelte:fragment slot="name" let:row><ColumnLabel {...row} forceIcon /></svelte:fragment>
|
<svelte:fragment slot="name" let:row><ColumnLabel {...row} forceIcon /></svelte:fragment>
|
||||||
</ObjectListControl>
|
</ObjectListControl>
|
||||||
|
|
||||||
<ObjectListControl
|
<PrimaryKeyLikeListControl {tableInfo} {setTableInfo} {isWritable} />
|
||||||
collection={_.compact([primaryKey])}
|
|
||||||
title="Primary key"
|
|
||||||
emptyMessage={isWritable ? 'No primary key defined' : null}
|
|
||||||
onAddNew={isWritable && !primaryKey && columns?.length > 0 ? addPrimaryKey : null}
|
|
||||||
clickable
|
|
||||||
on:clickrow={e => showModal(PrimaryKeyEditorModal, { constraintInfo: e.detail, tableInfo, setTableInfo })}
|
|
||||||
columns={[
|
|
||||||
{
|
|
||||||
fieldName: 'columns',
|
|
||||||
header: 'Columns',
|
|
||||||
slot: 0,
|
|
||||||
},
|
|
||||||
isWritable
|
|
||||||
? {
|
|
||||||
fieldName: 'actions',
|
|
||||||
sortable: true,
|
|
||||||
slot: 1,
|
|
||||||
}
|
|
||||||
: null,
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<svelte:fragment slot="name" let:row><ConstraintLabel {...row} /></svelte:fragment>
|
|
||||||
<svelte:fragment slot="0" let:row>{row?.columns.map(x => x.columnName).join(', ')}</svelte:fragment>
|
|
||||||
<svelte:fragment slot="1" let:row
|
|
||||||
><Link
|
|
||||||
onClick={e => {
|
|
||||||
e.stopPropagation();
|
|
||||||
setTableInfo(tbl => editorDeleteConstraint(tbl, row));
|
|
||||||
}}>Remove</Link
|
|
||||||
></svelte:fragment
|
|
||||||
>
|
|
||||||
</ObjectListControl>
|
|
||||||
|
|
||||||
{#if sortingKey}
|
{#if driver?.dialect?.sortingKeys}
|
||||||
<ObjectListControl
|
<PrimaryKeyLikeListControl
|
||||||
collection={[sortingKey]}
|
{tableInfo}
|
||||||
title="Sorting key"
|
{setTableInfo}
|
||||||
columns={[
|
{isWritable}
|
||||||
{
|
constraintLabel="sorting key"
|
||||||
fieldName: 'columns',
|
constraintType="sortingKey"
|
||||||
header: 'Columns',
|
/>
|
||||||
slot: 0,
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<svelte:fragment slot="name" let:row><ConstraintLabel {...row} /></svelte:fragment>
|
|
||||||
<svelte:fragment slot="0" let:row>{row?.columns.map(x => x.columnName).join(', ')}</svelte:fragment>
|
|
||||||
</ObjectListControl>
|
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<ObjectListControl
|
<ObjectListControl
|
||||||
@@ -353,6 +315,7 @@
|
|||||||
>
|
>
|
||||||
</ObjectListControl>
|
</ObjectListControl>
|
||||||
|
|
||||||
|
{#if !driver?.dialect?.omitUniqueConstraints}
|
||||||
<ObjectListControl
|
<ObjectListControl
|
||||||
collection={uniques}
|
collection={uniques}
|
||||||
onAddNew={isWritable && columns?.length > 0 ? addUnique : null}
|
onAddNew={isWritable && columns?.length > 0 ? addUnique : null}
|
||||||
@@ -386,7 +349,9 @@
|
|||||||
></svelte:fragment
|
></svelte:fragment
|
||||||
>
|
>
|
||||||
</ObjectListControl>
|
</ObjectListControl>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if !driver?.dialect?.omitForeignKeys}
|
||||||
<ForeignKeyObjectListControl
|
<ForeignKeyObjectListControl
|
||||||
collection={foreignKeys}
|
collection={foreignKeys}
|
||||||
onAddNew={isWritable && columns?.length > 0 ? addForeignKey : null}
|
onAddNew={isWritable && columns?.length > 0 ? addForeignKey : null}
|
||||||
@@ -397,6 +362,7 @@
|
|||||||
on:clickrow={e => showModal(ForeignKeyEditorModal, { constraintInfo: e.detail, tableInfo, setTableInfo, dbInfo })}
|
on:clickrow={e => showModal(ForeignKeyEditorModal, { constraintInfo: e.detail, tableInfo, setTableInfo, dbInfo })}
|
||||||
/>
|
/>
|
||||||
<ForeignKeyObjectListControl collection={dependencies} title="Dependencies" />
|
<ForeignKeyObjectListControl collection={dependencies} title="Dependencies" />
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
@@ -100,6 +100,9 @@ const dialect = {
|
|||||||
anonymousPrimaryKey: true,
|
anonymousPrimaryKey: true,
|
||||||
createColumnWithColumnKeyword: true,
|
createColumnWithColumnKeyword: true,
|
||||||
specificNullabilityImplementation: true,
|
specificNullabilityImplementation: true,
|
||||||
|
omitForeignKeys: true,
|
||||||
|
omitUniqueConstraints: true,
|
||||||
|
sortingKeys: true,
|
||||||
|
|
||||||
columnProperties: {
|
columnProperties: {
|
||||||
columnComment: true,
|
columnComment: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user