Skip to content

Commit

Permalink
chore: migrate knex configuration to config handler
Browse files Browse the repository at this point in the history
  • Loading branch information
UlisesGascon committed Dec 3, 2024
1 parent fab8e81 commit ac8ad1a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 30 deletions.
24 changes: 3 additions & 21 deletions knexfile.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
const { normalizeBoolean } = require('@ulisesgascon/normalize-boolean')
const dbSettings = {
client: 'pg',
connection: {
host: process.env.DB_HOST || '0.0.0.0',
user: process.env.DB_USER || 'openjs',
password: process.env.DB_PASSWORD || 'password',
database: process.env.DB_NAME || 'dashboard'
},
ssl: normalizeBoolean(process.env.DB_SSL),
pool: {
min: 2,
max: 10
},
migrations: {
directory: './src/database/migrations'
},
seeds: {
directory: './src/database/seeds'
}
}
const { getConfig } = require('./src/config')

const { dbSettings } = getConfig()

module.exports = {
development: dbSettings
Expand Down
42 changes: 33 additions & 9 deletions src/config/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
const { normalizeBoolean } = require('@ulisesgascon/normalize-boolean')
const projectCategories = ['impact', 'at-large', 'incubation', 'emeritus']

const dbSettings = {
client: 'pg',
connection: {
host: process.env.DB_HOST || '0.0.0.0',
user: process.env.DB_USER || 'openjs',
password: process.env.DB_PASSWORD || 'password',
database: process.env.DB_NAME || 'dashboard'
},
ssl: normalizeBoolean(process.env.DB_SSL),
pool: {
min: 2,
max: 10
},
migrations: {
directory: './src/database/migrations'
},
seeds: {
directory: './src/database/seeds'
}
}

const defaultValues = {
projectCategories
projectCategories,
dbSettings
}
const testEnvironment = {
projectCategories
projectCategories,
dbSettings
}

const getConfig = env => {
// NOTE: env variable should override the NODE_ENV
const environment = env || process.env.NODE_ENV
const config = environment === 'test' ? testEnvironment : defaultValues
return config
// NOTE: env variable should override the NODE_ENV
const environment = env || process.env.NODE_ENV
const config = environment === 'test' ? testEnvironment : defaultValues
return config
}

module.exports = {
getConfig
}
getConfig
}

0 comments on commit ac8ad1a

Please sign in to comment.