2020-04-11 18:24:30 +00:00
|
|
|
const fp = require('lodash/fp');
|
|
|
|
const _ = require('lodash');
|
|
|
|
const sql = require('./sql');
|
2020-02-02 19:28:27 +00:00
|
|
|
|
2020-04-11 18:24:30 +00:00
|
|
|
const DatabaseAnalayser = require('../default/DatabaseAnalyser');
|
2020-02-02 19:28:27 +00:00
|
|
|
|
|
|
|
class MySqlAnalyser extends DatabaseAnalayser {
|
|
|
|
constructor(pool, driver) {
|
|
|
|
super(pool, driver);
|
|
|
|
}
|
|
|
|
|
2020-04-11 18:24:30 +00:00
|
|
|
createQuery(resFileName, tables = false, views = false, procedures = false, functions = false, triggers = false) {
|
2020-03-14 09:38:10 +00:00
|
|
|
let res = sql[resFileName];
|
2020-04-11 18:24:30 +00:00
|
|
|
res = res.replace('=[OBJECT_ID_CONDITION]', ' is not null');
|
2020-02-02 19:28:27 +00:00
|
|
|
return res;
|
|
|
|
}
|
2020-04-12 08:16:33 +00:00
|
|
|
async _runAnalysis() {
|
2020-04-11 18:24:30 +00:00
|
|
|
const tables = await this.driver.query(this.pool, this.createQuery('tableModifications'));
|
|
|
|
const columns = await this.driver.query(this.pool, this.createQuery('columns'));
|
|
|
|
// const pkColumns = await this.driver.query(this.pool, this.createQuery('primary_keys.sql'));
|
|
|
|
// const fkColumns = await this.driver.query(this.pool, this.createQuery('foreign_keys.sql'));
|
2020-02-02 19:28:27 +00:00
|
|
|
|
2020-04-12 08:16:33 +00:00
|
|
|
return this.mergeAnalyseResult({
|
|
|
|
tables: tables.rows.map((table) => ({
|
|
|
|
...table,
|
|
|
|
columns: columns.rows
|
|
|
|
.filter((col) => col.pureName == table.pureName && col.schemaName == table.schemaName)
|
|
|
|
.map(({ isNullable, ...col }) => ({
|
|
|
|
...col,
|
|
|
|
notNull: !isNullable,
|
|
|
|
})),
|
|
|
|
foreignKeys: [],
|
|
|
|
// primaryKey: extractPrimaryKeys(table, pkColumns.rows),
|
|
|
|
// foreignKeys: extractForeignKeys(table, fkColumns.rows),
|
|
|
|
})),
|
|
|
|
});
|
2020-02-02 19:28:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = MySqlAnalyser;
|