Skip to content

Commit 388f1e3

Browse files
committed
reconcile missing 6.4 commits before cutting 6.5
1 parent 93dde07 commit 388f1e3

4 files changed

Lines changed: 358 additions & 4 deletions

File tree

.github/workflows/clientlibs-js-publish.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525
uses: actions/checkout@v6
2626
with:
2727
ref: ${{ inputs.ref || github.sha }}
28+
- uses: actions/setup-node@v4
29+
ref: ${{ inputs.ref || github.sha }}
2830
- uses: actions/setup-node@v4
2931
with:
3032
node-version: 22
@@ -38,4 +40,4 @@ jobs:
3840
run: yarn build
3941
- name: Publish upgrade_client_lib
4042
run: npm publish
41-
working-directory: clientlibs/js/package.json
43+
working-directory: clientlibs/js/package.json

clientlibs/js/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,4 @@
7777
"axios": "^1.4.0"
7878
}
7979
}
80+

packages/backend/src/loaders/typeormLoader.ts

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,36 @@ import { CONNECTION_NAME } from './enums';
66
import { PostgresConnectionCredentialsOptions } from 'typeorm/driver/postgres/PostgresConnectionCredentialsOptions';
77
import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions.js';
88
import { Container as tteContainer } from '../typeorm-typedi-extensions';
9+
import { UpgradeLogger } from '../lib/logger/UpgradeLogger';
910

10-
const replicaHosts = (env.db.host_replica ? JSON.parse(env.db.host_replica) : []) as string[];
11+
const log = new UpgradeLogger();
12+
13+
export const parseReplicaHosts = (hostReplica?: string | null): string[] => {
14+
if (!hostReplica) {
15+
return [];
16+
}
17+
18+
try {
19+
const parsedHosts = JSON.parse(hostReplica) as unknown;
20+
if (Array.isArray(parsedHosts) && parsedHosts.every((host) => typeof host === 'string')) {
21+
return parsedHosts;
22+
}
23+
24+
log.error({
25+
message: 'Invalid read replica host list format — continuing without replica hosts',
26+
error: new Error('host_replica must be a JSON string array'),
27+
});
28+
return [];
29+
} catch (error) {
30+
log.error({
31+
message: 'Invalid read replica host configuration — continuing without replica hosts',
32+
error,
33+
});
34+
return [];
35+
}
36+
};
37+
38+
const replicaHosts = parseReplicaHosts(env.db.host_replica);
1139

1240
const masterHost: PostgresConnectionCredentialsOptions = {
1341
host: env.db.host,
@@ -71,7 +99,12 @@ export const typeormLoader: MicroframeworkLoader = async (settings: Microframewo
7199

72100
// register the data source instance in the typeorm-typeDI-extensions
73101
tteContainer.setDataSource(CONNECTION_NAME.REPLICA, exportDataSourceInstance);
74-
await Promise.all([appDataSourceInstance.initialize(), exportDataSourceInstance.initialize()]);
102+
await appDataSourceInstance.initialize();
103+
104+
// Fire-and-forget replica init so a slow/unreachable replica doesn't block app startup.
105+
void exportDataSourceInstance.initialize().catch((replicaErr) => {
106+
log.error({ message: 'Read replica connection failed — continuing without replica', error: replicaErr });
107+
});
75108

76109
if (!env.db.synchronize && !env.isECS) {
77110
await appDataSourceInstance.runMigrations();
@@ -86,8 +119,8 @@ export const typeormLoader: MicroframeworkLoader = async (settings: Microframewo
86119
});
87120
}
88121
} catch (err) {
89-
// TODO: use logger to log the error
90122
const error = err as any;
123+
log.error({ message: 'Database connection failed', error });
91124
if (error.code === 'ECONNREFUSED') {
92125
error.type = SERVER_ERROR.DB_UNREACHABLE;
93126
throw error;

0 commit comments

Comments
 (0)