alter processor - works add column tests

This commit is contained in:
Jan Prochazka 2021-07-01 09:12:15 +02:00
parent 4a3ef70979
commit 3791fd568c
4 changed files with 14 additions and 4 deletions

View File

@ -4,7 +4,7 @@ const fp = require('lodash/fp');
const uuidv1 = require('uuid/v1'); const uuidv1 = require('uuid/v1');
const { testWrapper } = require('../tools'); const { testWrapper } = require('../tools');
const engines = require('../engines'); const engines = require('../engines');
const { getAlterTableScript, extendDatabaseInfo } = require('dbgate-tools'); const { getAlterTableScript, extendDatabaseInfo, generateDbPairingId } = require('dbgate-tools');
function pickImportantTableInfo(table) { function pickImportantTableInfo(table) {
return { return {
@ -21,7 +21,7 @@ function checkTableStructure(t1, t2) {
async function testTableDiff(conn, driver, mangle) { async function testTableDiff(conn, driver, mangle) {
await driver.query(conn, 'create table t1 (col1 int not null)'); 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); let structure2 = _.cloneDeep(structure1);
mangle(structure2.tables[0]); mangle(structure2.tables[0]);
structure2 = extendDatabaseInfo(structure2); structure2 = extendDatabaseInfo(structure2);

View File

@ -43,6 +43,14 @@ export function generateTablePairingId(table: TableInfo): TableInfo {
return table; 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) { function testEqualNames(a: string, b: string, opts: DbDiffOptions) {
if (opts.ignoreCase) return a.toLowerCase() == b.toLowerCase(); if (opts.ignoreCase) return a.toLowerCase() == b.toLowerCase();
return a == b; return a == b;

View File

@ -21,7 +21,7 @@ function getColumnInfo({
fullDataType = `${dataType}(${numericPrecision},${numericScale})`; fullDataType = `${dataType}(${numericPrecision},${numericScale})`;
return { return {
notNull: !isNullable || isNullable == 'NO' || isNullable == 'no', notNull: !isNullable || isNullable == 'NO' || isNullable == 'no',
autoIncrement: extra && extra.toLowerCase().includes('auto_increment'), autoIncrement: !!(extra && extra.toLowerCase().includes('auto_increment')),
columnName, columnName,
dataType: fullDataType, dataType: fullDataType,
defaultValue, defaultValue,

View File

@ -25,11 +25,13 @@ function getColumnInfo({
if (char_max_length && isTypeString(normDataType)) fullDataType = `${normDataType}(${char_max_length})`; if (char_max_length && isTypeString(normDataType)) fullDataType = `${normDataType}(${char_max_length})`;
if (numeric_precision && numeric_ccale && isTypeNumeric(normDataType)) if (numeric_precision && numeric_ccale && isTypeNumeric(normDataType))
fullDataType = `${normDataType}(${numeric_precision},${numeric_ccale})`; fullDataType = `${normDataType}(${numeric_precision},${numeric_ccale})`;
const autoIncrement = !!(default_value && default_value.startsWith('nextval('));
return { return {
columnName: column_name, columnName: column_name,
dataType: fullDataType, dataType: fullDataType,
notNull: !is_nullable || is_nullable == 'NO' || is_nullable == 'no', notNull: !is_nullable || is_nullable == 'NO' || is_nullable == 'no',
defaultValue: default_value, defaultValue: autoIncrement ? undefined : default_value,
autoIncrement,
}; };
} }