backend bundle refactor

This commit is contained in:
Jan Prochazka
2020-03-14 10:38:10 +01:00
parent cd58555409
commit 1d63908328
15 changed files with 66 additions and 53 deletions

View File

@@ -1,13 +1,9 @@
const fp = require('lodash/fp');
const _ = require('lodash');
const sql = require('./sql')
const DatabaseAnalayser = require('../default/DatabaseAnalyser');
/** @returns {Promise<string>} */
async function loadQuery(pool, name) {
return await pool._nativeModules.fs.readFile(pool._nativeModules.path.join(__dirname, name), 'utf-8');
}
const byTableFilter = table => x => x.pureName == table.pureName && x.schemaName == x.schemaName;
function extractPrimaryKeys(table, pkColumns) {
@@ -184,15 +180,15 @@ class MsSqlAnalyser extends DatabaseAnalayser {
functions = false,
triggers = false
) {
let res = await loadQuery(this.pool, resFileName);
let res = sql[resFileName];
res = res.replace('=[OBJECT_ID_CONDITION]', ' is not null');
return res;
}
async runAnalysis() {
const tables = await this.driver.query(this.pool, await this.createQuery('tables.sql'));
const columns = await this.driver.query(this.pool, await this.createQuery('columns.sql'));
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'));
const tables = await this.driver.query(this.pool, await this.createQuery('tables'));
const columns = await this.driver.query(this.pool, await this.createQuery('columns'));
const pkColumns = await this.driver.query(this.pool, await this.createQuery('primaryKeys'));
const fkColumns = await this.driver.query(this.pool, await this.createQuery('foreignKeys'));
this.result.tables = tables.rows.map(table => ({
...table,

View File

@@ -1,3 +1,4 @@
module.exports = `
select c.name as columnName, t.name as dataType, c.object_id as objectId, c.is_identity as isIdentity,
c.max_length as maxLength, c.precision, c.scale, c.is_nullable as isNullable,
d.definition as defaultValue, d.name as defaultConstraint,
@@ -11,3 +12,4 @@ left join sys.default_constraints d on c.default_object_id = d.object_id
left join sys.computed_columns m on m.object_id = c.object_id and m.column_id = c.column_id
where o.type = 'U' and o.object_id =[OBJECT_ID_CONDITION]
order by c.column_id
`;

View File

@@ -1,3 +1,4 @@
module.exports = `
SELECT
schemaName = FK.TABLE_SCHEMA,
pureName = FK.TABLE_NAME,
@@ -36,3 +37,4 @@ inner join sys.objects o on FK.TABLE_NAME = o.name
inner join sys.schemas s on o.schema_id = s.schema_id and FK.TABLE_SCHEMA = s.name
where o.object_id =[OBJECT_ID_CONDITION]
`;

View File

@@ -0,0 +1,11 @@
const columns = require('./columns');
const foreignKeys = require('./foreignKeys');
const primaryKeys = require('./primaryKeys');
const tables = require('./tables');
module.exports = {
columns,
tables,
foreignKeys,
primaryKeys,
};

View File

@@ -1,3 +1,4 @@
module.exports = `
select o.object_id, pureName = t.Table_Name, schemaName = t.Table_Schema, columnName = c.Column_Name, constraintName=t.constraint_name from
INFORMATION_SCHEMA.TABLE_CONSTRAINTS t,
sys.objects o,
@@ -10,3 +11,4 @@ where
and c.Table_Name = t.Table_Name
and Constraint_Type = 'PRIMARY KEY'
and o.object_id =[OBJECT_ID_CONDITION]
`;

View File

@@ -1,6 +1,8 @@
module.exports = `
select
o.name as pureName, s.name as schemaName, o.object_id as objectId,
o.create_date, o.modify_date
from sys.tables o
inner join sys.schemas s on o.schema_id = s.schema_id
where o.object_id =[OBJECT_ID_CONDITION]
`;