postgre analyser

This commit is contained in:
Jan Prochazka
2020-06-29 19:49:54 +02:00
parent eaaa7beaa1
commit 3c1be39976
6 changed files with 35 additions and 13 deletions

View File

@@ -29,7 +29,7 @@ function getColumnInfo({
return {
columnName,
dataType: fullDataType,
notNull: !isNullable,
notNull: !isNullable || isNullable == 'NO' || isNullable == 'no',
autoIncrement: !!isIdentity,
defaultValue,
};
@@ -40,16 +40,17 @@ class PostgreAnalyser extends DatabaseAnalayser {
super(pool, driver);
}
createQuery(resFileName, tables = false, views = false, procedures = false, functions = false, triggers = false) {
createQuery(resFileName, typeFields) {
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, this.createQuery('tableModifications'));
const columns = await this.driver.query(this.pool, this.createQuery('columns'));
const pkColumns = await this.driver.query(this.pool, this.createQuery('primaryKeys'));
const fkColumns = await this.driver.query(this.pool, this.createQuery('foreignKeys'));
const tables = await this.driver.query(this.pool, this.createQuery('tableModifications', ['tables']));
const columns = await this.driver.query(this.pool, this.createQuery('columns', ['tables']));
const pkColumns = await this.driver.query(this.pool, this.createQuery('primaryKeys', ['tables']));
const fkColumns = await this.driver.query(this.pool, this.createQuery('foreignKeys', ['tables']));
const views = await this.driver.query(this.pool, this.createQuery('views', ['views']));
// console.log('PG fkColumns', fkColumns.rows);
return this.mergeAnalyseResult({
@@ -61,6 +62,12 @@ class PostgreAnalyser extends DatabaseAnalayser {
primaryKey: DatabaseAnalayser.extractPrimaryKeys(table, pkColumns.rows),
foreignKeys: DatabaseAnalayser.extractForeignKeys(table, fkColumns.rows),
})),
views: views.rows.map((view) => ({
...view,
columns: columns.rows
.filter((col) => col.pureName == view.pureName && col.schemaName == view.schemaName)
.map(getColumnInfo),
})),
});
}
}