From d661b9f6a4651d0b7b8fcef975204fdb4503ad06 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Tue, 29 Oct 2024 16:07:51 +0100 Subject: [PATCH] fixed mssql defaults --- plugins/dbgate-plugin-mssql/src/backend/MsSqlAnalyser.js | 9 +++++++++ plugins/dbgate-plugin-mssql/src/frontend/MsSqlDumper.js | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/dbgate-plugin-mssql/src/backend/MsSqlAnalyser.js b/plugins/dbgate-plugin-mssql/src/backend/MsSqlAnalyser.js index 3ecf458a..d21ba9be 100644 --- a/plugins/dbgate-plugin-mssql/src/backend/MsSqlAnalyser.js +++ b/plugins/dbgate-plugin-mssql/src/backend/MsSqlAnalyser.js @@ -51,6 +51,15 @@ function getColumnInfo({ if (numericPrecision && numericScale && isTypeNumeric(dataType)) { fullDataType = `${dataType}(${numericPrecision},${numericScale})`; } + + if (defaultValue) { + defaultValue = defaultValue.trim(); + while (defaultValue.startsWith('(') && defaultValue.endsWith(')')) { + defaultValue = defaultValue.slice(1, -1); + defaultValue = defaultValue.trim(); + } + } + return { columnName, dataType: fullDataType, diff --git a/plugins/dbgate-plugin-mssql/src/frontend/MsSqlDumper.js b/plugins/dbgate-plugin-mssql/src/frontend/MsSqlDumper.js index 052319d7..61f27cf9 100644 --- a/plugins/dbgate-plugin-mssql/src/frontend/MsSqlDumper.js +++ b/plugins/dbgate-plugin-mssql/src/frontend/MsSqlDumper.js @@ -128,14 +128,14 @@ class MsSqlDumper extends SqlDumper { if (testEqualColumns(oldcol, newcol, false, false)) { this.dropDefault(oldcol); if (oldcol.columnName != newcol.columnName) this.renameColumn(oldcol, newcol.columnName); - this.createDefault(oldcol); + this.createDefault(newcol); } else { this.dropDefault(oldcol); if (oldcol.columnName != newcol.columnName) this.renameColumn(oldcol, newcol.columnName); this.put('^alter ^table %f ^alter ^column %i ', oldcol, oldcol.columnName, newcol.columnName); this.columnDefinition(newcol, { includeDefault: false }); this.endCommand(); - this.createDefault(oldcol); + this.createDefault(newcol); } }