mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-20 13:38:15 +02:00
Merge pull request #206 from R0m1k3/1.1
Fix Docker entrypoint and apply database migrations for production
This commit is contained in:
3 files changed
+80
-59
No files matched your search
+5
-3
@@ -84,6 +84,7 @@ COPY --from=build --chown=nextjs:nodejs /app/shared ./shared
|
|||||||
# Copy migration scripts and files
|
# Copy migration scripts and files
|
||||||
COPY --chown=nextjs:nodejs scripts/ ./scripts/
|
COPY --chown=nextjs:nodejs scripts/ ./scripts/
|
||||||
COPY --chown=nextjs:nodejs migrations/ ./migrations/
|
COPY --chown=nextjs:nodejs migrations/ ./migrations/
|
||||||
|
COPY --chown=nextjs:nodejs scripts/docker-entrypoint.sh ./scripts/docker-entrypoint.sh
|
||||||
|
|
||||||
# Create symlink for public files to be accessible from dist
|
# Create symlink for public files to be accessible from dist
|
||||||
RUN ln -sf /app/dist/public /app/dist/public
|
RUN ln -sf /app/dist/public /app/dist/public
|
||||||
@@ -109,8 +110,9 @@ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
|||||||
|
|
||||||
# Make scripts executable
|
# Make scripts executable
|
||||||
RUN chmod +x /app/scripts/auto-migrate-production.sh && \
|
RUN chmod +x /app/scripts/auto-migrate-production.sh && \
|
||||||
chmod +x /app/scripts/docker-entrypoint.sh
|
chmod +x /app/scripts/docker-entrypoint.sh && \
|
||||||
|
ls -la /app/scripts/ && \
|
||||||
|
test -f /app/scripts/docker-entrypoint.sh || echo "ERREUR: docker-entrypoint.sh manquant"
|
||||||
|
|
||||||
# Use entrypoint script for automatic migrations
|
# Start application normally (migration applied separately)
|
||||||
ENTRYPOINT ["/app/scripts/docker-entrypoint.sh"]
|
|
||||||
CMD ["node", "dist/index.js"]
|
CMD ["node", "dist/index.js"]
|
||||||
+35
-56
@@ -1,78 +1,57 @@
|
|||||||
# 🚨 SOLUTION IMMÉDIATE POUR LA PRODUCTION
|
# SOLUTION IMMÉDIATE - Migration DLC Production
|
||||||
|
|
||||||
## 🎯 Objectif
|
|
||||||
Créer **UNIQUEMENT** la table `announcements` manquante. Toutes les autres tables existent déjà en production et ne doivent pas être touchées.
|
|
||||||
|
|
||||||
## Problème
|
## Problème
|
||||||
La table `announcements` n'existe pas dans votre base de données de production, ce qui cause l'erreur:
|
|
||||||
```
|
```
|
||||||
Error: relation "announcements" does not exist
|
exec /app/scripts/docker-entrypoint.sh: no such file or directory
|
||||||
```
|
```
|
||||||
|
|
||||||
## Solution en 3 étapes simples
|
## Solution Rapide (2 minutes)
|
||||||
|
|
||||||
### 1. Connectez-vous à votre serveur de production
|
### ÉTAPE 1: Appliquer la migration directement
|
||||||
```bash
|
```bash
|
||||||
# SSH vers votre serveur
|
# Sur votre serveur de production, exécutez :
|
||||||
ssh votre-serveur-production
|
docker-compose exec logiflow-db psql -U logiflow_admin -d logiflow_db -c "
|
||||||
```
|
ALTER TABLE dlc_products
|
||||||
|
ADD COLUMN IF NOT EXISTS stock_epuise boolean DEFAULT false NOT NULL,
|
||||||
|
ADD COLUMN IF NOT EXISTS stock_epuise_by varchar(255),
|
||||||
|
ADD COLUMN IF NOT EXISTS stock_epuise_at timestamp;
|
||||||
|
|
||||||
### 2. Accédez au conteneur Docker
|
CREATE INDEX IF NOT EXISTS idx_dlc_products_stock_epuise ON dlc_products(stock_epuise);
|
||||||
```bash
|
|
||||||
# Entrer dans le conteneur
|
|
||||||
docker exec -it logiflow-logiflow-1 bash
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. Créer la table directement
|
|
||||||
```bash
|
|
||||||
# Dans le conteneur, exécuter cette commande :
|
|
||||||
psql $DATABASE_URL -c "
|
|
||||||
CREATE TABLE IF NOT EXISTS announcements (
|
|
||||||
id SERIAL PRIMARY KEY,
|
|
||||||
title VARCHAR(255) NOT NULL,
|
|
||||||
content TEXT NOT NULL,
|
|
||||||
priority VARCHAR(20) NOT NULL DEFAULT 'normal',
|
|
||||||
author_id VARCHAR(255) NOT NULL,
|
|
||||||
group_id INTEGER,
|
|
||||||
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
||||||
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
|
||||||
CONSTRAINT announcements_priority_check CHECK (priority IN ('normal', 'important', 'urgent')),
|
|
||||||
CONSTRAINT announcements_author_id_fkey FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE CASCADE,
|
|
||||||
CONSTRAINT announcements_group_id_fkey FOREIGN KEY (group_id) REFERENCES groups(id) ON DELETE CASCADE
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_announcements_priority ON announcements(priority);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_announcements_created_at ON announcements(created_at DESC);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_announcements_author_id ON announcements(author_id);
|
|
||||||
CREATE INDEX IF NOT EXISTS idx_announcements_group_id ON announcements(group_id);
|
|
||||||
"
|
"
|
||||||
```
|
```
|
||||||
|
|
||||||
### 4. Vérifier que ça fonctionne
|
### ÉTAPE 2: Redémarrer l'application
|
||||||
```bash
|
```bash
|
||||||
# Vérifier que la table existe
|
docker-compose restart logiflow
|
||||||
psql $DATABASE_URL -c "SELECT 'SUCCESS: Table announcements créée!' as status;"
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### 5. Sortir du conteneur
|
## Alternative avec script automatique
|
||||||
```bash
|
```bash
|
||||||
exit
|
# Utilisez le script de correction :
|
||||||
|
chmod +x fix-docker-entrypoint.sh
|
||||||
|
./fix-docker-entrypoint.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
## Résultat attendu
|
## Vérification
|
||||||
Après ces étapes, le système d'annonces fonctionnera immédiatement sur votre production.
|
|
||||||
|
|
||||||
## Alternative plus simple (une seule commande)
|
|
||||||
```bash
|
```bash
|
||||||
docker exec logiflow-logiflow-1 psql $DATABASE_URL -c "CREATE TABLE IF NOT EXISTS announcements (id SERIAL PRIMARY KEY, title VARCHAR(255) NOT NULL, content TEXT NOT NULL, priority VARCHAR(20) NOT NULL DEFAULT 'normal', author_id VARCHAR(255) NOT NULL, group_id INTEGER, created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(), updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(), CONSTRAINT announcements_priority_check CHECK (priority IN ('normal', 'important', 'urgent')), CONSTRAINT announcements_author_id_fkey FOREIGN KEY (author_id) REFERENCES users(id) ON DELETE CASCADE, CONSTRAINT announcements_group_id_fkey FOREIGN KEY (group_id) REFERENCES groups(id) ON DELETE CASCADE);"
|
# Vérifier que les colonnes existent :
|
||||||
|
docker-compose exec logiflow-db psql -U logiflow_admin -d logiflow_db -c "
|
||||||
|
SELECT column_name FROM information_schema.columns
|
||||||
|
WHERE table_name='dlc_products'
|
||||||
|
AND column_name LIKE '%stock_epuise%';
|
||||||
|
"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Script minimal (nouvelle option)
|
Résultat attendu :
|
||||||
```bash
|
```
|
||||||
# Copier et exécuter le script minimal
|
column_name
|
||||||
docker cp scripts/fix-announcements-only.sh logiflow-logiflow-1:/app/scripts/
|
-----------------
|
||||||
docker exec logiflow-logiflow-1 chmod +x /app/scripts/fix-announcements-only.sh
|
stock_epuise
|
||||||
docker exec logiflow-logiflow-1 /app/scripts/fix-announcements-only.sh
|
stock_epuise_by
|
||||||
|
stock_epuise_at
|
||||||
```
|
```
|
||||||
|
|
||||||
La correction du problème `Select.Item` value est déjà faite dans le code source.
|
## Après cette correction
|
||||||
|
- ✅ L'erreur "column does not exist" disparaîtra
|
||||||
|
- ✅ L'interface DLC fonctionnera
|
||||||
|
- ✅ Les boutons stock épuisé seront opérationnels
|
||||||
Executable
+40
@@ -0,0 +1,40 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Script de correction pour Docker entrypoint
|
||||||
|
# Applique la migration directement via docker-compose exec
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "🔧 [FIX] Correction du problème docker-entrypoint.sh"
|
||||||
|
|
||||||
|
# Vérifier que le conteneur fonctionne
|
||||||
|
if ! docker-compose ps | grep -q logiflow; then
|
||||||
|
echo "❌ [FIX] Conteneur logiflow non trouvé, démarrage..."
|
||||||
|
docker-compose up -d logiflow-db
|
||||||
|
sleep 10
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "🔄 [FIX] Application de la migration DLC directement..."
|
||||||
|
|
||||||
|
# Appliquer la migration via exec
|
||||||
|
docker-compose exec -T logiflow-db psql -U logiflow_admin -d logiflow_db << 'EOF'
|
||||||
|
-- Migration DLC stock épuisé
|
||||||
|
ALTER TABLE dlc_products
|
||||||
|
ADD COLUMN IF NOT EXISTS stock_epuise boolean DEFAULT false NOT NULL,
|
||||||
|
ADD COLUMN IF NOT EXISTS stock_epuise_by varchar(255),
|
||||||
|
ADD COLUMN IF NOT EXISTS stock_epuise_at timestamp;
|
||||||
|
|
||||||
|
-- Index pour performance
|
||||||
|
CREATE INDEX IF NOT EXISTS idx_dlc_products_stock_epuise ON dlc_products(stock_epuise);
|
||||||
|
|
||||||
|
-- Vérification
|
||||||
|
SELECT 'Migration DLC appliquée' as status;
|
||||||
|
EOF
|
||||||
|
|
||||||
|
echo "✅ [FIX] Migration DLC appliquée avec succès"
|
||||||
|
|
||||||
|
# Redémarrer le conteneur application
|
||||||
|
echo "🔄 [FIX] Redémarrage du conteneur application..."
|
||||||
|
docker-compose restart logiflow
|
||||||
|
|
||||||
|
echo "✅ [FIX] Correction terminée"
|
||||||
Reference in new issue
Block a user