Skip to content

Commit 7ddf8d1

Browse files
committed
fix: load database env vars on demand so they get correctly populated on verifier startup
1 parent a6add22 commit 7ddf8d1

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/config/configuration.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ import {
1717
import { IndexerConfig } from './interfaces/chain-indexer';
1818
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
1919
import { web2JsonDefaultParams } from './defaults/web2-json-config';
20-
import {
21-
database,
22-
typeOrmModulePartialOptions,
23-
} from './defaults/indexer-config';
20+
import { getDatabaseConfig } from './defaults/indexer-config';
2421
import { IConfig, VerifierServerConfig } from './interfaces/common';
2522
import { Web2JsonConfig, Web2JsonSource } from './interfaces/web2-json';
2623
import { WEB2_JSON_TEST_SOURCES } from './web2/web2-json-test-sources';
@@ -146,11 +143,19 @@ function getIndexerConfig(verifierType: ChainType): IndexerConfig {
146143
case ChainType.DOGE:
147144
case ChainType.XRP: {
148145
const entities = getDatabaseEntities(verifierType);
146+
const databaseConfig = getDatabaseConfig();
147+
const typeOrmModulePartialOptions: TypeOrmModuleOptions = {
148+
...databaseConfig,
149+
type: 'postgres',
150+
synchronize: false,
151+
migrationsRun: false,
152+
logging: false,
153+
};
149154
const typeOrmModuleOptions: TypeOrmModuleOptions = {
150155
...typeOrmModulePartialOptions,
151156
entities,
152157
};
153-
return { db: database, typeOrmModuleOptions };
158+
return { db: databaseConfig, typeOrmModuleOptions };
154159
}
155160
case ChainType.Web2:
156161
throw new Error('Web2 verifier does not use indexer config');
Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
1+
import { DatabaseConfig } from '../interfaces/chain-indexer';
22

3-
export const database = {
4-
database: process.env.DB_DATABASE || 'database',
5-
host: process.env.DB_HOST || '127.0.0.1',
6-
port: parseInt(process.env.DB_PORT) || 8080,
7-
username: process.env.DB_USERNAME || 'username',
8-
password: process.env.DB_PASSWORD || 'password',
9-
};
10-
export const typeOrmModulePartialOptions: TypeOrmModuleOptions = {
11-
...database,
12-
type: 'postgres',
13-
synchronize: false,
14-
migrationsRun: false,
15-
logging: false,
16-
};
3+
export function getDatabaseConfig(): DatabaseConfig {
4+
return {
5+
database: process.env.DB_DATABASE || 'database',
6+
host: process.env.DB_HOST || '127.0.0.1',
7+
port: parseInt(process.env.DB_PORT) || 8080,
8+
username: process.env.DB_USERNAME || 'username',
9+
password: process.env.DB_PASSWORD || 'password',
10+
};
11+
}

0 commit comments

Comments
 (0)