Skip to content

Commit

Permalink
fix: env var passing
Browse files Browse the repository at this point in the history
  • Loading branch information
Samika Kashyap committed May 17, 2024
1 parent 0c3fb85 commit 3843108
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
11 changes: 6 additions & 5 deletions config/env/dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,16 @@
"db": {
"connection": {
"database": "@@DB_NAME",
"replicaDatabase": "@@REPLICA_DB_NAME",
"host": "@@DB_HOST",
"replicaHost": "@@REPLICA_DB_HOST",
"user": "@@DB_USERNAME",
"replicaUser": "@@REPLICA_DB_USERNAME",
"password": "@@DB_PASSWORD",
"replicaPassword": "@@DB_PASSWORD",
"port": "@@DB_PORT",
"replicaPort": "@@REPLICA_DB_PORT"
"replicaDatabase": "@@REPLICA_DB_NAME",
"replicaHost": "@@REPLICA_DB_HOST",
"replicaUser": "@@REPLICA_DB_USERNAME",
"replicaPassword": "@@REPLICA_DB_PASSWORD",
"replicaPort": "@@REPLICA_DB_PORT",
"replicaConnectionString": "@@REPLICA_DB_CONNECTION_STRING"
}
},
"queue": {
Expand Down
15 changes: 8 additions & 7 deletions src/db-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,14 @@ export async function createDbConnection(dbConfig: Db = config.db): Promise<Knex
export async function createReplicaDbConnection(dbConfig: Db = config.db): Promise<Knex> {
const replicaKnexConfig: Knex.Config = {
client: dbConfig.client,
connection: dbConfig.replicaConnectionString,
connection: dbConfig.connection.replicaConnectionString || {
host: dbConfig.connection.replicaHost,
port: dbConfig.connection.replicaPort,
user: dbConfig.connection.replicaUser,
password: dbConfig.connection.replicaPassword,
database: dbConfig.connection.replicaDatabase,
},
debug: dbConfig.debug,
migrations: dbConfig.migrations,
pool: { min: 3, max: 30 },
// In our DB, identifiers have snake case formatting while in our code identifiers have camel case formatting.
// We use the following transformers so we can always use camel case formatting in our code.
Expand All @@ -88,13 +93,9 @@ export async function createReplicaDbConnection(dbConfig: Db = config.db): Promi
try {
connection = knex(replicaKnexConfig)
} catch (e) {
throw new Error(`Database connection failed: ${e}`)
throw new Error(`Replica database connection failed: ${e}`)
}

await runMigrations(connection).catch((err) => {
throw new Error(`Migrations have failed: ${err}`)
})

return connection
}

Expand Down

0 comments on commit 3843108

Please sign in to comment.