mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 17:36:01 +00:00
postgre analyser
This commit is contained in:
@@ -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),
|
||||
})),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user