diff --git a/integration-tests/__tests__/alter-processor.spec.js b/integration-tests/__tests__/alter-processor.spec.js index c5804718..13db05b5 100644 --- a/integration-tests/__tests__/alter-processor.spec.js +++ b/integration-tests/__tests__/alter-processor.spec.js @@ -4,7 +4,7 @@ const fp = require('lodash/fp'); const uuidv1 = require('uuid/v1'); const { testWrapper } = require('../tools'); const engines = require('../engines'); -const { getAlterTableScript, extendDatabaseInfo } = require('dbgate-tools'); +const { getAlterTableScript, extendDatabaseInfo, generateDbPairingId } = require('dbgate-tools'); function pickImportantTableInfo(table) { return { @@ -21,7 +21,7 @@ function checkTableStructure(t1, t2) { async function testTableDiff(conn, driver, mangle) { await driver.query(conn, 'create table t1 (col1 int not null)'); - const structure1 = extendDatabaseInfo(await driver.analyseFull(conn)); + const structure1 = generateDbPairingId(extendDatabaseInfo(await driver.analyseFull(conn))); let structure2 = _.cloneDeep(structure1); mangle(structure2.tables[0]); structure2 = extendDatabaseInfo(structure2); diff --git a/packages/tools/src/diffTools.ts b/packages/tools/src/diffTools.ts index 02ce614d..3e04f48e 100644 --- a/packages/tools/src/diffTools.ts +++ b/packages/tools/src/diffTools.ts @@ -43,6 +43,14 @@ export function generateTablePairingId(table: TableInfo): TableInfo { return table; } +export function generateDbPairingId(db: DatabaseInfo): DatabaseInfo { + if (!db) return db; + return { + ...db, + tables: (db.tables || []).map(generateTablePairingId), + }; +} + function testEqualNames(a: string, b: string, opts: DbDiffOptions) { if (opts.ignoreCase) return a.toLowerCase() == b.toLowerCase(); return a == b; diff --git a/plugins/dbgate-plugin-mysql/src/backend/Analyser.js b/plugins/dbgate-plugin-mysql/src/backend/Analyser.js index f0c92f4b..a4e101e0 100644 --- a/plugins/dbgate-plugin-mysql/src/backend/Analyser.js +++ b/plugins/dbgate-plugin-mysql/src/backend/Analyser.js @@ -21,7 +21,7 @@ function getColumnInfo({ fullDataType = `${dataType}(${numericPrecision},${numericScale})`; return { notNull: !isNullable || isNullable == 'NO' || isNullable == 'no', - autoIncrement: extra && extra.toLowerCase().includes('auto_increment'), + autoIncrement: !!(extra && extra.toLowerCase().includes('auto_increment')), columnName, dataType: fullDataType, defaultValue, diff --git a/plugins/dbgate-plugin-postgres/src/backend/Analyser.js b/plugins/dbgate-plugin-postgres/src/backend/Analyser.js index 523dca8b..7ff13b89 100644 --- a/plugins/dbgate-plugin-postgres/src/backend/Analyser.js +++ b/plugins/dbgate-plugin-postgres/src/backend/Analyser.js @@ -25,11 +25,13 @@ function getColumnInfo({ if (char_max_length && isTypeString(normDataType)) fullDataType = `${normDataType}(${char_max_length})`; if (numeric_precision && numeric_ccale && isTypeNumeric(normDataType)) fullDataType = `${normDataType}(${numeric_precision},${numeric_ccale})`; + const autoIncrement = !!(default_value && default_value.startsWith('nextval(')); return { columnName: column_name, dataType: fullDataType, notNull: !is_nullable || is_nullable == 'NO' || is_nullable == 'no', - defaultValue: default_value, + defaultValue: autoIncrement ? undefined : default_value, + autoIncrement, }; }