Skip to content

Commit

Permalink
postgre analyser
Browse files Browse the repository at this point in the history
  • Loading branch information
janproch committed Jun 29, 2020
1 parent 3c1be39 commit 7186177
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/engines/postgres/PostgreAnalyser.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class PostgreAnalyser extends DatabaseAnalayser {
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']));
const routines = await this.driver.query(this.pool, this.createQuery('routines', ['procedures', 'functions']));
// console.log('PG fkColumns', fkColumns.rows);

return this.mergeAnalyseResult({
Expand All @@ -68,6 +69,8 @@ class PostgreAnalyser extends DatabaseAnalayser {
.filter((col) => col.pureName == view.pureName && col.schemaName == view.schemaName)
.map(getColumnInfo),
})),
procedures: routines.rows.filter((x) => x.objectType == 'PROCEDURE'),
functions: routines.rows.filter((x) => x.objectType == 'FUNCTION'),
});
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/engines/postgres/sql/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ const tableModifications = require('./tableModifications');
const primaryKeys = require('./primaryKeys');
const foreignKeys = require('./foreignKeys');
const views = require('./views');
const routines = require('./routines');

module.exports = {
columns,
tableModifications,
primaryKeys,
foreignKeys,
views,
routines,
};
10 changes: 10 additions & 0 deletions packages/engines/postgres/sql/routines.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = `
select
routine_name as "pureName",
routine_schema as "schemaName",
routine_definition as "createSql",
md5(routine_definition) as "hashCode",
routine_type as "objectType"
from
information_schema.routines where routine_schema != 'information_schema' and routine_schema != 'pg_catalog' and routine_type is not null
`;

0 comments on commit 7186177

Please sign in to comment.