mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 12:13:57 +00:00
alter processor - works add column tests
This commit is contained in:
parent
4a3ef70979
commit
3791fd568c
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user