Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix postgres hascolumn return value #140

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/dialects/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,15 @@ export default class Postgres implements SchemaInspector {
/**
* Check if the given table contains the given column
*/
async hasColumn(table: string, column: string) {
async hasColumn(table: string, column: string): Promise<boolean> {
const schemaIn = this.explodedSchema.map(
(schemaName) => `${this.knex.raw('?', [schemaName])}::regnamespace`
);

const result = await this.knex.raw(
const result = await this.knex.raw<{ rows: { count: number }[] }>(
`
SELECT
att.attname AS column,
rel.relname AS table
COUNT(*)::integer as count
FROM
pg_attribute att
LEFT JOIN pg_class rel ON att.attrelid = rel.oid
Expand All @@ -377,7 +376,7 @@ export default class Postgres implements SchemaInspector {
[table, column]
);

return result.rows;
return !!(result && result.rows[0].count > 0);
}

/**
Expand Down