[P0] F03: Wire PostgreSQL migrations, bounded pooling and canonical repositories #8

Closed
opened 2026-10-21 20:29:23 +02:00 by amiryahaya · 1 comment
Owner

Backlog ID: F03 | Priority: P0 | Phase: M1 — Secure build and persistence foundation

Outcome and scope

Integrate migration execution and SQLx repository boundaries with bounded pools. Audit the initial conversation/message/audit/outbox schema and add incremental migrations for missing invariants.

Dependencies and gates

Engineering prerequisites: #6 (F01), #7 (F02)

Synthetic-data development may proceed. Production use remains subject to the decision gates in the SRS.

Starting points

migrations/0001_initial.sql; crates/storage-postgres/; crates/api/src/

These are current files or proposed responsibility boundaries; finalize a focused implementation plan before coding. Existing local scaffolding is uncommitted and is not evidence of completion.

Acceptance criteria

  • Empty supported PostgreSQL initializes repeatably and migration failure prevents readiness; applied migration integrity is verified.

  • Pool limits, acquisition timeouts and graceful shutdown are explicit; database rows stay behind domain-owned repository interfaces.

  • Conversation ownership/scope and unique message ordering are enforced transactionally; recent-history query plans use bounded indexed reads.

  • Production database roles are least privilege; document RLS defense-in-depth and prove the selected role cannot bypass intended policies if enabled.

  • Application-generated identifiers use UUIDv7 throughout (FR-DATA-006); PostgreSQL stores UUID-valued entity IDs and UUID-only references natively and migration preserves existing IDs.

Verification

Run real-PostgreSQL integration tests for fresh/repeated migration, concurrent message sequence allocation, ownership isolation, transaction rollback and pool exhaustion.

Behavior changes follow Red → Green → Refactor. Run affected Rust shared contract/unit tests and real PostgreSQL/Qdrant/runtime integration tests where applicable; frontend changes run typecheck/build and the relevant browser tests. Record exact commands/results in the implementation PR. Documentation/decision tasks use recorded review evidence.

Requirements and design

FR-DATA-001, FR-DATA-006; NFR-MAINT-005; architecture §§3, 7; implementation plan increment A

Sources: SRS, system design. Local planning context: docs/implementation-plan.md and docs/development-backlog.md (not published by this task).

Security impact: Use synthetic fixtures until approved for operational data. Preserve current authorization, markings, provenance and default-deny behavior; exclude protected payloads/secrets from operational telemetry. No classified-deployment or PQC-compliance claim is implied by closing this issue.

Parent roadmap: #1

Additional user specification: NFR-MAINT-007 sets an 80% line-coverage minimum with explained shortfalls. Rust application-only coverage is 87.29%; frontend coverage is unmeasured because the scaffold has no behavior-test/coverage tooling. The concrete reason, risk and P0 #40 remediation are recorded in docs/verification/2026-10-22-coverage.md; CI coverage enforcement is tracked in #40.

**Backlog ID:** F03 | **Priority:** P0 | **Phase:** M1 — Secure build and persistence foundation ## Outcome and scope Integrate migration execution and SQLx repository boundaries with bounded pools. Audit the initial conversation/message/audit/outbox schema and add incremental migrations for missing invariants. ## Dependencies and gates **Engineering prerequisites:** #6 (F01), #7 (F02) Synthetic-data development may proceed. Production use remains subject to the decision gates in the SRS. ## Starting points migrations/0001_initial.sql; crates/storage-postgres/; crates/api/src/ These are current files or proposed responsibility boundaries; finalize a focused implementation plan before coding. Existing local scaffolding is uncommitted and is not evidence of completion. ## Acceptance criteria - [x] Empty supported PostgreSQL initializes repeatably and migration failure prevents readiness; applied migration integrity is verified. - [x] Pool limits, acquisition timeouts and graceful shutdown are explicit; database rows stay behind domain-owned repository interfaces. - [x] Conversation ownership/scope and unique message ordering are enforced transactionally; recent-history query plans use bounded indexed reads. - [x] Production database roles are least privilege; document RLS defense-in-depth and prove the selected role cannot bypass intended policies if enabled. - [x] Application-generated identifiers use UUIDv7 throughout (FR-DATA-006); PostgreSQL stores UUID-valued entity IDs and UUID-only references natively and migration preserves existing IDs. ## Verification Run real-PostgreSQL integration tests for fresh/repeated migration, concurrent message sequence allocation, ownership isolation, transaction rollback and pool exhaustion. Behavior changes follow Red → Green → Refactor. Run affected Rust shared contract/unit tests and real PostgreSQL/Qdrant/runtime integration tests where applicable; frontend changes run typecheck/build and the relevant browser tests. Record exact commands/results in the implementation PR. Documentation/decision tasks use recorded review evidence. ## Requirements and design FR-DATA-001, FR-DATA-006; NFR-MAINT-005; architecture §§3, 7; implementation plan increment A Sources: [SRS](https://forgejo.primatekun.tech/primatekuntech/rag-rust/src/branch/main/docs/SRS.md), [system design](https://forgejo.primatekun.tech/primatekuntech/rag-rust/src/branch/main/docs/architecture.md). Local planning context: `docs/implementation-plan.md` and `docs/development-backlog.md` (not published by this task). **Security impact:** Use synthetic fixtures until approved for operational data. Preserve current authorization, markings, provenance and default-deny behavior; exclude protected payloads/secrets from operational telemetry. No classified-deployment or PQC-compliance claim is implied by closing this issue. **Parent roadmap:** #1 **Additional user specification:** NFR-MAINT-007 sets an 80% line-coverage minimum with explained shortfalls. Rust application-only coverage is 87.29%; frontend coverage is unmeasured because the scaffold has no behavior-test/coverage tooling. The concrete reason, risk and P0 #40 remediation are recorded in `docs/verification/2026-10-22-coverage.md`; CI coverage enforcement is tracked in #40.
Author
Owner

Implemented in draft PR #39 at e12e70a78a209359f0da985336f26d4b6930b478; leaving this issue open pending review/merge.

  • Separate migration CLI and restricted runtime identity; embedded migration/checksum verification before startup; original migration 0001 unchanged.
  • Domain-owned repository contracts, bounded pool/probes/shutdown, transactional owner/org scope, atomic message ordering and indexed bounded history. FORCE RLS hides inactive/foreign rows. Exact parent marking/policy version required initially.
  • Review findings fixed with red/green regressions: startup now rejects destructive table privileges, predefined-role membership and database CREATE/TEMPORARY.
  • cargo fmt --all -- --check, workspace Clippy with -D warnings, workspace tests (20 behavioral + 6 compile-fail doctests), bash scripts/test-postgres.sh --local (14 real PostgreSQL tests), frontend typecheck/build, Compose and normalized actionlint all passed.
  • Built-process smoke verified startup rejection before migrations, separate migration CLI success, live/ready HTTP 200 and clean SIGTERM exit.
  • Hosted CI passed including PostgreSQL contracts: branch run 17, PR run 18.

Owner selectors remain internal query scope; trusted identity/ABAC and chat endpoints are subsequent issues. Existing deployments must follow docs/operations/postgres.md for bootstrap and migration review.

CI provisioning runs PostgreSQL 17 inside each isolated job container over loopback. Pinned runner source confirmed missing service-port context and ignored workflow host mappings; the original bridge-network approach was replaced. No shared runner settings or fixed host ports are changed.

User-requested UUIDv7 standard (FR-DATA-006) is in specs and implementation, with forward migration 0003 and legacy ID/reference preservation. User-requested 80% line coverage (NFR-MAINT-007) is in specs; Rust is 87.29% (632/724 application lines), with a recorded unmeasured frontend shortfall because instrumentation is absent. P0 #40 addresses frontend tests and CI enforcement; report/reason/risk/remediation are committed in docs/verification/2026-10-22-coverage.md. No frontend coverage compliance claim is made.

Implemented in draft PR #39 at `e12e70a78a209359f0da985336f26d4b6930b478`; leaving this issue open pending review/merge. - Separate migration CLI and restricted runtime identity; embedded migration/checksum verification before startup; original migration 0001 unchanged. - Domain-owned repository contracts, bounded pool/probes/shutdown, transactional owner/org scope, atomic message ordering and indexed bounded history. FORCE RLS hides inactive/foreign rows. Exact parent marking/policy version required initially. - Review findings fixed with red/green regressions: startup now rejects destructive table privileges, predefined-role membership and database CREATE/TEMPORARY. - `cargo fmt --all -- --check`, workspace Clippy with `-D warnings`, workspace tests (20 behavioral + 6 compile-fail doctests), `bash scripts/test-postgres.sh --local` (14 real PostgreSQL tests), frontend typecheck/build, Compose and normalized actionlint all passed. - Built-process smoke verified startup rejection before migrations, separate migration CLI success, live/ready HTTP 200 and clean SIGTERM exit. - Hosted CI passed including PostgreSQL contracts: [branch run 17](https://forgejo.primatekun.tech/primatekuntech/rag-rust/actions/runs/17), [PR run 18](https://forgejo.primatekun.tech/primatekuntech/rag-rust/actions/runs/18). Owner selectors remain internal query scope; trusted identity/ABAC and chat endpoints are subsequent issues. Existing deployments must follow `docs/operations/postgres.md` for bootstrap and migration review. CI provisioning runs PostgreSQL 17 inside each isolated job container over loopback. Pinned runner source confirmed missing service-port context and ignored workflow host mappings; the original bridge-network approach was replaced. No shared runner settings or fixed host ports are changed. User-requested UUIDv7 standard (FR-DATA-006) is in specs and implementation, with forward migration 0003 and legacy ID/reference preservation. User-requested 80% line coverage (NFR-MAINT-007) is in specs; Rust is 87.29% (632/724 application lines), with a recorded unmeasured frontend shortfall because instrumentation is absent. P0 #40 addresses frontend tests and CI enforcement; report/reason/risk/remediation are committed in `docs/verification/2026-10-22-coverage.md`. No frontend coverage compliance claim is made.
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
primatekuntech/rag-rust#8
No description provided.