> ## Documentation Index
> Fetch the complete documentation index at: https://docs.a7manager.se/llms.txt
> Use this file to discover all available pages before exploring further.

# Planner tables

> Plannings and the occurrences projected from them.

Plannings and the occurrences projected from them.

A **✓** in the Null column means the field is optional. Constraint definitions are
reproduced verbatim from PostgreSQL, so they are the exact rule being enforced.
Descriptions come from the models; a blank one means the field carries no
description yet, not that it has no meaning.

### `planner_maintenanceplanning`

| Column          | Type         | Null | Default | Description                                                     |
| --------------- | ------------ | :--: | ------- | --------------------------------------------------------------- |
| `id`            | uuid         |      |         |                                                                 |
| `created_at`    | timestamptz  |      |         |                                                                 |
| `updated_at`    | timestamptz  |      |         |                                                                 |
| `name`          | varchar(200) |      |         | Planning name                                                   |
| `start_date`    | date         |      |         | First day of the planning horizon                               |
| `end_date`      | date         |      |         | Last day of the planning horizon (inclusive)                    |
| `km_per_day`    | int          |      |         | Assumed average vehicle usage for projecting km-based intervals |
| `generated_at`  | timestamptz  |   ✓  |         | When occurrences were last (re)generated                        |
| `created_by_id` | uuid         |   ✓  |         | User who created the planning                                   |
| `project_id`    | uuid         |      |         | Owning project (multi-tenancy)                                  |

<Accordion title="Constraints — 3 checks, 2 foreign keys, 1 primary key">
  | Kind        | Name                                           | Definition                                  |
  | ----------- | ---------------------------------------------- | ------------------------------------------- |
  | Check       | `planner_maintenanceplanning_km_per_day_check` | `((km_per_day >= 0))`                       |
  | Check       | `planning_end_on_or_after_start`               | `((end_date >= start_date))`                |
  | Check       | `planning_km_per_day_positive`                 | `((km_per_day > 0))`                        |
  | Foreign key |                                                | `(created_by_id) REFERENCES users_user(id)` |
  | Foreign key |                                                | `(project_id) REFERENCES project(id)`       |
  | Primary key |                                                | `(id)`                                      |
</Accordion>

### `planner_plannedoccurrence`

| Column                | Type        | Null | Default | Description                                                     |
| --------------------- | ----------- | :--: | ------- | --------------------------------------------------------------- |
| `id`                  | uuid        |      |         |                                                                 |
| `created_at`          | timestamptz |      |         |                                                                 |
| `updated_at`          | timestamptz |      |         |                                                                 |
| `sequence`            | int2        |      |         | 1-based occurrence number of this task within the planning      |
| `due_date`            | date        |      |         | Projected nominal due date                                      |
| `earliest_date`       | date        |      |         | Tolerance window start (can do this early)                      |
| `latest_date`         | date        |      |         | Tolerance window end (overdue after)                            |
| `planned_date`        | date        |      |         | Date the planner scheduled the work for                         |
| `due_km`              | int         |   ✓  |         | Projected odometer at due point (km-based tasks only)           |
| `is_overdue`          | bool        |      |         | Occurrence was already past due at generation time              |
| `component_id`        | uuid        |   ✓  |         | Set for component-type tasks (component mounted on the vehicle) |
| `maintenance_task_id` | uuid        |      |         | Task being planned                                              |
| `planning_id`         | uuid        |      |         | Parent planning                                                 |
| `project_id`          | uuid        |      |         | Denormalized from planning for multi-tenancy filtering          |
| `vehicle_id`          | uuid        |      |         | Vehicle the work is performed on (scheduler row)                |

<Accordion title="Constraints — 1 check, 1 unique, 5 foreign keys, 1 primary key">
  | Kind        | Name                                       | Definition                                                                                  |
  | ----------- | ------------------------------------------ | ------------------------------------------------------------------------------------------- |
  | Check       | `planner_plannedoccurrence_sequence_check` | `((sequence >= 0))`                                                                         |
  | Foreign key |                                            | `(component_id) REFERENCES assets_component(id)`                                            |
  | Foreign key |                                            | `(maintenance_task_id) REFERENCES servicebook_maintenancetask(id)`                          |
  | Foreign key |                                            | `(planning_id) REFERENCES planner_maintenanceplanning(id)`                                  |
  | Foreign key |                                            | `(vehicle_id) REFERENCES assets_vehicle(id)`                                                |
  | Foreign key |                                            | `(project_id) REFERENCES project(id)`                                                       |
  | Primary key |                                            | `(id)`                                                                                      |
  | Unique      | `unique_occurrence_per_planning`           | `NULLS NOT DISTINCT (planning_id, vehicle_id, component_id, maintenance_task_id, sequence)` |
</Accordion>
