Skip to content

Commit 0f57172

Browse files
chore(runtime): update env/bootstrap, db logging, and platform wiring
1 parent 9d4ddfa commit 0f57172

15 files changed

Lines changed: 79 additions & 138 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,6 @@ report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
5757
# Sensitive / secrets (override earlier negation)
5858
.vscode/settings.json
5959
google-service-account-key.json
60+
google-services.json
61+
62+
bak/

docker-entrypoint.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@ export NODE_ENV=${NODE_ENV:-production}
1616
DB_HOST=${DATABASE_HOST:-db}
1717
DB_PORT=${DATABASE_PORT:-5432}
1818

19+
# If DATABASE_URL isn't set (some deploys set DB_* vars only), build it here
20+
if [ -z "$DATABASE_URL" ]; then
21+
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DB_HOST}:${DB_PORT}/${POSTGRES_DB}?schema=${DB_SCHEMA:-public}"
22+
echo "[ENTRYPOINT] Built DATABASE_URL from components"
23+
fi
24+
25+
# If SHADOW_DATABASE_URL isn't set, build a shadow DB url next to the main DB
26+
if [ -z "$SHADOW_DATABASE_URL" ]; then
27+
export SHADOW_DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DB_HOST}:${DB_PORT}/${POSTGRES_DB}_shadow?schema=${DB_SCHEMA:-public}"
28+
echo "[ENTRYPOINT] Built SHADOW_DATABASE_URL from components"
29+
fi
30+
1931
# Colors for output
2032
RED='\033[0;31m'
2133
GREEN='\033[0;32m'
@@ -38,7 +50,13 @@ echo -e "${GREEN}✅ Database is ready.${NC}"
3850
# 'prisma migrate deploy' is the command intended for production/CI/CD environments.
3951
# It applies pending migrations without generating new ones.
4052
echo -e "${YELLOW}🔄 Running database migrations...${NC}"
41-
npx prisma migrate deploy
53+
echo "[ENTRYPOINT] Working dir: $(pwd)"
54+
echo "[ENTRYPOINT] Prisma schema file: ./prisma/schema.prisma"
55+
echo "[ENTRYPOINT] Environment:"
56+
env | grep -E "(DATABASE|POSTGRES|DB)" || true
57+
58+
# Explicitly pass the schema path to avoid ambiguity and help debugging
59+
npx prisma migrate deploy --schema=./prisma/schema.prisma
4260

4361
echo -e "${GREEN}✅ Migrations complete.${NC}"
4462

src/app.module.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
//import { GraphQLModule } from '@nestjs/graphql';
21
import { Logger, MiddlewareConsumer, Module, RequestMethod } from '@nestjs/common';
3-
import { ConfigModule } from './common/configs/config.module';
2+
import { ConfigModule } from '@nestjs/config';
43
import { PrismaModule } from 'nestjs-prisma';
54
import { AppService } from './app.service';
65
//import config from './common/configs/config';
@@ -23,9 +22,6 @@ import { SentryModule } from '@sentry/nestjs/setup';
2322
//import { ConfigModule } from '@nestjs/config';
2423
// import { UserModule } from './users/user.module';
2524

26-
//import { AppResolver } from './app.resolver';
27-
//import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo';
28-
//import { GqlConfigService } from './gql-config.service';
2925
// import { AllowedBlockchainsGuard } from './blockchains/allowed-blockchains.guard';
3026
//import { OpenTelemetryModule } from '@metinseylan/nestjs-opentelemetry';
3127
//import { RedisModule } from './redis/redis.module';
@@ -40,14 +36,18 @@ import { SentryModule } from '@sentry/nestjs/setup';
4036
// },
4137
// },
4238
// });
39+
console.log('DEBUG ENVIRONMENT:', process.env.NODE_ENV);
4340

4441
@Module({
4542
imports: [
4643
SentryModule.forRoot(),
4744
// Setup NestJS open telemetry auto instrumentation. This requires the configuration
4845
// to be passed in again for some features (e.g. metrics) to work correctly.
4946
//OpenTelemetryModule.forRoot(openTelemetryConfig),
50-
ConfigModule,
47+
ConfigModule.forRoot({
48+
isGlobal: true,
49+
envFilePath: process.env.NODE_ENV === 'local' ? '.env.local' : '.env',
50+
}),
5151
//ConfigModule.forRoot({ isGlobal: true, load: [config] }),
5252
//LoggerModule,
5353
//OpenTelemetryModuleConfig,
@@ -71,11 +71,6 @@ import { SentryModule } from '@sentry/nestjs/setup';
7171
} as any,
7272
}),
7373

74-
// GraphQLModule.forRootAsync<ApolloDriverConfig>({
75-
// driver: ApolloDriver,
76-
// useClass: GqlConfigService,
77-
// }),
78-
7974
AppRouterModule,
8075
CloudflareKvModule,
8176
CommonModule,

src/common/configs/config.helper.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ export function loadConfig() {
3636

3737
const dotenvConfig = dotenv.parse(file);
3838

39-
// Inject parsed values into process.env if not already present so the rest of the
40-
// application (e.g. main.ts reading process.env.PORT) sees them.
39+
// Inject parsed values into process.env. Values from the selected env file
40+
// OVERRIDE existing process.env values to ensure .env.local takes precedence
41+
// over .env (which Prisma/dotenv may have auto-loaded).
4142
for (const [k, v] of Object.entries(dotenvConfig)) {
42-
if (process.env[k] === undefined) {
43-
process.env[k] = v;
44-
}
43+
process.env[k] = v;
4544
}
4645

4746
if (!process.env.ENV_FILE_LOGGED) {

src/common/configs/config.interface.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ export interface Config {
22
nest: NestConfig;
33
cors: CorsConfig;
44
swagger: SwaggerConfig;
5-
graphql: GraphqlConfig;
65
security: SecurityConfig;
76
}
87

@@ -22,13 +21,6 @@ export interface SwaggerConfig {
2221
path: string;
2322
}
2423

25-
export interface GraphqlConfig {
26-
playgroundEnabled: boolean;
27-
debug: boolean;
28-
schemaDestination: string;
29-
sortSchema: boolean;
30-
}
31-
3224
export interface SecurityConfig {
3325
expiresIn: string;
3426
refreshIn: string;
@@ -39,7 +31,6 @@ export interface ApplicationConfig {
3931
nest: NestConfig;
4032
cors: CorsConfig;
4133
swagger: SwaggerConfig;
42-
graphql: GraphqlConfig;
4334
security: SecurityConfig;
4435

4536
SERVICE_NAME: string;
@@ -90,3 +81,8 @@ export interface ApplicationConfig {
9081
EDGE_KV_URL: string;
9182
EDGE_KV_AUTHORIZATION_TOKEN: string;
9283
}
84+
85+
export interface UnflattenApplicationConfig {
86+
name: string;
87+
children: string[];
88+
}

src/common/configs/unflatten-keys.model.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/common/database/database.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class DatabaseService extends PrismaClient implements OnModuleInit, OnMod
6565
await (this as any).$connect();
6666

6767
this.logger.info(
68-
`Connected to ${prismaEngine.activeProvider} instance using Prisma v${prismaEngine.clientVersion} ${this.configService.get('DATABASE_URL')}`
68+
`Connected to ${prismaEngine.activeProvider} instance using Prisma v${prismaEngine.clientVersion} ${this.configService.get('DATABASE_URL').replace(/:[^:]*@/, ':***@')}}`
6969
);
7070

7171
// Enable this when you really need to see the SQL / params

src/common/database/mongo-database.service.ts

Lines changed: 0 additions & 92 deletions
This file was deleted.

src/common/redis/redis.providers.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ function redisFactory(redis: RedisService, prefix: string, cfg: ConfigService):
4242
}),
4343
} as const;
4444

45-
console.log(server.port, server.host, redisOptions);
4645
redis.client = new IORedis(server.port, server.host, redisOptions);
4746

4847
redis.client.on('connect', () => {
@@ -126,7 +125,7 @@ export const redisProviders: Provider[] = [
126125
const options: any = {
127126
host,
128127
port,
129-
...(password ? { password } : {}),
128+
...(password && password.length > 0 ? { password } : {}),
130129
...(useTls ? { tls: { servername: host } } : {}),
131130
};
132131
return new IORedis(options);
@@ -143,7 +142,7 @@ export const redisProviders: Provider[] = [
143142
const options: any = {
144143
host,
145144
port,
146-
...(password ? { password } : {}),
145+
...(password && password.length > 0 ? { password } : {}),
147146
...(useTls ? { tls: { servername: host } } : {}),
148147
};
149148
return new IORedis(options);

src/common/redis/redis.service.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ export interface IRedisSubscribeMessage {
1111
readonly channel: string;
1212
}
1313

14-
function capitalize(s: string) {
15-
return s[0].toUpperCase() + s.slice(1);
16-
}
17-
1814
@Injectable({ scope: Scope.TRANSIENT })
1915
export class RedisService /* implements OnModuleInit, OnModuleDestroy */ {
2016
public prefix?: string;

0 commit comments

Comments
 (0)