From eaa5970a0f6b8a85ac7e2b7ee5f6f600d2daddfd Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Sun, 5 Sep 2021 11:18:44 +0200 Subject: [PATCH] drop column with default works --- .../__tests__/alter-processor.spec.js | 2 +- integration-tests/engines.js | 6 ++--- .../src/backend/MsSqlAnalyser.js | 24 +++++++++++-------- .../src/frontend/MsSqlDumper.js | 7 ++++++ 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/integration-tests/__tests__/alter-processor.spec.js b/integration-tests/__tests__/alter-processor.spec.js index 2aefc4af..77bd18cc 100644 --- a/integration-tests/__tests__/alter-processor.spec.js +++ b/integration-tests/__tests__/alter-processor.spec.js @@ -60,7 +60,7 @@ async function testTableDiff(conn, driver, mangle) { // const TESTED_COLUMNS = ['col_pk', 'col_std', 'col_def', 'col_fk', 'col_ref', 'col_idx', 'col_uq']; // const TESTED_COLUMNS = ['col_pk']; // const TESTED_COLUMNS = ['col_idx']; -const TESTED_COLUMNS = ['col_ref']; +const TESTED_COLUMNS = ['col_def']; // const TESTED_COLUMNS = ['col_std']; function engines_columns_source() { diff --git a/integration-tests/engines.js b/integration-tests/engines.js index 2b8d38fe..bbaa86ad 100644 --- a/integration-tests/engines.js +++ b/integration-tests/engines.js @@ -117,10 +117,10 @@ const engines = [ const filterLocal = [ // filter local testing '-MySQL', - 'PostgreSQL', - '-SQL Server', + '-PostgreSQL', + 'SQL Server', '-SQLite', - 'CockroachDB', + '-CockroachDB', ]; module.exports = process.env.CITEST diff --git a/plugins/dbgate-plugin-mssql/src/backend/MsSqlAnalyser.js b/plugins/dbgate-plugin-mssql/src/backend/MsSqlAnalyser.js index 498c21d7..e30a94ac 100644 --- a/plugins/dbgate-plugin-mssql/src/backend/MsSqlAnalyser.js +++ b/plugins/dbgate-plugin-mssql/src/backend/MsSqlAnalyser.js @@ -32,6 +32,8 @@ function getColumnInfo({ charMaxLength, numericPrecision, numericScale, + defaultValue, + defaultConstraint, }) { let fullDataType = dataType; if (charMaxLength && isTypeString(dataType)) fullDataType = `${dataType}(${charMaxLength})`; @@ -42,6 +44,8 @@ function getColumnInfo({ dataType: fullDataType, notNull: !isNullable, autoIncrement: !!isIdentity, + defaultValue, + defaultConstraint, }; } @@ -99,21 +103,21 @@ class MsSqlAnalyser extends DatabaseAnalyser { .filter(idx => idx.object_id == row.objectId && !idx.is_unique_constraint) .map(idx => ({ ..._.pick(idx, ['constraintName', 'indexType', 'isUnique']), - columns: indexcolsRows.rows.filter( - col => col.object_id == idx.object_id && col.index_id == idx.index_id - ).map(col => ({ - ..._.pick(col, ['columnName', 'isDescending', 'isIncludedColumn']), - })), + columns: indexcolsRows.rows + .filter(col => col.object_id == idx.object_id && col.index_id == idx.index_id) + .map(col => ({ + ..._.pick(col, ['columnName', 'isDescending', 'isIncludedColumn']), + })), })), uniques: indexesRows.rows .filter(idx => idx.object_id == row.objectId && idx.is_unique_constraint) .map(idx => ({ ..._.pick(idx, ['constraintName']), - columns: indexcolsRows.rows.filter( - col => col.object_id == idx.object_id && col.index_id == idx.index_id - ).map(col => ({ - ..._.pick(col, ['columnName']), - })), + columns: indexcolsRows.rows + .filter(col => col.object_id == idx.object_id && col.index_id == idx.index_id) + .map(col => ({ + ..._.pick(col, ['columnName']), + })), })), })); diff --git a/plugins/dbgate-plugin-mssql/src/frontend/MsSqlDumper.js b/plugins/dbgate-plugin-mssql/src/frontend/MsSqlDumper.js index 5ed8f7dc..ff94ef67 100644 --- a/plugins/dbgate-plugin-mssql/src/frontend/MsSqlDumper.js +++ b/plugins/dbgate-plugin-mssql/src/frontend/MsSqlDumper.js @@ -65,6 +65,13 @@ class MsSqlDumper extends SqlDumper { super.dropTable(obj, options); } + dropColumn(column) { + if (column.defaultConstraint) { + this.putCmd('^alter ^table %f ^drop ^constraint %i', column, column.defaultConstraint); + } + super.dropColumn(column); + } + dropDefault(col) { if (col.defaultConstraint) { this.putCmd('^alter ^table %f ^drop ^constraint %i', col, col.defaultConstraint);