mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
handle sparse, zerofill, unsigned, commant flags
This commit is contained in:
parent
691bb0af4f
commit
0debe66dd0
@ -181,6 +181,8 @@ export class SqlDumper implements AlterProcessor {
|
||||
this.put(' ^auto_increment');
|
||||
}
|
||||
|
||||
specialColumnOptions(column) {}
|
||||
|
||||
columnDefinition(column: ColumnInfo, { includeDefault = true, includeNullable = true, includeCollate = true } = {}) {
|
||||
if (column.computedExpression) {
|
||||
this.put('^as %s', column.computedExpression);
|
||||
@ -193,9 +195,7 @@ export class SqlDumper implements AlterProcessor {
|
||||
}
|
||||
|
||||
this.putRaw(' ');
|
||||
if (column.isSparse) {
|
||||
this.put(' ^sparse ');
|
||||
}
|
||||
this.specialColumnOptions(column);
|
||||
if (includeNullable) {
|
||||
this.put(column.notNull ? '^not ^null' : '^null');
|
||||
}
|
||||
|
@ -217,6 +217,24 @@ export function testEqualColumns(
|
||||
// opts.DiffLogger.Trace('Column {0}, {1}: different is_sparse: {2}; {3}', a, b, a.IsSparse, b.IsSparse);
|
||||
return false;
|
||||
}
|
||||
if ((a.isUnsigned || false) != (b.isUnsigned || false)) {
|
||||
console.debug(
|
||||
`Column ${a.pureName}.${a.columnName}, ${b.pureName}.${b.columnName}: different unsigned: ${a.isUnsigned}, ${b.isUnsigned}`
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if ((a.isZerofill || false) != (b.isZerofill || false)) {
|
||||
console.debug(
|
||||
`Column ${a.pureName}.${a.columnName}, ${b.pureName}.${b.columnName}: different zerofill: ${a.isZerofill}, ${b.isZerofill}`
|
||||
);
|
||||
return false;
|
||||
}
|
||||
if ((a.columnComment || '') != (b.columnComment || '')) {
|
||||
console.debug(
|
||||
`Column ${a.pureName}.${a.columnName}, ${b.pureName}.${b.columnName}: different comment: ${a.columnComment}, ${b.columnComment}`
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!testEqualTypes(a, b, opts)) {
|
||||
return false;
|
||||
|
2
packages/types/dbinfo.d.ts
vendored
2
packages/types/dbinfo.d.ts
vendored
@ -55,6 +55,8 @@ export interface ColumnInfo extends NamedObjectInfo {
|
||||
defaultValue?: string;
|
||||
defaultConstraint?: string;
|
||||
columnComment?: string;
|
||||
isUnsigned?: boolean;
|
||||
isZerofill?: boolean;
|
||||
}
|
||||
|
||||
export interface DatabaseObjectInfo extends NamedObjectInfo {
|
||||
|
@ -20,6 +20,7 @@
|
||||
export let setTableInfo;
|
||||
export let tableInfo;
|
||||
export let onAddNext;
|
||||
export let driver;
|
||||
</script>
|
||||
|
||||
<FormProvider initialValues={fillEditorColumnInfo(columnInfo || {}, tableInfo)}>
|
||||
@ -36,6 +37,18 @@
|
||||
<FormCheckboxField name="autoIncrement" label="Is Autoincrement" />
|
||||
<FormTextField name="defaultValue" label="Default value" />
|
||||
<FormTextField name="computedExpression" label="Computed expression" />
|
||||
{#if driver?.dialect?.columnProperties?.isUnsigned}
|
||||
<FormCheckboxField name="isUnsigned" label="Unsigned" />
|
||||
{/if}
|
||||
{#if driver?.dialect?.columnProperties?.isZerofill}
|
||||
<FormCheckboxField name="isZerofill" label="Zero fill" />
|
||||
{/if}
|
||||
{#if driver?.dialect?.columnProperties?.columnComment}
|
||||
<FormTextField name="columnComment" label="Comment" />
|
||||
{/if}
|
||||
{#if driver?.dialect?.columnProperties?.isSparse}
|
||||
<FormCheckboxField name="isSparse" label="Sparse" />
|
||||
{/if}
|
||||
|
||||
<svelte:fragment slot="footer">
|
||||
<FormSubmit
|
||||
|
@ -97,6 +97,7 @@
|
||||
showModal(ColumnEditorModal, {
|
||||
setTableInfo,
|
||||
tableInfo,
|
||||
driver,
|
||||
onAddNext: async () => {
|
||||
await tick();
|
||||
addColumn();
|
||||
@ -158,7 +159,7 @@
|
||||
title={`Columns (${columns?.length || 0})`}
|
||||
emptyMessage="No columns defined"
|
||||
clickable={writable()}
|
||||
on:clickrow={e => showModal(ColumnEditorModal, { columnInfo: e.detail, tableInfo, setTableInfo })}
|
||||
on:clickrow={e => showModal(ColumnEditorModal, { columnInfo: e.detail, tableInfo, setTableInfo, driver })}
|
||||
onAddNew={writable() ? addColumn : null}
|
||||
columns={[
|
||||
{
|
||||
@ -194,6 +195,18 @@
|
||||
sortable: true,
|
||||
slot: 2,
|
||||
},
|
||||
driver?.dialect?.columnProperties?.isUnsigned && {
|
||||
fieldName: 'isUnsigned',
|
||||
header: 'Unsigned',
|
||||
sortable: true,
|
||||
slot: 4,
|
||||
},
|
||||
driver?.dialect?.columnProperties?.isZerofill && {
|
||||
fieldName: 'isZerofill',
|
||||
header: 'Zero fill',
|
||||
sortable: true,
|
||||
slot: 5,
|
||||
},
|
||||
driver?.dialect?.columnProperties?.columnComment && {
|
||||
fieldName: 'columnComment',
|
||||
header: 'Comment',
|
||||
@ -219,6 +232,8 @@
|
||||
}}>Remove</Link
|
||||
></svelte:fragment
|
||||
>
|
||||
<svelte:fragment slot="4" let:row>{row?.isUnsigned ? 'YES' : 'NO'}</svelte:fragment>
|
||||
<svelte:fragment slot="5" let:row>{row?.isZerofill ? 'YES' : 'NO'}</svelte:fragment>
|
||||
<svelte:fragment slot="name" let:row><ColumnLabel {...row} forceIcon /></svelte:fragment>
|
||||
</ObjectListControl>
|
||||
|
||||
|
@ -129,6 +129,12 @@ class MsSqlDumper extends SqlDumper {
|
||||
}
|
||||
}
|
||||
|
||||
specialColumnOptions(column) {
|
||||
if (column.isSparse) {
|
||||
this.put('^sparse ');
|
||||
}
|
||||
}
|
||||
|
||||
renameConstraint(cnt, newname) {
|
||||
if (cnt.constraintType == 'index')
|
||||
this.putCmd("^execute sp_rename '%f.%i', '%s', 'INDEX'", cnt, cnt.constraintName, newname);
|
||||
|
@ -15,7 +15,9 @@ function getColumnInfo({
|
||||
numericScale,
|
||||
defaultValue,
|
||||
columnComment,
|
||||
columnType,
|
||||
}) {
|
||||
const columnTypeTokens = _.isString(columnType) ? columnType.split(' ').map(x => x.trim().toLowerCase()) : [];
|
||||
let fullDataType = dataType;
|
||||
if (charMaxLength && isTypeString(dataType)) fullDataType = `${dataType}(${charMaxLength})`;
|
||||
if (numericPrecision && numericScale && isTypeNumeric(dataType))
|
||||
@ -27,6 +29,8 @@ function getColumnInfo({
|
||||
columnComment,
|
||||
dataType: fullDataType,
|
||||
defaultValue,
|
||||
isUnsigned: columnTypeTokens.includes('unsigned'),
|
||||
isZerofill: columnTypeTokens.includes('zerofill'),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ select
|
||||
NUMERIC_SCALE as numericScale,
|
||||
COLUMN_DEFAULT as defaultValue,
|
||||
COLUMN_COMMENT as columnComment,
|
||||
COLUMN_TYPE as columnType,
|
||||
EXTRA as extra
|
||||
from INFORMATION_SCHEMA.COLUMNS
|
||||
where TABLE_SCHEMA = '#DATABASE#' and TABLE_NAME =OBJECT_ID_CONDITION
|
||||
|
@ -38,6 +38,22 @@ class Dumper extends SqlDumper {
|
||||
this.endCommand();
|
||||
}
|
||||
|
||||
specialColumnOptions(column) {
|
||||
if (column.isUnsigned) {
|
||||
this.put('^unsigned ');
|
||||
}
|
||||
if (column.isZerofill) {
|
||||
this.put('^zerofill ');
|
||||
}
|
||||
}
|
||||
|
||||
columnDefinition(col, options) {
|
||||
super.columnDefinition(col, options);
|
||||
if (col.columnComment) {
|
||||
this.put(' ^comment %v ', col.columnComment);
|
||||
}
|
||||
}
|
||||
|
||||
renameColumn(column, newcol) {
|
||||
this.changeColumn(
|
||||
column,
|
||||
|
@ -33,6 +33,8 @@ const dialect = {
|
||||
|
||||
columnProperties: {
|
||||
columnComment: true,
|
||||
isUnsigned: true,
|
||||
isZerofill: true,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -54,7 +54,6 @@ class Dumper extends SqlDumper {
|
||||
}
|
||||
|
||||
columnDefinition(col, options) {
|
||||
const { autoIncrement } = options || {};
|
||||
if (col.autoIncrement) {
|
||||
this.put('^serial');
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user