Skip to content

Commit

Permalink
fix(knexfile): don't panic if there is no .env file
Browse files Browse the repository at this point in the history
When running zion on a container usually the envs
are provided as configuration parameters from the
CLI or in a docker-compose file. This change makes
sure that the knexfile doesn't panic if there is no
.env file, but uses the process.env directly.
  • Loading branch information
relu91 committed Feb 14, 2024
1 parent 4cb6801 commit 5940b35
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions knexfile.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import { existsSync } from 'fs';

import { path as rootPath } from 'app-root-path';
import * as dotenv from 'dotenv';
import type { Knex } from 'knex';

const baseEnvPath = `${process.cwd()}`;
const envPath =
process.env.NODE_ENV === undefined ? `${baseEnvPath}/.env` : `${baseEnvPath}/${process.env.NODE_ENV}.env`;
dotenv.config({
path: envPath,
debug: true,
});

if (existsSync(envPath)) {
dotenv.config({
path: envPath,
debug: true,
});
} else {
console.warn(
`No .env file found at ${envPath}, using process.env. If you are running in a container please ensure that the environment variables are set.`,
);
}

const config: Knex.Config = {
client: 'pg',
Expand Down

0 comments on commit 5940b35

Please sign in to comment.