Data model
The tables and how they relate.
Care Core uses one MySQL (or MariaDB) database with real foreign keys. Every table that holds an organisation’s data carries organisation_id. Public identifiers are UUIDs; internal keys are integers. The canonical definition is database/schema.sql.
The shape of it
organisations
├─ organisation_modules which modules are switched on
├─ persons one permanent identity per human
│ ├─ person_profiles 1:1 address, emergency contact, NI/bank (encrypted), photo, signature
│ ├─ employments a stint of work: dates, job, contract, hours, line manager
│ │ ├─ employment_changes what changed in a move, and from when
│ │ └─ employment_details 1:1 TUPE, working time, visa, apprenticeship, leave
│ ├─ support_episodes a period of receiving support
│ │ ├─ care_needs
│ │ └─ person_contacts
│ ├─ team_assignments who is in which team, valid_from / valid_to
│ ├─ key_worker_assignments supported person ↔ staff person, valid_from / valid_to
│ ├─ registrations, supervisions, appraisals, learning_records
│ ├─ profile_changes staff requests waiting for approval
│ ├─ tasks joiner / mover / leaver / reassign work
│ └─ users a login (access_ends_on, oidc_subject)
├─ teams hierarchy (parent_team_id), staff_only
├─ checklist_templates / _items what creates tasks
├─ outbox_events → webhook_deliveries ← webhook_endpoints
├─ audit_log append only
└─ scim_tokens, login_attempts, schema_migrations
The tables
| Table | Holds | Key points |
|---|---|---|
organisations | Each tenant. | Everything else belongs to one. |
job_roles, job_role_requirements | A job role and the checks needed before someone can start in it. | Title, code, description, reporting line (to another role), usual team, contract, hours, grade; each check is required or optional. |
vacancies | A post (or several) to fill in a role. | Reference, role, team, line manager, posts, status (draft, open, filled, closed). |
applications, application_checks | A candidate for a vacancy, and their checks. | Candidate details, stage, interview and offer dates; linked to a person and an employment once hired. |
persons | A human, once. | Names, date of birth, sex, NHS/CHI number, email, phone, employment status, GP practice, home address in parts, notes. Never deleted. |
person_profiles | Personal details that belong to the person. | National Insurance and bank columns hold encrypted text. |
employments | One stint of work. | start_date, end_date (last day), job title, contract type, hours, line_manager_person_id, employee_ref (unique per organisation), leaving reason. A rehire is a new row. |
employment_changes | History of a move. | Field, from value, to value, effective date. |
employment_details | Terms of an employment. | One row per employment: TUPE, working time, apprenticeship, visa, leave. |
teams | Services and teams. | Parent, kind, staff_only, active. |
team_assignments | Membership stints. | valid_from, valid_to, role, primary flag, source. |
support_episodes | Periods of support. | Start and end dates, reference, NHS number, local authority reference. |
care_needs | Needs for a person supported. | Category, description, severity, review date, ended_on. |
person_contacts | Contacts. | Type, label, value, primary. |
key_worker_assignments | Key worker links. | Supported person, staff person, role label, valid_from, valid_to. |
registrations, supervisions, appraisals, learning_records | Compliance records. | Belong to the person. |
profile_changes | Self-service requests. | Field, label, current and proposed value (encrypted for sensitive fields), status (pending, approved, rejected, withdrawn), reviewer, reason. |
users | Logins. | Unique email, password hash (null for Microsoft-only), role, status, access_ends_on, invitation token hash, oidc_subject. |
checklist_templates, checklist_template_items | What creates tasks. | Per kind (joiner, mover, leaver). |
tasks | Work to do. | Kind, title, due date, owner role, status (open, done, skipped). |
outbox_events | Events. | The signed-and-sent payload, fanned_out_at. |
webhook_endpoints, webhook_deliveries | Webhooks. | Address, secret, event filter, active; per-delivery attempts, status and last error. |
audit_log | Who did what. | Append-only. |
scim_tokens | SCIM credentials. | Only a SHA-256 hash of each token. |
api_keys | API keys. | Prefix, SHA-256 hash, scopes, allowed addresses, rate limit, expiry, last use. |
api_rate, api_idempotency | API rate limiting and replay protection. | Per key per minute; stored results of POSTs with an Idempotency-Key, kept 24 hours. |
login_attempts | Failed sign-ins. | For the lock-out rule. |
schema_migrations | Which upgrades have run. | See Day-to-day operations. |
The period rule
For employments, support_episodes, team_assignments and key_worker_assignments, a row is active on date D when start <= D AND (end IS NULL OR end >= D). The end date is the last day, inclusive. All queries use this one rule.
Deletion
Lifecycle processes never delete rows. They end them. Rows are removed only by a few explicit actions: removing a compliance record, removing a contact, removing a checklist item, and (by foreign key) deleting an entire organisation or person in the database.
Upgrading the schema
Numbered files in database/migrations/ are applied once each, in order, by php scripts/migrate.php. A new installation builds from schema.sql, which already contains them all. See operations.