diff --git a/.dockerignore b/.dockerignore index c65bfe4..0a60e9e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,7 +1,7 @@ .git *.sqlite *.sqlite-journal -data.json +data/*.json .DS_Store .idea/ .vscode/ \ No newline at end of file diff --git a/.gitignore b/.gitignore index 000810a..1f48621 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -data.json +data/*.json *.sqlite *.sqlite-journal .DS_Store diff --git a/README.md b/README.md index 54b09f0..5b46e3f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ API REST en PHP natif (POO) pour gérer des liens de vidéos YouTube. - PHP natif uniquement : aucun framework, aucune dépendance, aucun Composer - Stockage SQLite via PDO -- À chaque création / modification / suppression, un snapshot complet de la table est écrit dans `data.json` +- À chaque création / modification / suppression, un snapshot complet de la table est écrit dans `data/data.json` ## Prérequis @@ -66,7 +66,7 @@ php database/migrate.php `title` et `link_url` sont obligatoires ; `description` et `thumbnail` sont optionnels. `link_url` doit être une URL valide et unique. -## Fichier `data.json` +## Fichier `data/data.json` Régénéré à chaque POST / PUT / DELETE : contient la liste complète des liens, formatée (pretty print). @@ -94,7 +94,7 @@ docker compose down -v # supprime la base (reset complet) ### Persistance -La base SQLite est stockée dans le Docker volume `db-data` : elle survit aux `down`/`up` successifs. Un `down -v` la supprime ; le prochain démarrage recrée la base via les migrations. +La base SQLite est stockée dans le Docker volume `db-data` et le fichier `data/data.json` dans le volume `data-data`. Ils survivent aux `down`/`up` successifs. Un `down -v` les supprime ; le prochain démarrage recrée la base via les migrations. ### Rebuild après modification du code @@ -111,12 +111,13 @@ public/ src/ Database.php # connexion PDO SQLite + exécution des migrations LinkRepository.php # CRUD SQL - JsonExporter.php # écriture de data.json + JsonExporter.php # écriture de data/data.json LinkController.php # routage, validation, orchestration database/ migrate.php # runner de migrations (CLI) migrations/ # fichiers SQL versionnés +data/ # data.json (volume Docker dédié) Dockerfile # image PHP 8.4 Apache + mod_rewrite -docker-compose.yml # service web + volume db-data +docker-compose.yml # service web + volumes db-data et data-data .dockerignore ``` \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index be11c99..07738d1 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,6 +8,8 @@ services: - "8000:80" volumes: - db-data:/var/www/html/database + - data-data:/var/www/html/data volumes: - db-data: \ No newline at end of file + db-data: + data-data: \ No newline at end of file diff --git a/public/index.php b/public/index.php index 51d20f2..50a1350 100644 --- a/public/index.php +++ b/public/index.php @@ -22,7 +22,7 @@ try { $controller = new LinkController( new LinkRepository($pdo), - new JsonExporter($pdo, dirname(__DIR__) . '/data.json'), + new JsonExporter($pdo, dirname(__DIR__) . '/data/data.json'), ); $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); diff --git a/tests/curl.sh b/tests/curl.sh index ba5c0f8..cf05268 100755 --- a/tests/curl.sh +++ b/tests/curl.sh @@ -37,4 +37,4 @@ echo "== DELETE /links/1 (suppression) ==" curl -s -w "\n[%{http_code}]\n" -X DELETE "$URL/1" echo "== data.json ==" -cat data.json \ No newline at end of file +cat data/data.json \ No newline at end of file