79 lines
5.3 KiB
Markdown
79 lines
5.3 KiB
Markdown
# CL02 — Normalize database configuration once and enforce consistent service switches
|
|
|
|
Parent epic: E10. Priority/severity: P1 / High. Complexity: M. Specialization: TypeScript configuration and database adapters.
|
|
|
|
Scheduling metadata: [manifest](../manifest.json). Read the [cleanup execution contract](../../CLEANUP.md#execution-contract). Implementation and validated commits were authorized after planning; scheduling and completion evidence live in the manifest.
|
|
|
|
## User story and outcome
|
|
|
|
As a developer, I want my connection settings and explicit service-disable choices to reach the intended clients unchanged, so configuration cannot silently enable services or discard settings.
|
|
|
|
Expected benefit: Addresses a reproduced enable/disable defect and the same multi-stage mapping pattern that caused the QuestDB credential failure.
|
|
|
|
## Verified evidence
|
|
|
|
- **Verified — CL-F01:** An isolated probe with supplied enabled configurations and all three enable options false still resolves enabled PostgreSQL, MongoDB and cache configurations. [libs/core/di/src/container/builder.ts:88](../../../../libs/core/di/src/container/builder.ts#L88).
|
|
- **Verified — CL-F01:** The canonical PostgreSQL schema accepts SSL, pool size and timeouts, while the DI schema and registration omit them. [libs/core/config/src/schemas/database.schema.ts:4](../../../../libs/core/config/src/schemas/database.schema.ts#L4).
|
|
- **Verified — CL-F01:** Client registration reconstructs only part of the accepted PostgreSQL configuration. [libs/core/di/src/registrations/database.registration.ts:43](../../../../libs/core/di/src/registrations/database.registration.ts#L43).
|
|
|
|
## Implementation scope
|
|
|
|
- Use the existing core configuration schemas as the canonical database representation; keep compatibility aliases in a single boundary adapter rather than multiple reconstruction passes.
|
|
- Define consistent precedence: an explicit service option false disables that service; true permits but does not override an explicitly disabled configured service. Preserve documented defaults when neither is specified.
|
|
- Carry supported credentials, SSL, pool and timeout settings into client-specific configuration, including explicit ilpPort/influxPort translation. Audit accepted fields for silent loss and document supported mappings.
|
|
- Add real-path tests with distinctive nondefault values for each store. Update configuration types and DI registration together.
|
|
|
|
Likely existing files/modules:
|
|
|
|
- `libs/core/config/src/schemas/database.schema.ts`
|
|
- `libs/core/config/src/schemas/unified-app.schema.ts`
|
|
- `libs/core/di/src/config/schemas/`
|
|
- `libs/core/di/src/container/builder.ts`
|
|
- `libs/core/di/src/registrations/database.registration.ts`
|
|
- `libs/core/di/src/registrations/cache.registration.ts`
|
|
- `test/integration/questdb-configuration.test.ts`
|
|
- `libs/core/di/test/container-builder.test.ts`
|
|
|
|
Proposed new files/modules (names may be adjusted within this scope):
|
|
|
|
- `test/integration/store-configuration.test.ts`
|
|
|
|
## Exclusions
|
|
|
|
- No credential rotation, environment-file deletion, new configuration framework or database replacement.
|
|
- No connection to development trading state in automated tests; no financial-policy changes.
|
|
|
|
## Dependencies and ownership
|
|
|
|
Implementation prerequisites: [CL01](CL01.md).
|
|
|
|
Write locks: `di-configuration`, `di-container`, `di-builder-tests`.
|
|
|
|
Parallel execution: After CL01. Must be serialized with CL03 because both can edit container/builder.ts; this is an actual-file lock, not an additional code dependency.
|
|
|
|
## Acceptance criteria
|
|
|
|
1. The audit probe with configured stores enabled and explicit options false resolves disabled/null PostgreSQL, MongoDB and cache services without opening sockets.
|
|
2. Configured enabled=false remains disabled when the corresponding service option is true.
|
|
3. Nondefault PostgreSQL SSL, pool size and connection/idle timeouts reach final wire settings; QuestDB credentials and ports retain their existing regression guarantees.
|
|
4. Each supported database field has one explicit translation to the client representation; no accepted setting silently disappears during schema conversion.
|
|
5. Existing nested and flat configuration callers remain compatible, including intentional precedence when both appear.
|
|
|
|
## Mandatory verification
|
|
|
|
store-configuration.test.ts is a proposed new test file. Capture real client/wire configuration without connecting to stores; substitute external transports only where necessary.
|
|
|
|
```sh
|
|
bun run --cwd libs/core/di build
|
|
bun test libs/core/di/test/container-builder.test.ts
|
|
bun test test/integration/store-configuration.test.ts test/integration/questdb-configuration.test.ts
|
|
bun run typecheck
|
|
```
|
|
|
|
Required regression cases: all explicit disable switches, configured disable with option true, absent defaults, nested/flat precedence, optional credentials, SSL and nondefault pool/timeouts.
|
|
|
|
## Risks and definition of done
|
|
|
|
Configuration precedence and client SSL representations differ today. Preserve existing defaults, reject unsupported combinations explicitly, and do not make a broad strict-schema change that rejects unrelated process environment variables.
|
|
|
|
Done means the acceptance criteria and relevant checks pass, an independent review accepts the focused diff, and the integrator records exact test results and a commit/reference in the manifest. Preserve the compatibility and financial invariants in the cleanup execution contract.
|