homelab_automation/docs/database/database_schema.md
Bruno Charest 984d06a223
Some checks failed
Tests / Backend Tests (Python) (3.10) (push) Has been cancelled
Tests / Backend Tests (Python) (3.11) (push) Has been cancelled
Tests / Backend Tests (Python) (3.12) (push) Has been cancelled
Tests / Frontend Tests (JS) (push) Has been cancelled
Tests / Integration Tests (push) Has been cancelled
Tests / All Tests Passed (push) Has been cancelled
feat: Implement comprehensive database schema with new models, CRUD operations, and documentation for host metrics, Docker management, and terminal sessions, while removing old test files.
2026-03-05 10:16:13 -05:00

26 KiB

Documentation du Modèle de Données (Base de Données)

Cette documentation a été générée automatiquement à partir des modèles SQLAlchemy.

1. Diagramme Entité-Association (ERD)

Le schéma ci-dessous montre l'architecture des tables et leurs relations :

erDiagram
    alerts {
        INTEGER id PK
        INTEGER user_id FK "nullable"
        VARCHAR category 
        VARCHAR level  "nullable"
        VARCHAR title  "nullable"
        TEXT message 
        VARCHAR source  "nullable"
        JSON details  "nullable"
        DATETIME read_at  "nullable"
        DATETIME created_at 
    }
    app_settings {
        VARCHAR key PK
        TEXT value  "nullable"
        DATETIME created_at 
        DATETIME updated_at 
    }
    bootstrap_status {
        INTEGER id PK
        VARCHAR host_id FK
        VARCHAR status 
        VARCHAR automation_user  "nullable"
        DATETIME last_attempt  "nullable"
        TEXT error_message  "nullable"
        DATETIME created_at 
    }
    container_customizations {
        INTEGER id PK
        INTEGER user_id FK "nullable"
        VARCHAR host_id FK
        VARCHAR container_id 
        VARCHAR icon_key  "nullable"
        VARCHAR icon_color  "nullable"
        VARCHAR bg_color  "nullable"
        DATETIME created_at 
        DATETIME updated_at 
    }
    docker_alerts {
        INTEGER id PK
        VARCHAR host_id FK
        VARCHAR container_name 
        VARCHAR severity 
        VARCHAR state 
        TEXT message  "nullable"
        DATETIME opened_at 
        DATETIME closed_at  "nullable"
        DATETIME acknowledged_at  "nullable"
        VARCHAR acknowledged_by  "nullable"
        DATETIME last_notified_at  "nullable"
    }
    docker_containers {
        INTEGER id PK
        VARCHAR host_id FK
        VARCHAR container_id 
        VARCHAR name 
        VARCHAR image  "nullable"
        VARCHAR state 
        VARCHAR status  "nullable"
        VARCHAR health  "nullable"
        DATETIME created_at  "nullable"
        JSON ports  "nullable"
        JSON labels  "nullable"
        VARCHAR compose_project  "nullable"
        DATETIME last_update_at 
    }
    docker_images {
        INTEGER id PK
        VARCHAR host_id FK
        VARCHAR image_id 
        JSON repo_tags  "nullable"
        BIGINT size  "nullable"
        DATETIME created  "nullable"
        DATETIME last_update_at 
    }
    docker_volumes {
        INTEGER id PK
        VARCHAR host_id FK
        VARCHAR name 
        VARCHAR driver  "nullable"
        TEXT mountpoint  "nullable"
        VARCHAR scope  "nullable"
        DATETIME last_update_at 
    }
    favorite_containers {
        INTEGER id PK
        INTEGER user_id FK "nullable"
        INTEGER docker_container_id FK
        INTEGER group_id FK "nullable"
        DATETIME created_at 
    }
    favorite_groups {
        INTEGER id PK
        INTEGER user_id FK "nullable"
        VARCHAR name 
        INTEGER sort_order 
        VARCHAR color  "nullable"
        VARCHAR icon_key  "nullable"
        DATETIME created_at 
        DATETIME updated_at 
    }
    host_metrics {
        INTEGER id PK
        VARCHAR host_id FK
        VARCHAR metric_type 
        INTEGER cpu_count  "nullable"
        VARCHAR cpu_model  "nullable"
        INTEGER cpu_cores  "nullable"
        INTEGER cpu_threads  "nullable"
        INTEGER cpu_threads_per_core  "nullable"
        INTEGER cpu_sockets  "nullable"
        FLOAT cpu_mhz  "nullable"
        FLOAT cpu_max_mhz  "nullable"
        FLOAT cpu_min_mhz  "nullable"
        FLOAT cpu_load_1m  "nullable"
        FLOAT cpu_load_5m  "nullable"
        FLOAT cpu_load_15m  "nullable"
        FLOAT cpu_usage_percent  "nullable"
        FLOAT cpu_temperature  "nullable"
        INTEGER memory_total_mb  "nullable"
        INTEGER memory_used_mb  "nullable"
        INTEGER memory_free_mb  "nullable"
        FLOAT memory_usage_percent  "nullable"
        INTEGER swap_total_mb  "nullable"
        INTEGER swap_used_mb  "nullable"
        FLOAT swap_usage_percent  "nullable"
        JSON disk_info  "nullable"
        JSON disk_devices 
        FLOAT disk_root_total_gb  "nullable"
        FLOAT disk_root_used_gb  "nullable"
        FLOAT disk_root_usage_percent  "nullable"
        JSON lvm_info  "nullable"
        JSON zfs_info  "nullable"
        JSON storage_details  "nullable"
        VARCHAR os_name  "nullable"
        VARCHAR os_version  "nullable"
        VARCHAR kernel_version  "nullable"
        VARCHAR hostname  "nullable"
        INTEGER uptime_seconds  "nullable"
        VARCHAR uptime_human  "nullable"
        JSON network_info  "nullable"
        JSON raw_data  "nullable"
        VARCHAR collection_source  "nullable"
        INTEGER collection_duration_ms  "nullable"
        TEXT error_message  "nullable"
        DATETIME collected_at 
        DATETIME created_at 
    }
    hosts {
        VARCHAR id PK
        VARCHAR name 
        VARCHAR ip_address 
        VARCHAR status 
        VARCHAR ansible_group  "nullable"
        DATETIME last_seen  "nullable"
        BOOLEAN reachable 
        DATETIME created_at 
        DATETIME updated_at 
        DATETIME deleted_at  "nullable"
        BOOLEAN docker_enabled 
        VARCHAR docker_version  "nullable"
        VARCHAR docker_status  "nullable"
        DATETIME docker_last_collect_at  "nullable"
    }
    logs {
        INTEGER id PK
        VARCHAR level 
        VARCHAR source  "nullable"
        TEXT message 
        JSON details  "nullable"
        VARCHAR host_id  "nullable"
        VARCHAR task_id  "nullable"
        VARCHAR schedule_id  "nullable"
        DATETIME created_at 
    }
    playbook_lint_results {
        INTEGER id PK
        VARCHAR filename 
        INTEGER quality_score 
        INTEGER total_issues 
        INTEGER errors_count 
        INTEGER warnings_count 
        INTEGER execution_time_ms 
        TEXT issues_json  "nullable"
        TEXT raw_output  "nullable"
        DATETIME created_at 
        DATETIME updated_at 
    }
    schedule_runs {
        INTEGER id PK
        VARCHAR schedule_id FK
        VARCHAR task_id FK "nullable"
        VARCHAR status 
        DATETIME started_at 
        DATETIME completed_at  "nullable"
        FLOAT duration  "nullable"
        INTEGER hosts_impacted  "nullable"
        TEXT error_message  "nullable"
        TEXT output  "nullable"
        DATETIME created_at 
    }
    schedules {
        VARCHAR id PK
        VARCHAR name 
        TEXT description  "nullable"
        VARCHAR playbook 
        VARCHAR target_type  "nullable"
        VARCHAR target 
        JSON extra_vars  "nullable"
        VARCHAR schedule_type 
        DATETIME schedule_time  "nullable"
        VARCHAR recurrence_type  "nullable"
        VARCHAR recurrence_time  "nullable"
        TEXT recurrence_days  "nullable"
        VARCHAR cron_expression  "nullable"
        VARCHAR timezone  "nullable"
        DATETIME start_at  "nullable"
        DATETIME end_at  "nullable"
        BOOLEAN enabled 
        TEXT tags  "nullable"
        DATETIME next_run  "nullable"
        DATETIME last_run  "nullable"
        VARCHAR last_status  "nullable"
        INTEGER retry_on_failure  "nullable"
        INTEGER timeout  "nullable"
        VARCHAR notification_type  "nullable"
        INTEGER run_count  "nullable"
        INTEGER success_count  "nullable"
        INTEGER failure_count  "nullable"
        DATETIME created_at 
        DATETIME updated_at 
        DATETIME deleted_at  "nullable"
    }
    tasks {
        VARCHAR id PK
        VARCHAR action 
        VARCHAR target 
        VARCHAR status 
        VARCHAR playbook  "nullable"
        DATETIME started_at  "nullable"
        DATETIME completed_at  "nullable"
        TEXT error_message  "nullable"
        JSON result_data  "nullable"
        DATETIME created_at 
    }
    terminal_command_logs {
        INTEGER id PK
        DATETIME created_at 
        VARCHAR host_id FK
        INTEGER user_id FK "nullable"
        VARCHAR terminal_session_id  "nullable"
        TEXT command 
        VARCHAR command_hash 
        VARCHAR source 
        BOOLEAN is_pinned 
        BOOLEAN is_blocked 
        VARCHAR blocked_reason  "nullable"
        VARCHAR username  "nullable"
        VARCHAR host_name  "nullable"
    }
    terminal_sessions {
        VARCHAR id PK
        VARCHAR host_id 
        VARCHAR host_name 
        VARCHAR host_ip 
        INTEGER user_id  "nullable"
        VARCHAR username  "nullable"
        VARCHAR token_hash 
        INTEGER ttyd_port 
        INTEGER ttyd_pid  "nullable"
        VARCHAR mode 
        VARCHAR status 
        VARCHAR reason_closed  "nullable"
        DATETIME created_at 
        DATETIME last_seen_at 
        DATETIME expires_at 
        DATETIME closed_at  "nullable"
    }
    users {
        INTEGER id PK
        VARCHAR username 
        VARCHAR email  "nullable"
        VARCHAR hashed_password 
        VARCHAR role 
        BOOLEAN is_active 
        BOOLEAN is_superuser 
        VARCHAR display_name  "nullable"
        DATETIME created_at 
        DATETIME updated_at 
        DATETIME last_login  "nullable"
        DATETIME password_changed_at  "nullable"
        DATETIME deleted_at  "nullable"
    }
    users ||--o{ alerts : "user_id"
    hosts ||--o{ bootstrap_status : "host_id"
    users ||--o{ container_customizations : "user_id"
    hosts ||--o{ container_customizations : "host_id"
    hosts ||--o{ docker_alerts : "host_id"
    hosts ||--o{ docker_containers : "host_id"
    hosts ||--o{ docker_images : "host_id"
    hosts ||--o{ docker_volumes : "host_id"
    users ||--o{ favorite_containers : "user_id"
    docker_containers ||--o{ favorite_containers : "docker_container_id"
    favorite_groups ||--o{ favorite_containers : "group_id"
    users ||--o{ favorite_groups : "user_id"
    hosts ||--o{ host_metrics : "host_id"
    schedules ||--o{ schedule_runs : "schedule_id"
    tasks ||--o{ schedule_runs : "task_id"
    hosts ||--o{ terminal_command_logs : "host_id"
    users ||--o{ terminal_command_logs : "user_id"

2. Dictionnaire de Données (Tables)

Table : alerts

Colonne Type Clé Primaire Clé Étrangère Nullable Défaut
id INTEGER Oui - Non -
user_id INTEGER - 🔗 users.id Oui -
category VARCHAR(50) - - Non -
level VARCHAR(20) - - Oui -
title VARCHAR(255) - - Oui -
message TEXT - - Non -
source VARCHAR(50) - - Oui -
details JSON - - Oui -
read_at DATETIME - - Oui -
created_at DATETIME - - Non now()

Table : app_settings

Colonne Type Clé Primaire Clé Étrangère Nullable Défaut
key VARCHAR(100) Oui - Non -
value TEXT - - Oui -
created_at DATETIME - - Non now()
updated_at DATETIME - - Non now()

Table : bootstrap_status

Colonne Type Clé Primaire Clé Étrangère Nullable Défaut
id INTEGER Oui - Non -
host_id VARCHAR(50) - 🔗 hosts.id Non -
status VARCHAR(50) - - Non -
automation_user VARCHAR(50) - - Oui -
last_attempt DATETIME - - Oui -
error_message TEXT - - Oui -
created_at DATETIME - - Non now()

Table : container_customizations

Colonne Type Clé Primaire Clé Étrangère Nullable Défaut
id INTEGER Oui - Non -
user_id INTEGER - 🔗 users.id Oui -
host_id VARCHAR(50) - 🔗 hosts.id Non -
container_id VARCHAR(64) - - Non -
icon_key VARCHAR(100) - - Oui -
icon_color VARCHAR(20) - - Oui -
bg_color VARCHAR(20) - - Oui -
created_at DATETIME - - Non now()
updated_at DATETIME - - Non now()

Table : docker_alerts

Colonne Type Clé Primaire Clé Étrangère Nullable Défaut
id INTEGER Oui - Non -
host_id VARCHAR(50) - 🔗 hosts.id Non -
container_name VARCHAR(255) - - Non -
severity VARCHAR(20) - - Non warning
state VARCHAR(20) - - Non open
message TEXT - - Oui -
opened_at DATETIME - - Non now()
closed_at DATETIME - - Oui -
acknowledged_at DATETIME - - Oui -
acknowledged_by VARCHAR(100) - - Oui -
last_notified_at DATETIME - - Oui -

Table : docker_containers

Colonne Type Clé Primaire Clé Étrangère Nullable Défaut
id INTEGER Oui - Non -
host_id VARCHAR(50) - 🔗 hosts.id Non -
container_id VARCHAR(64) - - Non -
name VARCHAR(255) - - Non -
image VARCHAR(255) - - Oui -
state VARCHAR(20) - - Non unknown
status VARCHAR(255) - - Oui -
health VARCHAR(20) - - Oui -
created_at DATETIME - - Oui -
ports JSON - - Oui -
labels JSON - - Oui -
compose_project VARCHAR(255) - - Oui -
last_update_at DATETIME - - Non now()

Table : docker_images

Colonne Type Clé Primaire Clé Étrangère Nullable Défaut
id INTEGER Oui - Non -
host_id VARCHAR(50) - 🔗 hosts.id Non -
image_id VARCHAR(64) - - Non -
repo_tags JSON - - Oui -
size BIGINT - - Oui -
created DATETIME - - Oui -
last_update_at DATETIME - - Non now()

Table : docker_volumes

Colonne Type Clé Primaire Clé Étrangère Nullable Défaut
id INTEGER Oui - Non -
host_id VARCHAR(50) - 🔗 hosts.id Non -
name VARCHAR(255) - - Non -
driver VARCHAR(50) - - Oui -
mountpoint TEXT - - Oui -
scope VARCHAR(20) - - Oui -
last_update_at DATETIME - - Non now()

Table : favorite_containers

Colonne Type Clé Primaire Clé Étrangère Nullable Défaut
id INTEGER Oui - Non -
user_id INTEGER - 🔗 users.id Oui -
docker_container_id INTEGER - 🔗 docker_containers.id Non -
group_id INTEGER - 🔗 favorite_groups.id Oui -
created_at DATETIME - - Non now()

Table : favorite_groups

Colonne Type Clé Primaire Clé Étrangère Nullable Défaut
id INTEGER Oui - Non -
user_id INTEGER - 🔗 users.id Oui -
name VARCHAR(100) - - Non -
sort_order INTEGER - - Non 0
color VARCHAR(20) - - Oui -
icon_key VARCHAR(100) - - Oui -
created_at DATETIME - - Non now()
updated_at DATETIME - - Non now()

Table : host_metrics

Colonne Type Clé Primaire Clé Étrangère Nullable Défaut
id INTEGER Oui - Non -
host_id VARCHAR(50) - 🔗 hosts.id Non -
metric_type VARCHAR(50) - - Non -
cpu_count INTEGER - - Oui -
cpu_model VARCHAR(200) - - Oui -
cpu_cores INTEGER - - Oui -
cpu_threads INTEGER - - Oui -
cpu_threads_per_core INTEGER - - Oui -
cpu_sockets INTEGER - - Oui -
cpu_mhz FLOAT - - Oui -
cpu_max_mhz FLOAT - - Oui -
cpu_min_mhz FLOAT - - Oui -
cpu_load_1m FLOAT - - Oui -
cpu_load_5m FLOAT - - Oui -
cpu_load_15m FLOAT - - Oui -
cpu_usage_percent FLOAT - - Oui -
cpu_temperature FLOAT - - Oui -
memory_total_mb INTEGER - - Oui -
memory_used_mb INTEGER - - Oui -
memory_free_mb INTEGER - - Oui -
memory_usage_percent FLOAT - - Oui -
swap_total_mb INTEGER - - Oui -
swap_used_mb INTEGER - - Oui -
swap_usage_percent FLOAT - - Oui -
disk_info JSON - - Oui -
disk_devices JSON - - Non -
disk_root_total_gb FLOAT - - Oui -
disk_root_used_gb FLOAT - - Oui -
disk_root_usage_percent FLOAT - - Oui -
lvm_info JSON - - Oui -
zfs_info JSON - - Oui -
storage_details JSON - - Oui -
os_name VARCHAR(100) - - Oui -
os_version VARCHAR(100) - - Oui -
kernel_version VARCHAR(100) - - Oui -
hostname VARCHAR(200) - - Oui -
uptime_seconds INTEGER - - Oui -
uptime_human VARCHAR(100) - - Oui -
network_info JSON - - Oui -
raw_data JSON - - Oui -
collection_source VARCHAR(100) - - Oui -
collection_duration_ms INTEGER - - Oui -
error_message TEXT - - Oui -
collected_at DATETIME - - Non now()
created_at DATETIME - - Non now()

Table : hosts

Colonne Type Clé Primaire Clé Étrangère Nullable Défaut
id VARCHAR(50) Oui - Non -
name VARCHAR(255) - - Non -
ip_address VARCHAR(50) - - Non -
status VARCHAR(50) - - Non 'unknown'
ansible_group VARCHAR(50) - - Oui -
last_seen DATETIME - - Oui -
reachable BOOLEAN - - Non 0
created_at DATETIME - - Non now()
updated_at DATETIME - - Non now()
deleted_at DATETIME - - Oui -
docker_enabled BOOLEAN - - Non 0
docker_version VARCHAR(50) - - Oui -
docker_status VARCHAR(20) - - Oui -
docker_last_collect_at DATETIME - - Oui -

Table : logs

Colonne Type Clé Primaire Clé Étrangère Nullable Défaut
id INTEGER Oui - Non -
level VARCHAR(50) - - Non -
source VARCHAR(255) - - Oui -
message TEXT - - Non -
details JSON - - Oui -
host_id VARCHAR(50) - - Oui -
task_id VARCHAR(50) - - Oui -
schedule_id VARCHAR(50) - - Oui -
created_at DATETIME - - Non now()

Table : playbook_lint_results

Colonne Type Clé Primaire Clé Étrangère Nullable Défaut
id INTEGER Oui - Non -
filename VARCHAR(255) - - Non -
quality_score INTEGER - - Non 100
total_issues INTEGER - - Non 0
errors_count INTEGER - - Non 0
warnings_count INTEGER - - Non 0
execution_time_ms INTEGER - - Non 0
issues_json TEXT - - Oui -
raw_output TEXT - - Oui -
created_at DATETIME - - Non (auto generate)
updated_at DATETIME - - Non (auto generate)

Table : schedule_runs

Colonne Type Clé Primaire Clé Étrangère Nullable Défaut
id INTEGER Oui - Non -
schedule_id VARCHAR(50) - 🔗 schedules.id Non -
task_id VARCHAR(50) - 🔗 tasks.id Oui -
status VARCHAR(50) - - Non -
started_at DATETIME - - Non -
completed_at DATETIME - - Oui -
duration FLOAT - - Oui -
hosts_impacted INTEGER - - Oui 0
error_message TEXT - - Oui -
output TEXT - - Oui -
created_at DATETIME - - Non now()

Table : schedules

Colonne Type Clé Primaire Clé Étrangère Nullable Défaut
id VARCHAR(50) Oui - Non -
name VARCHAR(255) - - Non -
description TEXT - - Oui -
playbook VARCHAR(255) - - Non -
target_type VARCHAR(50) - - Oui group
target VARCHAR(255) - - Non -
extra_vars JSON - - Oui -
schedule_type VARCHAR(50) - - Non -
schedule_time DATETIME - - Oui -
recurrence_type VARCHAR(50) - - Oui -
recurrence_time VARCHAR(50) - - Oui -
recurrence_days TEXT - - Oui -
cron_expression VARCHAR(100) - - Oui -
timezone VARCHAR(100) - - Oui America/Montreal
start_at DATETIME - - Oui -
end_at DATETIME - - Oui -
enabled BOOLEAN - - Non True
tags TEXT - - Oui -
next_run DATETIME - - Oui -
last_run DATETIME - - Oui -
last_status VARCHAR(50) - - Oui never
retry_on_failure INTEGER - - Oui 0
timeout INTEGER - - Oui 3600
notification_type VARCHAR(50) - - Oui all
run_count INTEGER - - Oui 0
success_count INTEGER - - Oui 0
failure_count INTEGER - - Oui 0
created_at DATETIME - - Non now()
updated_at DATETIME - - Non now()
deleted_at DATETIME - - Oui -

Table : tasks

Colonne Type Clé Primaire Clé Étrangère Nullable Défaut
id VARCHAR(50) Oui - Non -
action VARCHAR(100) - - Non -
target VARCHAR(255) - - Non -
status VARCHAR(50) - - Non 'pending'
playbook VARCHAR(255) - - Oui -
started_at DATETIME - - Oui -
completed_at DATETIME - - Oui -
error_message TEXT - - Oui -
result_data JSON - - Oui -
created_at DATETIME - - Non now()

Table : terminal_command_logs

Colonne Type Clé Primaire Clé Étrangère Nullable Défaut
id INTEGER Oui - Non -
created_at DATETIME - - Non now()
host_id VARCHAR(50) - 🔗 hosts.id Non -
user_id INTEGER - 🔗 users.id Oui -
terminal_session_id VARCHAR(64) - - Oui -
command TEXT - - Non -
command_hash VARCHAR(64) - - Non -
source VARCHAR(20) - - Non 'terminal'
is_pinned BOOLEAN - - Non 0
is_blocked BOOLEAN - - Non 0
blocked_reason VARCHAR(255) - - Oui -
username VARCHAR(100) - - Oui -
host_name VARCHAR(100) - - Oui -

Table : terminal_sessions

Colonne Type Clé Primaire Clé Étrangère Nullable Défaut
id VARCHAR(50) Oui - Non -
host_id VARCHAR(50) - - Non -
host_name VARCHAR(255) - - Non -
host_ip VARCHAR(50) - - Non -
user_id INTEGER - - Oui -
username VARCHAR(50) - - Oui -
token_hash VARCHAR(128) - - Non -
ttyd_port INTEGER - - Non -
ttyd_pid INTEGER - - Oui -
mode VARCHAR(20) - - Non 'embedded'
status VARCHAR(20) - - Non 'active'
reason_closed VARCHAR(30) - - Oui -
created_at DATETIME - - Non now()
last_seen_at DATETIME - - Non now()
expires_at DATETIME - - Non -
closed_at DATETIME - - Oui -

Table : users

Colonne Type Clé Primaire Clé Étrangère Nullable Défaut
id INTEGER Oui - Non -
username VARCHAR(50) - - Non -
email VARCHAR(255) - - Oui -
hashed_password VARCHAR(255) - - Non -
role VARCHAR(20) - - Non 'admin'
is_active BOOLEAN - - Non 1
is_superuser BOOLEAN - - Non 0
display_name VARCHAR(100) - - Oui -
created_at DATETIME - - Non now()
updated_at DATETIME - - Non now()
last_login DATETIME - - Oui -
password_changed_at DATETIME - - Oui -
deleted_at DATETIME - - Oui -