chore: code review comments
This commit is contained in:
@@ -47,7 +47,7 @@ export const initDrizzle = ({
|
||||
maxConnections?: number;
|
||||
replica?: boolean;
|
||||
/** Connect timeout in seconds */
|
||||
connectTimeout?: number;
|
||||
connectTimeout?: number | null;
|
||||
poolConfig?: PoolConfig;
|
||||
} = {}) => {
|
||||
const dbUrl =
|
||||
@@ -59,7 +59,7 @@ export const initDrizzle = ({
|
||||
...poolConfig,
|
||||
max: maxConnections,
|
||||
connectionTimeoutMillis:
|
||||
connectTimeout === undefined ? undefined : connectTimeout * 1000,
|
||||
connectTimeout === null ? undefined : connectTimeout * 1000,
|
||||
});
|
||||
|
||||
const drizzleDb = drizzle(client, { schema });
|
||||
@@ -98,7 +98,7 @@ export const { db: dbGeneral, client: clientGeneral } = initDrizzle({
|
||||
// -- Replica pool: used as fallback when primary is degraded --
|
||||
// Only created if DATABASE_REPLICA_URL is configured.
|
||||
const replicaResult = process.env.DATABASE_REPLICA_URL
|
||||
? initDrizzle({ replica: true, maxConnections: 5, connectTimeout: undefined })
|
||||
? initDrizzle({ replica: true, maxConnections: 5, connectTimeout: null })
|
||||
: null;
|
||||
export const dbReplica = replicaResult?.db ?? null;
|
||||
export const clientReplica = replicaResult?.client ?? null;
|
||||
|
||||
@@ -59,10 +59,7 @@ export class MigrationService {
|
||||
const lockResult = await txDb.execute<{ acquired: boolean }>(
|
||||
sql`SELECT pg_try_advisory_xact_lock(${lockId}) as acquired`,
|
||||
);
|
||||
const lockRows = Array.isArray(lockResult)
|
||||
? lockResult
|
||||
: (lockResult as any).rows;
|
||||
const lockAcquired = lockRows[0]?.acquired;
|
||||
const lockAcquired = lockResult[0]?.acquired;
|
||||
|
||||
if (!lockAcquired) {
|
||||
throw new RecaseError({
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import net from "node:net";
|
||||
import { afterAll, expect, test } from "bun:test";
|
||||
import { expect, test } from "bun:test";
|
||||
import { sql } from "drizzle-orm";
|
||||
import { assertNotProductionDb } from "@/db/dbUtils.js";
|
||||
import {
|
||||
client,
|
||||
clientCritical,
|
||||
dbCritical,
|
||||
dbGeneral,
|
||||
@@ -55,9 +54,7 @@ test("db connect timeout fails fast when postgres accepts tcp but never responds
|
||||
const startedAt = Date.now();
|
||||
|
||||
try {
|
||||
await expect(deadClient.query("SELECT 1")).rejects.toThrow(
|
||||
/connection timeout/i,
|
||||
);
|
||||
await expect(deadClient.query("SELECT 1")).rejects.toThrow(/timeout/i);
|
||||
|
||||
expect(Date.now() - startedAt).toBeLessThan(2_000);
|
||||
} finally {
|
||||
@@ -68,7 +65,3 @@ test("db connect timeout fails fast when postgres accepts tcp but never responds
|
||||
});
|
||||
}
|
||||
}, 5_000);
|
||||
|
||||
afterAll(async () => {
|
||||
await Promise.all([client.end(), clientCritical.end()]);
|
||||
});
|
||||
|
||||
@@ -60,9 +60,11 @@ test.concurrent(`${chalk.yellowBright("get-customer: multi-entity customer retur
|
||||
const cusV1 = await autumnV1.customers.get<ApiCustomerV3>(customerId);
|
||||
ApiCustomerV3Schema.parse(cusV1);
|
||||
expect(cusV1.products.length).toBeGreaterThan(0);
|
||||
const cusV1Prod = cusV1.products[0];
|
||||
expect(cusV1Prod.current_period_start).toBeNumber();
|
||||
expect(cusV1Prod.current_period_end).toBeNumber();
|
||||
const cusV1Prod = cusV1.products.find(
|
||||
(product) => product.id === cusLevelProd.id,
|
||||
);
|
||||
expect(cusV1Prod?.current_period_start).toBeNumber();
|
||||
expect(cusV1Prod?.current_period_end).toBeNumber();
|
||||
expect(cusV1.features[TestFeature.Messages]).toMatchObject({
|
||||
id: TestFeature.Messages,
|
||||
balance: 90,
|
||||
@@ -79,9 +81,11 @@ test.concurrent(`${chalk.yellowBright("get-customer: multi-entity customer retur
|
||||
});
|
||||
ApiCustomerV5Schema.parse(cusV2_1);
|
||||
expect(cusV2_1.subscriptions.length).toBeGreaterThan(0);
|
||||
const cusV2_1Sub = cusV2_1.subscriptions[0];
|
||||
expect(cusV2_1Sub.current_period_start).toBeNumber();
|
||||
expect(cusV2_1Sub.current_period_end).toBeNumber();
|
||||
const cusV2_1Sub = cusV2_1.subscriptions.find(
|
||||
(subscription) => subscription.plan_id === cusLevelProd.id,
|
||||
);
|
||||
expect(cusV2_1Sub?.current_period_start).toBeNumber();
|
||||
expect(cusV2_1Sub?.current_period_end).toBeNumber();
|
||||
expectFlagCorrect({
|
||||
customer: cusV2_1,
|
||||
featureId: TestFeature.Dashboard,
|
||||
@@ -103,9 +107,11 @@ test.concurrent(`${chalk.yellowBright("get-customer: multi-entity customer retur
|
||||
});
|
||||
ApiCustomerV5Schema.parse(cusV2_2);
|
||||
expect(cusV2_2.subscriptions.length).toBeGreaterThan(0);
|
||||
const cusV2_2Sub = cusV2_2.subscriptions[0];
|
||||
expect(cusV2_2Sub.current_period_start).toBeNumber();
|
||||
expect(cusV2_2Sub.current_period_end).toBeNumber();
|
||||
const cusV2_2Sub = cusV2_2.subscriptions.find(
|
||||
(subscription) => subscription.plan_id === cusLevelProd.id,
|
||||
);
|
||||
expect(cusV2_2Sub?.current_period_start).toBeNumber();
|
||||
expect(cusV2_2Sub?.current_period_end).toBeNumber();
|
||||
expectFlagCorrect({
|
||||
customer: cusV2_2,
|
||||
featureId: TestFeature.Dashboard,
|
||||
|
||||
Reference in New Issue
Block a user