2020-02-03 19:34:38 +00:00
|
|
|
const fp = require("lodash/fp");
|
|
|
|
const _ = require("lodash");
|
2020-02-02 19:28:27 +00:00
|
|
|
|
2020-02-03 19:34:38 +00:00
|
|
|
const DatabaseAnalayser = require("../default/DatabaseAnalyser");
|
2020-02-02 19:28:27 +00:00
|
|
|
|
|
|
|
/** @returns {Promise<string>} */
|
2020-02-03 19:34:38 +00:00
|
|
|
async function loadQuery(pool, name) {
|
|
|
|
return await pool._nativeModules.fs.readFile(
|
|
|
|
pool._nativeModules.path.join(__dirname, name),
|
|
|
|
"utf-8"
|
|
|
|
);
|
2020-02-02 19:28:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class MySqlAnalyser extends DatabaseAnalayser {
|
|
|
|
constructor(pool, driver) {
|
|
|
|
super(pool, driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
async createQuery(
|
|
|
|
resFileName,
|
|
|
|
tables = false,
|
|
|
|
views = false,
|
|
|
|
procedures = false,
|
|
|
|
functions = false,
|
|
|
|
triggers = false
|
|
|
|
) {
|
2020-02-03 19:34:38 +00:00
|
|
|
let res = await loadQuery(this.pool, resFileName);
|
|
|
|
res = res.replace("=[OBJECT_ID_CONDITION]", " is not null");
|
2020-02-02 19:28:27 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
async runAnalysis() {
|
2020-02-03 19:34:38 +00:00
|
|
|
const tables = await this.driver.query(
|
|
|
|
this.pool,
|
|
|
|
await this.createQuery("table_modifications.psql")
|
|
|
|
);
|
|
|
|
const columns = await this.driver.query(
|
|
|
|
this.pool,
|
|
|
|
await this.createQuery("columns.psql")
|
|
|
|
);
|
2020-02-02 19:28:27 +00:00
|
|
|
// const pkColumns = await this.driver.query(this.pool, await this.createQuery('primary_keys.sql'));
|
|
|
|
// const fkColumns = await this.driver.query(this.pool, await this.createQuery('foreign_keys.sql'));
|
|
|
|
|
|
|
|
this.result.tables = tables.rows.map(table => ({
|
|
|
|
...table,
|
|
|
|
columns: columns.rows
|
2020-02-03 19:34:38 +00:00
|
|
|
.filter(
|
|
|
|
col =>
|
|
|
|
col.pureName == table.pureName && col.schemaName == table.schemaName
|
|
|
|
)
|
2020-02-02 19:28:27 +00:00
|
|
|
.map(({ isNullable, ...col }) => ({
|
|
|
|
...col,
|
2020-02-03 19:34:38 +00:00
|
|
|
notNull: !isNullable
|
2020-02-02 19:28:27 +00:00
|
|
|
})),
|
2020-02-03 19:34:38 +00:00
|
|
|
foreignKeys: []
|
2020-02-02 19:28:27 +00:00
|
|
|
// primaryKey: extractPrimaryKeys(table, pkColumns.rows),
|
|
|
|
// foreignKeys: extractForeignKeys(table, fkColumns.rows),
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = MySqlAnalyser;
|