feat: data.json dans un volume docker gere (data/)
This commit is contained in:
1 parent
a033f415b5
commit
56244d2e95
6 files changed
+13
-10
No files matched your search
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
.git
|
.git
|
||||||
*.sqlite
|
*.sqlite
|
||||||
*.sqlite-journal
|
*.sqlite-journal
|
||||||
data.json
|
data/*.json
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.idea/
|
.idea/
|
||||||
.vscode/
|
.vscode/
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
data.json
|
data/*.json
|
||||||
*.sqlite
|
*.sqlite
|
||||||
*.sqlite-journal
|
*.sqlite-journal
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|||||||
@@ -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
|
- PHP natif uniquement : aucun framework, aucune dépendance, aucun Composer
|
||||||
- Stockage SQLite via PDO
|
- 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
|
## 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.
|
`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).
|
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
|
### 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
|
### Rebuild après modification du code
|
||||||
|
|
||||||
@@ -111,12 +111,13 @@ public/
|
|||||||
src/
|
src/
|
||||||
Database.php # connexion PDO SQLite + exécution des migrations
|
Database.php # connexion PDO SQLite + exécution des migrations
|
||||||
LinkRepository.php # CRUD SQL
|
LinkRepository.php # CRUD SQL
|
||||||
JsonExporter.php # écriture de data.json
|
JsonExporter.php # écriture de data/data.json
|
||||||
LinkController.php # routage, validation, orchestration
|
LinkController.php # routage, validation, orchestration
|
||||||
database/
|
database/
|
||||||
migrate.php # runner de migrations (CLI)
|
migrate.php # runner de migrations (CLI)
|
||||||
migrations/ # fichiers SQL versionnés
|
migrations/ # fichiers SQL versionnés
|
||||||
|
data/ # data.json (volume Docker dédié)
|
||||||
Dockerfile # image PHP 8.4 Apache + mod_rewrite
|
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
|
.dockerignore
|
||||||
```
|
```
|
||||||
+3
-1
@@ -8,6 +8,8 @@ services:
|
|||||||
- "8000:80"
|
- "8000:80"
|
||||||
volumes:
|
volumes:
|
||||||
- db-data:/var/www/html/database
|
- db-data:/var/www/html/database
|
||||||
|
- data-data:/var/www/html/data
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
db-data:
|
db-data:
|
||||||
|
data-data:
|
||||||
+1
-1
@@ -22,7 +22,7 @@ try {
|
|||||||
|
|
||||||
$controller = new LinkController(
|
$controller = new LinkController(
|
||||||
new LinkRepository($pdo),
|
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);
|
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
||||||
|
|||||||
+1
-1
@@ -37,4 +37,4 @@ echo "== DELETE /links/1 (suppression) =="
|
|||||||
curl -s -w "\n[%{http_code}]\n" -X DELETE "$URL/1"
|
curl -s -w "\n[%{http_code}]\n" -X DELETE "$URL/1"
|
||||||
|
|
||||||
echo "== data.json =="
|
echo "== data.json =="
|
||||||
cat data.json
|
cat data/data.json
|
||||||
Reference in new issue
Block a user