Skip to content

Commit

Permalink
fix: ssl not set up properly
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Jan 11, 2021
1 parent ad476cb commit 24ebbfd
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ module.exports = ({
defaults.password ||
"",
database,
ssl: process.env.POSTGRES_SSL
? Boolean(process.env.POSTGRES_SSL)
: {
rejectUnauthorized: false,
},
}

const createDatabase = async (dbName) => {
Expand All @@ -52,6 +47,11 @@ module.exports = ({
client: "pg",
connection: getConnectionInfo("postgres"),
pool,
ssl: process.env.POSTGRES_SSL
? Boolean(process.env.POSTGRES_SSL)
: {
rejectUnauthorized: false,
},
})
await conn.raw(`CREATE DATABASE ${dbName}`)
await conn.destroy()
Expand All @@ -64,6 +64,11 @@ module.exports = ({
client: "pg",
connection: getConnectionInfo("postgres"),
pool,
ssl: process.env.POSTGRES_SSL
? Boolean(process.env.POSTGRES_SSL)
: {
rejectUnauthorized: false,
},
})
await conn.raw(`DROP DATABASE ${dbName}`)
await conn.destroy()
Expand Down Expand Up @@ -97,6 +102,11 @@ module.exports = ({
client: "pg",
connection,
pool,
ssl: process.env.POSTGRES_SSL
? Boolean(process.env.POSTGRES_SSL)
: {
rejectUnauthorized: false,
},
})

// test connection
Expand All @@ -113,7 +123,17 @@ module.exports = ({

if (user) {
await pg.destroy()
pg = knex({ client: "pg", connection: getConnectionInfo(dbName), pool })
pg = knex({
client: "pg",
connection: getConnectionInfo(dbName),
pool,

ssl: process.env.POSTGRES_SSL
? Boolean(process.env.POSTGRES_SSL)
: {
rejectUnauthorized: false,
},
})
await pg.raw(`SET ROLE ${user};`)
// test connection
try {
Expand Down

0 comments on commit 24ebbfd

Please sign in to comment.