# Database

The current live database is `huquq_ishleri`.

The schema map is documented in `../docs/database-map.md`.

Before adding new constraints or migrations, run data checks against production because the legacy app uses several relationships that are not currently enforced by foreign keys.

Recommended first migration tasks:

1. Add non-destructive indexes for common filters.
2. Add unique constraints only after duplicate checks.
3. Add foreign keys only after orphan-record checks.
4. Consider replacing archive tables with a single lifecycle/status model in a later major migration.

## Migrations

Run migrations in filename order:

- `migrations/20260729_add_iclas_neticesi.sql` adds the hearing result field and
  carries existing `istirak_edildi=1` values into the new result model.
- `migrations/20260730_add_case_proceeding_history.sql` stores every court-case
  proceeding suspension and resumption with its change timestamp.
- `migrations/20260730_add_case_reward_details.sql` records whether a case reward
  is a one-time amount or percentage and stores the one-time payment condition.
- `migrations/20260730_add_task_archive_case_link.sql` allows a task to reference
  a finalized court case stored in `mehkeme_arxiv`.
- `migrations/20260731_add_task_title.sql` adds a required task title and fills
  existing task titles from the first line of their content.
- `migrations/20260731_task_responsible_registry.sql` limits task summaries to
  100 characters and creates the responsible-person registry with one default.
- `migrations/20260801_add_case_final_act_details.sql` stores the selected final
  court-act outcome codes and whether the act has entered into legal force for
  active and archived court cases.
- `migrations/20260801_extend_case_relationship_types.sql` adds merged-case and
  general relationship types to the existing court-case relationship registry.
- `migrations/20260802_add_subscribers_module.sql` creates subscriber profiles,
  their important-employee registry, and subscriber file records.
- `migrations/20260802_add_task_file_subject.sql` adds an editable subject field
  to files attached to tasks.
- `migrations/20260802_add_erp_user_profile.sql` stores the ERP profile and an
  optional database-backed SHA-256 login override for in-app password changes.
- `migrations/20260802_add_criminal_proceedings_module.sql` creates criminal
  materials/cases, decisions, person status history, preventive measures,
  investigation/detention extensions, and linked PDF records.
- `migrations/20260802_extend_criminal_proceeding_details.sql` adds separate
  material/case subject fields and repeatable represented or defended persons.
- `migrations/20260802_extend_criminal_decisions_and_people.sql` adds the full
  procedural-decision registry, applicant status, proceeding suspension state,
  and non-destructive removal of people from the current list.
