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