# Spec Kit Component: database

> For the complete documentation index, see [llms.txt](https://deploy-preview-472--lucky-concha-f3599f.netlify.app/llms.txt).

## Responsibilities

*   Host H2 database runtime for baseline services.
*   Provide seeded account, trade, position, and account-user data.
*   Expose TCP/PG/Web console ports for service access and local inspection.

## Covered Flows

*   `STARTUP`
*   [`F4`](https://deploy-preview-472--lucky-concha-f3599f.netlify.app/specs/baseline-uncontainerized-parity/system/end-to-end-flows.md#f4-process-trade-events) (persistence for trade processing)
*   [`F5`](https://deploy-preview-472--lucky-concha-f3599f.netlify.app/specs/baseline-uncontainerized-parity/system/end-to-end-flows.md#f5-addupdate-account) and [`F6`](https://deploy-preview-472--lucky-concha-f3599f.netlify.app/specs/baseline-uncontainerized-parity/system/end-to-end-flows.md#f6-addupdate-account-users) (account and account-user persistence)

## Requirement Coverage

*   [`SYS-FR-001`](https://deploy-preview-472--lucky-concha-f3599f.netlify.app/specs/baseline-uncontainerized-parity/system/system-requirements.md), [`SYS-FR-007`](https://deploy-preview-472--lucky-concha-f3599f.netlify.app/specs/baseline-uncontainerized-parity/system/system-requirements.md)
*   [`SYS-NFR-002`](https://deploy-preview-472--lucky-concha-f3599f.netlify.app/specs/baseline-uncontainerized-parity/system/system-requirements.md), [`SYS-NFR-004`](https://deploy-preview-472--lucky-concha-f3599f.netlify.app/specs/baseline-uncontainerized-parity/system/system-requirements.md)

## Verification

*   `scripts/test-database-overlay.sh`

## Connection retirement and existing databases (#461)

The H2 schema uses CASE for Trades.Side/State and OrderBook.Side/Status checks. Do not regenerate literal IN-list checks: H2 2.4.240 can retain the closed schema session's comparator. Invalid values must still fail and NULL remains allowed. `templates/database-specfirst/src/test/java/SchemaConnectionRetirementTest.java` executes the canonical schema and validates all allowed values after creator closure. Existing persistent databases require a backed-up constraint migration; regeneration alone does not alter their constraints. Never run the destructive initial schema to repair an existing database. See `docs/operations/h2-booking-constraint-migration.md`.
