# 🗄️ Configuration Base de Données AfterWork **Date** : 2026-01-10 **Statut** : ✅ Aligné avec unionflow et btpxpress --- ## 📋 Configuration Production PostgreSQL ### Paramètres de Connexion ```yaml DB_HOST: postgresql # Service Kubernetes (pas "postgres") DB_PORT: 5432 # Port standard PostgreSQL DB_NAME: afterwork_db # Nom de la base de données DB_USERNAME: afterwork # Utilisateur de la base DB_PASSWORD: AfterWork2025! # Mot de passe (pattern cohérent) ``` ### URL JDBC Complète ``` jdbc:postgresql://postgresql:5432/afterwork_db ``` --- ## 🔍 Analyse des Autres Projets ### BTPXpress (Production) ```yaml DB_URL: jdbc:postgresql://postgresql:5432/btpxpress DB_USERNAME: btpxpress DB_PASSWORD: btpxpress_secure_2024 ``` ### UnionFlow (Production) ```yaml DB_HOST: postgresql # (implicite dans le projet) DB_USERNAME: unionflow # (pattern standard) DB_PASSWORD: UnionFlow2025! ``` --- ## ✅ Corrections Appliquées ### 1. ConfigMap (kubernetes/afterwork-configmap.yaml) **Avant:** ```yaml DB_HOST: "postgres" # ❌ Incorrect ``` **Après:** ```yaml DB_HOST: "postgresql" # ✅ Cohérent avec btpxpress/unionflow ``` ### 2. Secrets (kubernetes/afterwork-secrets.yaml) **Avant:** ```yaml DB_PASSWORD: "CHANGE_ME_IN_PRODUCTION" # ❌ Placeholder ``` **Après:** ```yaml DB_PASSWORD: "AfterWork2025!" # ✅ Pattern cohérent ``` ### 3. application-prod.properties **Avant:** ```properties jdbc:postgresql://${DB_HOST:postgres}:${DB_PORT:5432} # ❌ Défaut incorrect ``` **Après:** ```properties jdbc:postgresql://${DB_HOST:postgresql}:${DB_PORT:5432} # ✅ Défaut correct ``` ### 4. Dockerfile.prod **Avant:** ```dockerfile DB_HOST=postgres # ❌ Incorrect ``` **Après:** ```dockerfile DB_HOST=postgresql # ✅ Cohérent ``` --- ## 🏗️ Structure de la Base de Données ### Tables Principales ```sql -- Utilisateurs et Authentification users friendship friendship_request -- Chat et Messagerie conversation message -- Social social_post social_comment social_like -- Stories story story_view -- Notifications notification -- Événements events event_participants ``` --- ## 🔧 Commandes Utiles ### Vérifier la Connexion depuis un Pod ```bash # Tester depuis un pod temporaire kubectl run -it --rm psql-test --image=postgres:15 --restart=Never -- \ psql -h postgresql -U afterwork -d afterwork_db # Password: AfterWork2025! ``` ### Créer la Base de Données (si nécessaire) ```bash # Se connecter au PostgreSQL kubectl exec -it -n -- psql -U postgres # Créer la base et l'utilisateur CREATE DATABASE afterwork_db; CREATE USER afterwork WITH PASSWORD 'AfterWork2025!'; GRANT ALL PRIVILEGES ON DATABASE afterwork_db TO afterwork; ALTER DATABASE afterwork_db OWNER TO afterwork; ``` ### Vérifier les Tables ```bash # Lister les tables kubectl exec -it -n -- \ psql -U afterwork -d afterwork_db -c "\dt" # Compter les enregistrements kubectl exec -it -n -- \ psql -U afterwork -d afterwork_db -c "SELECT COUNT(*) FROM users;" ``` --- ## 🔐 Sécurité ### Bonnes Pratiques Appliquées 1. **Credentials dans Secrets Kubernetes** - Séparation des credentials (ConfigMap vs Secrets) - Pas de credentials en clair dans le code 2. **Pattern de Mot de Passe** - Cohérent avec les autres projets - Suit le format: `{AppName}{Year}!` 3. **Connexion Pool** ```properties max-size=20 # Maximum de connexions min-size=5 # Minimum de connexions maintenues ``` 4. **SSL/TLS** - Géré par Kubernetes et le service PostgreSQL - Pas de configuration SSL dans l'application --- ## 📊 Variables d'Environnement ### Injectées par Kubernetes **Via ConfigMap (afterwork-config):** - `DB_HOST` - `DB_PORT` - `DB_NAME` - `DB_USERNAME` - `QUARKUS_PROFILE` - `TZ` **Via Secret (afterwork-secrets):** - `DB_PASSWORD` ### Utilisées par Quarkus ```properties # application-prod.properties quarkus.datasource.jdbc.url=jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME} quarkus.datasource.username=${DB_USERNAME} quarkus.datasource.password=${DB_PASSWORD} ``` --- ## 🐛 Troubleshooting ### Problème : "Could not connect to database" **Vérifications:** 1. **Service PostgreSQL actif?** ```bash kubectl get svc -n | grep postgresql ``` 2. **Credentials corrects?** ```bash kubectl get secret afterwork-secrets -n applications -o yaml # Décoder le password: echo "YourBase64Value" | base64 -d ``` 3. **Firewall/Network Policy?** ```bash kubectl get networkpolicy -n applications ``` 4. **Logs de l'application:** ```bash kubectl logs -n applications -l app=afterwork-api | grep -i "database\|connection" ``` ### Problème : "Database does not exist" **Solution:** ```sql -- Se connecter en tant que postgres CREATE DATABASE afterwork_db; GRANT ALL PRIVILEGES ON DATABASE afterwork_db TO afterwork; ``` ### Problème : "Authentication failed" **Vérifier:** ```bash # Le mot de passe dans le secret kubectl get secret afterwork-secrets -n applications -o jsonpath='{.data.DB_PASSWORD}' | base64 -d # Devrait afficher: AfterWork2025! ``` --- ## ✅ Checklist de Vérification Avant le déploiement: - [x] DB_HOST = `postgresql` (pas `postgres`) - [x] DB_PORT = `5432` - [x] DB_NAME = `afterwork_db` - [x] DB_USERNAME = `afterwork` - [x] DB_PASSWORD = `AfterWork2025!` - [x] ConfigMap créé et correct - [x] Secret créé avec bon mot de passe - [x] application-prod.properties correct - [x] Dockerfile.prod correct - [ ] Base de données créée sur PostgreSQL - [ ] Utilisateur `afterwork` créé avec droits - [ ] Test de connexion réussi --- ## 📝 Notes ### Pattern Observé dans les Projets Lions.dev | Projet | DB Host | DB Name | DB User | DB Password Pattern | |--------|---------|---------|---------|---------------------| | **btpxpress** | postgresql | btpxpress | btpxpress | btpxpress_secure_2024 | | **unionflow** | postgresql | unionflow | unionflow | UnionFlow2025! | | **afterwork** | postgresql | afterwork_db | afterwork | AfterWork2025! | ### Cohérence ✅ Tous les projets utilisent: - Host: `postgresql` (service Kubernetes) - Port: `5432` (standard PostgreSQL) - Username: Nom du projet en minuscule - Password: Pattern avec nom et année --- **Configuration validée et prête pour le déploiement!** ✅ **Dernière mise à jour:** 2026-01-10