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,16 +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"
);
}
class MySqlAnalyser extends DatabaseAnalayser {
constructor(pool, driver) {
super(pool, driver);
@@ -24,18 +17,18 @@ class MySqlAnalyser 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("table_modifications.psql")
await this.createQuery("tableModifications")
);
const columns = await this.driver.query(
this.pool,
await this.createQuery("columns.psql")
await this.createQuery("columns")
);
// 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'));

View File

@@ -1,3 +1,4 @@
module.exports = `
select
table_schema as "schemaName",
table_name as "pureName",
@@ -15,3 +16,4 @@ where
and table_schema !~ '^pg_toast'
and 'table:' || table_schema || '.' || table_name =[OBJECT_ID_CONDITION]
order by ordinal_position
`;

View File

@@ -0,0 +1,7 @@
const columns = require('./columns');
const tableModifications = require('./tableModifications');
module.exports = {
columns,
tableModifications,
};

View File

@@ -1,6 +1,7 @@
module.exports = `
with pkey as
(
select cc.conrelid, format(E'create constraint %I primary key(%s);\n', cc.conname,
select cc.conrelid, format(E'create constraint %I primary key(%s);\\n', cc.conname,
string_agg(a.attname, ', '
order by array_position(cc.conkey, a.attnum))) pkey
from pg_catalog.pg_constraint cc
@@ -13,13 +14,13 @@ with pkey as
SELECT oid as "objectId", nspname as "schemaName", relname as "pureName",
md5('CREATE TABLE ' || nspname || '.' || relname || E'\n(\n' ||
md5('CREATE TABLE ' || nspname || '.' || relname || E'\\n(\\n' ||
array_to_string(
array_agg(
' ' || column_name || ' ' || type || ' '|| not_null
)
, E',\n'
) || E'\n);\n' || (select pkey from pkey where pkey.conrelid = oid)) as "hash"
, E',\\n'
) || E'\\n);\\n' || (select pkey from pkey where pkey.conrelid = oid)) as "hash"
from
(
SELECT
@@ -48,3 +49,4 @@ from
) as tabledefinition
where 'table:' || nspname || '.' || relname =[OBJECT_ID_CONDITION]
group by relname, nspname, oid
`;