# Data Model: Backup Scheduler & Unified Task UI

## Entities

### Task
Represents a background operation (Backup, Migration) managed by the system.

| Field | Type | Description | Constraints |
|-------|------|-------------|-------------|
| `id` | UUID | Unique identifier | Primary Key |
| `type` | String | Type of task | Enum: "backup", "migration" |
| `status` | String | Current execution state | Enum: "pending", "running", "success", "failed" |
| `environment_id` | UUID | Target environment (if applicable) | Foreign Key (Environments), Nullable |
| `started_at` | DateTime | When the task began | Nullable |
| `finished_at` | DateTime | When the task completed | Nullable |
| `logs` | Text | Execution logs | |
| `error` | Text | Error message if failed | Nullable |
| `created_at` | DateTime | When task was queued | Default: Now |

### Schedule
Configuration for automatic task execution. Nested within Environment config.

| Field | Type | Description | Constraints |
|-------|------|-------------|-------------|
| `environment_id` | UUID | Target environment | Foreign Key (Environments) |
| `enabled` | Boolean | Is schedule active? | Default: false |
| `cron_expression` | String | Frequency definition | Valid Cron string (e.g., "0 0 * * *") |
| `last_run_at` | DateTime | Last execution time | Nullable |
| `next_run_at` | DateTime | Calculated next run | Nullable |

## Storage Strategy

- **Tasks**: Stored in `tasks.db` (SQLite) via SQLAlchemy.
- **Schedules**: Stored in `config.json` as part of the Environment model.