From 85da50c288539d3020a816d364d3a3efa50b6467 Mon Sep 17 00:00:00 2001 From: Euclides dos Reis Silva Junior Date: Tue, 3 Dec 2019 17:01:12 +0100 Subject: [PATCH] Check schema when checking for migrations table. --- src/migrate.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/migrate.ts b/src/migrate.ts index 414c99f..1752fe1 100644 --- a/src/migrate.ts +++ b/src/migrate.ts @@ -190,11 +190,17 @@ function logResult(completedMigrations: Array, log: Logger) { } /** Check whether table exists in postgres - http://stackoverflow.com/a/24089729 */ -async function doesTableExist(client: BasicPgClient, tableName: string) { +async function doesTableExist( + client: BasicPgClient, + tableName: string, + schema = "public", +) { const result = await client.query(SQL`SELECT EXISTS ( SELECT 1 FROM pg_catalog.pg_class c - WHERE c.relname = ${tableName} + JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace + WHERE n.nspname = ${schema} + AND c.relname = ${tableName} AND c.relkind = 'r' );`)