# Persistence and data ownership One fresh B PostgreSQL database contains profile and observations schemas. Each has a separate NOLOGIN owner and schema_version table; installed runtime credentials have DML and metadata-read permissions, not schema ownership or DDL privileges. Analytics, Overview and Guidance own no database tables. ```mermaid erDiagram PROFILE_PATIENT ||--o{ OBSERVATIONS_OBSERVATION : "patient_id FK (RESTRICT)" PROFILE_PATIENT { uuid patient_id PK text account_id UK varchar name date date_of_birth varchar contact_info timestamp created_at timestamp updated_at } OBSERVATIONS_OBSERVATION { uuid observation_id PK uuid patient_id FK timestamp measured_at int systolic int diastolic int pulse varchar context varchar note text setting text activity_condition numeric rest_duration_minutes text body_position text measured_arm text device_details text cuff_details text additional_circumstances timestamp created_at timestamp updated_at } ``` Table names are `profile.patient` and `observations.observation`. Every diagram timestamp column is `timestamp without time zone`. Runtime normalizes measurement instants to UTC with DateTimeKind.Unspecified for stored/wire compatibility. Nullable columns: patient contact_info; observation context, note and optional preparation fields. Account ID, name, birth date, identifiers, measurements, categories and audit timestamps are required. Domain class nullability is not a substitute for SQL constraints. ## Constraints and query semantics - Patient account_id has unique index IX_patient_account_id. A profile is created from trusted ticket identity, not caller-supplied account binding. - Observations have a restricted FK to profile.patient; deleting a referenced profile is prohibited by SQL. No public profile-delete route exists. - Systolic, diastolic and pulse are positive integers; rest_duration_minutes is null or nonnegative. - Setting is Home/Clinic/Other/Unknown; activity is AtRest/DuringActivity/AfterActivity/Unknown. SQL defaults are Unknown. - Index ix_observation_patient_time spans patient_id, measured_at, created_at, observation_id. - Latest sorts measured_at, created_at and UUID descending. Selected history sorts measured_at then UUID ascending. PostgreSQL UUID ordering preserves the baseline unsigned network-byte tie behavior. - Each schema_version has integer primary-key version; both migrations install version 1. Runtime does not apply privileged migrations. Profile owns account association and mutable patient fields; Observations owns all measurement/context state and asks ProfileQueries when recording. Runtime modules do not join across schema-owned health tables. The FK is a provisioned integrity boundary, not permission to read another module's entity. ## Mutations and derived data Profile update preserves identity, account binding, date of birth and original creation time. Observation PUT updates only the three measured values. PATCH distinguishes omitted properties from explicit null: omissions retain state, nullable values can clear, categories reset to Unknown, and clearing the structured context does not implicitly erase legacy context/note. Validation precedes persistence and row locks serialize edits. Owner filters apply to retrieval and mutation. Summary/trend/overview responses are derived from current immutable observations; they are not persisted or cached. Credentials/accounts/assignments live in protected configuration, token keys on disk, and versioned guidance/reference data in assemblies. There is no event bus, outbox, replica, background analytics store or historical A import. Exact DDL: [Profile migration](../src/Modules/Profile/Migrations/001-profile.sql) and [Observations migration](../src/Modules/Observations/Migrations/001-observations.sql).