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: db url check #24

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Empty file removed .github/workflows/.gitkeep
Empty file.
11 changes: 7 additions & 4 deletions knexfile.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
require('dotenv').config({ path: `.env.${process.env.NODE_ENV}` });
const path = require('path');
const expect = require('expect-runtime');

const connection = process.env.DATABASE_URL_SEEDER;

expect(connection).to.match(/^postgresql:\//);
const postgresPattern = /^postgresql:\//;

if (!postgresPattern.test(connection)) {
throw new Error('invalid database connection url received');
}

module.exports = {
development: {
Expand All @@ -13,7 +16,7 @@ module.exports = {
searchPath: [process.env.DATABASE_SCHEMA, 'public'],
pool: {
min: 1,
max: 100,
max: 10,
},
seeds: {
directory: path.join(__dirname, 'database', 'seeds'),
Expand All @@ -26,7 +29,7 @@ module.exports = {
searchPath: [process.env.DATABASE_SCHEMA, 'public'],
pool: {
min: 1,
max: 100,
max: 10,
},
seeds: {
directory: path.join(__dirname, 'database', 'seeds'),
Expand Down
9 changes: 6 additions & 3 deletions server/database/knex.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
require('dotenv').config();
const expect = require('expect-runtime');
const knex = require('knex');
const connection = require('../../config/config').connectionString;

expect(connection).to.match(/^postgresql:\//);
const postgresPattern = /^postgresql:\//;

if (!postgresPattern.test(connection)) {
throw new Error('invalid database connection url received');
}

const knexConfig = {
client: 'pg',
debug: process.env.NODE_LOG_LEVEL === 'debug',
connection,
pool: {
min: 0,
max: 100,
max: 10,
},
};

Expand Down