From ba4605752b60681dd105b9d677265c393ab91322 Mon Sep 17 00:00:00 2001 From: Samuli Asmala Date: Mon, 30 Nov 2020 11:50:18 +0200 Subject: [PATCH] Only select columns from BASE TABLEs to exclude views Postgres views cannot have primary keys so presence of any views prevented the use of application. Fixes #3229. --- packages/schema/src/dialects/postgres.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/schema/src/dialects/postgres.ts b/packages/schema/src/dialects/postgres.ts index 42cf64ab48..048acc331c 100644 --- a/packages/schema/src/dialects/postgres.ts +++ b/packages/schema/src/dialects/postgres.ts @@ -90,18 +90,23 @@ export default class Postgres implements Schema { // =============================================================================================== async overview() { const [columnsResult, primaryKeysResult] = await Promise.all([ + // Only select columns from BASE TABLEs to exclude views (Postgres views + // cannot have primary keys so they cannot be used) this.knex.raw( ` SELECT - table_name, - column_name, - column_default as default_value, - is_nullable, - data_type + c.table_name, + c.column_name, + c.column_default as default_value, + c.is_nullable, + c.data_type FROM - information_schema.columns + information_schema.columns c + LEFT JOIN information_schema.tables t + ON c.table_name = t.table_name WHERE - table_schema IN (?); + t.table_type = 'BASE TABLE' + AND c.table_schema IN (?); `, [this.explodedSchema.join(',')] ),