migrating to typescript
This commit is contained in:
parent
565db8de1b
commit
e28d07b8fa
|
@ -18,54 +18,45 @@
|
||||||
*
|
*
|
||||||
* @author Anatoly Khaytovich <anatolyuss@gmail.com>
|
* @author Anatoly Khaytovich <anatolyuss@gmail.com>
|
||||||
*/
|
*/
|
||||||
'use strict';
|
import log from './Logger';
|
||||||
|
import Conversion from './Conversion';
|
||||||
const connect = require('./Connector');
|
import DBAccess from './DBAccess';
|
||||||
const log = require('./Logger');
|
import DBAccessQueryResult from './DBAccessQueryResult';
|
||||||
const generateError = require('./ErrorGenerator');
|
import DBVendors from './DBVendors';
|
||||||
const extraConfigProcessor = require('./ExtraConfigProcessor');
|
import * as extraConfigProcessor from './ExtraConfigProcessor';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts MySQL data types to corresponding PostgreSQL data types.
|
* Converts MySQL data types to corresponding PostgreSQL data types.
|
||||||
* This conversion performs in accordance to mapping rules in './config/data_types_map.json'.
|
* This conversion performs in accordance to mapping rules in './config/data_types_map.json'.
|
||||||
* './config/data_types_map.json' can be customized.
|
* './config/data_types_map.json' can be customized.
|
||||||
*
|
|
||||||
* @param {Object} objDataTypesMap
|
|
||||||
* @param {String} mySqlDataType
|
|
||||||
*
|
|
||||||
* @returns {String}
|
|
||||||
*/
|
*/
|
||||||
const mapDataTypes = (objDataTypesMap, mySqlDataType) => {
|
export function mapDataTypes(objDataTypesMap: any, mySqlDataType: string): string {
|
||||||
let retVal = '';
|
let retVal: string = '';
|
||||||
let arrDataTypeDetails = mySqlDataType.split(' ');
|
const arrDataTypeDetails: string[] = mySqlDataType.split(' ');
|
||||||
mySqlDataType = arrDataTypeDetails[0].toLowerCase();
|
mySqlDataType = arrDataTypeDetails[0].toLowerCase();
|
||||||
const increaseOriginalSize = arrDataTypeDetails.indexOf('unsigned') !== -1 || arrDataTypeDetails.indexOf('zerofill') !== -1;
|
const increaseOriginalSize: boolean = arrDataTypeDetails.indexOf('unsigned') !== -1 || arrDataTypeDetails.indexOf('zerofill') !== -1;
|
||||||
arrDataTypeDetails = null;
|
|
||||||
|
|
||||||
if (mySqlDataType.indexOf('(') === -1) {
|
if (mySqlDataType.indexOf('(') === -1) {
|
||||||
// No parentheses detected.
|
// No parentheses detected.
|
||||||
retVal = increaseOriginalSize ? objDataTypesMap[mySqlDataType].increased_size : objDataTypesMap[mySqlDataType].type;
|
retVal = increaseOriginalSize ? objDataTypesMap[mySqlDataType].increased_size : objDataTypesMap[mySqlDataType].type;
|
||||||
} else {
|
} else {
|
||||||
// Parentheses detected.
|
// Parentheses detected.
|
||||||
let arrDataType = mySqlDataType.split('(');
|
const arrDataType: string[] = mySqlDataType.split('(');
|
||||||
const strDataType = arrDataType[0].toLowerCase();
|
const strDataType: string = arrDataType[0].toLowerCase();
|
||||||
const strDataTypeDisplayWidth = arrDataType[1];
|
const strDataTypeDisplayWidth: string = arrDataType[1];
|
||||||
arrDataType = null;
|
|
||||||
|
|
||||||
if ('enum' === strDataType || 'set' === strDataType) {
|
if ('enum' === strDataType || 'set' === strDataType) {
|
||||||
retVal = 'character varying(255)';
|
retVal = 'character varying(255)';
|
||||||
} else if ('decimal' === strDataType || 'numeric' === strDataType) {
|
} else if ('decimal' === strDataType || 'numeric' === strDataType) {
|
||||||
retVal = objDataTypesMap[strDataType].type + '(' + strDataTypeDisplayWidth;
|
retVal = `${ objDataTypesMap[strDataType].type }(${ strDataTypeDisplayWidth }`;
|
||||||
} else if ('decimal(19,2)' === mySqlDataType || objDataTypesMap[strDataType].mySqlVarLenPgSqlFixedLen) {
|
} else if ('decimal(19,2)' === mySqlDataType || objDataTypesMap[strDataType].mySqlVarLenPgSqlFixedLen) {
|
||||||
// Should be converted without a length definition.
|
// Should be converted without a length definition.
|
||||||
retVal = increaseOriginalSize
|
retVal = increaseOriginalSize ? objDataTypesMap[strDataType].increased_size : objDataTypesMap[strDataType].type;
|
||||||
? objDataTypesMap[strDataType].increased_size
|
|
||||||
: objDataTypesMap[strDataType].type;
|
|
||||||
} else {
|
} else {
|
||||||
// Should be converted with a length definition.
|
// Should be converted with a length definition.
|
||||||
retVal = increaseOriginalSize
|
retVal = increaseOriginalSize
|
||||||
? objDataTypesMap[strDataType].increased_size + '(' + strDataTypeDisplayWidth
|
? `${ objDataTypesMap[strDataType].increased_size }(${ strDataTypeDisplayWidth }`
|
||||||
: objDataTypesMap[strDataType].type + '(' + strDataTypeDisplayWidth;
|
: `${ objDataTypesMap[strDataType].type }(${ strDataTypeDisplayWidth }`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,18 +70,15 @@ const mapDataTypes = (objDataTypesMap, mySqlDataType) => {
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.mapDataTypes = mapDataTypes;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Migrates structure of a single table to PostgreSql server.
|
* Migrates structure of a single table to PostgreSql server.
|
||||||
*
|
|
||||||
* @param {Conversion} self
|
|
||||||
* @param {String} tableName
|
|
||||||
*
|
|
||||||
* @returns {Promise}
|
|
||||||
*/
|
*/
|
||||||
module.exports.createTable = (self, tableName) => {
|
export async function createTable(conversion: Conversion, tableName: string): Promise<void> {
|
||||||
return connect(self).then(() => {
|
const logTitle: string = 'createTable';
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
/*return connect(self).then(() => {
|
||||||
return new Promise((resolveCreateTable, rejectCreateTable) => {
|
return new Promise((resolveCreateTable, rejectCreateTable) => {
|
||||||
log(self, '\t--[createTable] Currently creating table: `' + tableName + '`', self._dicTables[tableName].tableLogPath);
|
log(self, '\t--[createTable] Currently creating table: `' + tableName + '`', self._dicTables[tableName].tableLogPath);
|
||||||
self._mysql.getConnection((error, connection) => {
|
self._mysql.getConnection((error, connection) => {
|
||||||
|
@ -151,5 +139,5 @@ module.exports.createTable = (self, tableName) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});*/
|
||||||
};
|
}
|
Loading…
Reference in a new issue