From 43776944cb40808ce049d8df50cc7d5f7d76cf6a Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Mon, 18 Aug 2025 09:36:03 +0000 Subject: [PATCH 1/3] Fix error when fetching product stock information Address a database error where the `stock_epuise` column is missing in the `dlc_products` table, preventing product stock data from being retrieved. Replit-Commit-Author: Agent Replit-Commit-Session-Id: f9197b9b-a5b3-4469-a27d-930a9e9ee736 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/f9197b9b-a5b3-4469-a27d-930a9e9ee736/i2gFnxm --- ...l-orders-C-1755509679309_1755509679309.txt | 196 ++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 attached_assets/Pasted--userRole-admin-Admin-filtering-with-groupIds-1-Fetching-all-orders-C-1755509679309_1755509679309.txt diff --git a/attached_assets/Pasted--userRole-admin-Admin-filtering-with-groupIds-1-Fetching-all-orders-C-1755509679309_1755509679309.txt b/attached_assets/Pasted--userRole-admin-Admin-filtering-with-groupIds-1-Fetching-all-orders-C-1755509679309_1755509679309.txt new file mode 100644 index 0000000..b375805 --- /dev/null +++ b/attached_assets/Pasted--userRole-admin-Admin-filtering-with-groupIds-1-Fetching-all-orders-C-1755509679309_1755509679309.txt @@ -0,0 +1,196 @@ + + userRole: 'admin' + +} + +Admin filtering with groupIds: [ 1 ] + +Fetching all orders + +Customer Orders API called with: { groupIds: [ 1 ], userRole: 'admin' } + +Deliveries API called with: { + + startDate: undefined, + + endDate: undefined, + + storeId: '1', + + withBL: undefined, + + userRole: 'admin' + +} + +Admin filtering deliveries with groupIds: [ 1 ] + +Fetching all deliveries + +Customer Orders returned: 10 items + +GET /api/customer-orders 200 in 16ms + +🔗 PRODUCTION: getOrders() rĂ©cupĂ©rĂ© 33 commandes avec relations + +Orders returned: 33 items + +GET /api/orders 200 in 124ms + +🔗 PRODUCTION: getDeliveries() rĂ©cupĂ©rĂ© 49 livraisons avec relations + +Deliveries returned: 49 items + +GET /api/deliveries 200 in 140ms + +GET /api/groups 304 in 48ms + +GET /api/user 304 in 4ms + +GET /api/suppliers 304 in 9ms + +Error fetching DLC products: error: column dlc_products.stock_epuise does not exist + + at /app/node_modules/pg-pool/index.js:45:11 + + at process.processTicksAndRejections (node:internal/process/task_queues:95:5) + + at async file:///app/node_modules/drizzle-orm/node-postgres/session.js:83:22 + + at async DatabaseStorage.getDlcProducts (file:///app/dist/index.js:2187:25) + + at async file:///app/dist/index.js:6178:28 { + + length: 124, + + severity: 'ERROR', + + code: '42703', + + detail: undefined, + + hint: undefined, + + position: '337', + + internalPosition: undefined, + + internalQuery: undefined, + + where: undefined, + + schema: undefined, + + table: undefined, + + column: undefined, + + dataType: undefined, + + constraint: undefined, + + file: 'parse_relation.c', + + line: '3665', + + routine: 'errorMissingColumn' + +} + +GET /api/dlc-products 500 in 15ms + +GET /api/dlc-products 500 in 7ms + +Error fetching DLC products: error: column dlc_products.stock_epuise does not exist + + at /app/node_modules/pg-pool/index.js:45:11 + + at process.processTicksAndRejections (node:internal/process/task_queues:95:5) + + at async file:///app/node_modules/drizzle-orm/node-postgres/session.js:83:22 + + at async DatabaseStorage.getDlcProducts (file:///app/dist/index.js:2187:25) + + at async file:///app/dist/index.js:6178:28 { + + length: 124, + + severity: 'ERROR', + + code: '42703', + + detail: undefined, + + hint: undefined, + + position: '337', + + internalPosition: undefined, + + internalQuery: undefined, + + where: undefined, + + schema: undefined, + + table: undefined, + + column: undefined, + + dataType: undefined, + + constraint: undefined, + + file: 'parse_relation.c', + + line: '3665', + + routine: 'errorMissingColumn' + +} + +Error fetching DLC products: error: column dlc_products.stock_epuise does not exist + + at /app/node_modules/pg-pool/index.js:45:11 + + at process.processTicksAndRejections (node:internal/process/task_queues:95:5) + + at async file:///app/node_modules/drizzle-orm/node-postgres/session.js:83:22 + + at async DatabaseStorage.getDlcProducts (file:///app/dist/index.js:2187:25) + + at async file:///app/dist/index.js:6178:28 { + + length: 124, + + severity: 'ERROR', + + code: '42703', + + detail: undefined, + + hint: undefined, + + position: '337', + + internalPosition: undefined, + + internalQuery: undefined, + + where: undefined, + + schema: undefined, + + table: undefined, + + column: undefined, + + dataType: undefined, + + constraint: undefined, + + file: 'parse_relation.c', + + line: '3665', + + routine: 'errorMissingColumn' \ No newline at end of file From f55a7a6217dcdbd3888246e6fda8661b99091147 Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Mon, 18 Aug 2025 09:37:56 +0000 Subject: [PATCH 2/3] Add missing stock status columns and documentation for DLC products Add `stock_epuise`, `stock_epuise_by`, and `stock_epuise_at` columns to the `dlc_products` table, including SQL migration scripts and production deployment instructions to resolve a missing column error. Replit-Commit-Author: Agent Replit-Commit-Session-Id: f9197b9b-a5b3-4469-a27d-930a9e9ee736 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/f9197b9b-a5b3-4469-a27d-930a9e9ee736/i2gFnxm --- COMMANDES_PRODUCTION.md | 57 ++++++++++++++++++++++++++++++ MIGRATION_PRODUCTION_URGENTE.sql | 60 ++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 COMMANDES_PRODUCTION.md create mode 100644 MIGRATION_PRODUCTION_URGENTE.sql diff --git a/COMMANDES_PRODUCTION.md b/COMMANDES_PRODUCTION.md new file mode 100644 index 0000000..5f93569 --- /dev/null +++ b/COMMANDES_PRODUCTION.md @@ -0,0 +1,57 @@ +# MIGRATION PRODUCTION URGENTE - DLC Stock ÉpuisĂ© + +## ProblĂšme +``` +Error: column dlc_products.stock_epuise does not exist +``` + +## Solution Rapide + +### Option 1: Migration SQL directe +```bash +# Connectez-vous Ă  votre base PostgreSQL de production +psql -h [VOTRE_HOST] -U [VOTRE_USER] -d [VOTRE_DB] -f MIGRATION_PRODUCTION_URGENTE.sql +``` + +### Option 2: Commandes manuelles +```sql +-- Connectez-vous Ă  votre base et exĂ©cutez : +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; + +CREATE INDEX IF NOT EXISTS idx_dlc_products_stock_epuise ON dlc_products(stock_epuise); +``` + +### Option 3: Via Docker (si vous utilisez notre docker-compose) +```bash +# Sur votre serveur de production +./scripts/production-deploy-dlc-stock.sh +``` + +## VĂ©rification aprĂšs migration +```sql +SELECT EXISTS ( + SELECT FROM information_schema.columns + WHERE table_name='dlc_products' + AND column_name='stock_epuise' +); +``` + +RĂ©sultat attendu: `t` (true) + +## RedĂ©marrage application +AprĂšs la migration, redĂ©marrez votre application : +```bash +# Si Docker +docker-compose restart logiflow + +# Ou selon votre setup +systemctl restart votre-service +``` + +## VĂ©rification fonctionnelle +1. L'erreur "column does not exist" doit disparaĂźtre +2. L'interface DLC doit afficher les boutons PackageX et RotateCcw +3. Les fonctionnalitĂ©s stock Ă©puisĂ© doivent ĂȘtre opĂ©rationnelles \ No newline at end of file diff --git a/MIGRATION_PRODUCTION_URGENTE.sql b/MIGRATION_PRODUCTION_URGENTE.sql new file mode 100644 index 0000000..b8c96ef --- /dev/null +++ b/MIGRATION_PRODUCTION_URGENTE.sql @@ -0,0 +1,60 @@ +-- MIGRATION URGENTE PRODUCTION - DLC Stock ÉpuisĂ© +-- Date: 2025-08-18 +-- À exĂ©cuter sur votre serveur de production privĂ© + +-- VĂ©rification que la table dlc_products existe +DO $$ +BEGIN + IF NOT EXISTS (SELECT FROM information_schema.tables WHERE table_name = 'dlc_products') THEN + RAISE EXCEPTION 'ERREUR: La table dlc_products n''existe pas'; + END IF; + RAISE NOTICE 'OK: Table dlc_products trouvĂ©e'; +END +$$; + +-- VĂ©rification des colonnes existantes avant migration +SELECT 'AVANT MIGRATION - Colonnes actuelles:' as status; +SELECT column_name FROM information_schema.columns +WHERE table_name = 'dlc_products' +AND column_name IN ('stock_epuise', 'stock_epuise_by', 'stock_epuise_at') +ORDER BY column_name; + +-- Migration sĂ©curisĂ©e - Ajout des colonnes 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; + +-- Commentaires pour documenter les nouveaux champs +COMMENT ON COLUMN dlc_products.stock_epuise IS 'Indique si le produit est marquĂ© comme stock Ă©puisĂ© (diffĂ©rent de pĂ©rimĂ©)'; +COMMENT ON COLUMN dlc_products.stock_epuise_by IS 'ID de l''utilisateur qui a marquĂ© le produit comme stock Ă©puisĂ©'; +COMMENT ON COLUMN dlc_products.stock_epuise_at IS 'Date et heure de marquage du stock Ă©puisĂ©'; + +-- Index pour amĂ©liorer les performances +CREATE INDEX IF NOT EXISTS idx_dlc_products_stock_epuise ON dlc_products(stock_epuise); + +-- Initialiser tous les produits existants comme stock disponible +UPDATE dlc_products +SET stock_epuise = false +WHERE stock_epuise IS NULL; + +-- VĂ©rification finale +SELECT 'APRÈS MIGRATION - VĂ©rification:' as status; +SELECT + column_name, + data_type, + is_nullable, + column_default +FROM information_schema.columns +WHERE table_name = 'dlc_products' +AND column_name IN ('stock_epuise', 'stock_epuise_by', 'stock_epuise_at') +ORDER BY column_name; + +-- Statistiques aprĂšs migration +SELECT + COUNT(*) as total_produits, + COUNT(CASE WHEN stock_epuise = true THEN 1 END) as stock_epuise, + COUNT(CASE WHEN stock_epuise = false THEN 1 END) as stock_disponible +FROM dlc_products; + +SELECT 'MIGRATION TERMINÉE AVEC SUCCÈS' as status; \ No newline at end of file From a2554c49625d18bdc29160467306170e8c1013a2 Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Mon, 18 Aug 2025 09:39:20 +0000 Subject: [PATCH 3/3] Automate database migrations on Docker startup for production Update Dockerfile and entrypoint script to automatically run database migrations and apply schema changes upon container initialization. Replit-Commit-Author: Agent Replit-Commit-Session-Id: f9197b9b-a5b3-4469-a27d-930a9e9ee736 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/f9197b9b-a5b3-4469-a27d-930a9e9ee736/i2gFnxm --- Dockerfile | 8 +- docker-compose.yml | 2 + scripts/docker-entrypoint.sh | 116 +++++++++++++++++++------ scripts/production-deploy-dlc-stock.sh | 4 +- 4 files changed, 98 insertions(+), 32 deletions(-) mode change 100644 => 100755 scripts/docker-entrypoint.sh mode change 100755 => 100644 scripts/production-deploy-dlc-stock.sh diff --git a/Dockerfile b/Dockerfile index 7c3eba8..c3afe88 100644 --- a/Dockerfile +++ b/Dockerfile @@ -107,8 +107,10 @@ USER nextjs HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:3000/api/health || exit 1 -# Make migration script executable -RUN chmod +x /app/scripts/auto-migrate-production.sh +# Make scripts executable +RUN chmod +x /app/scripts/auto-migrate-production.sh && \ + chmod +x /app/scripts/docker-entrypoint.sh -# Start the application normally (migration will be manual or via init script) +# Use entrypoint script for automatic migrations +ENTRYPOINT ["/app/scripts/docker-entrypoint.sh"] CMD ["node", "dist/index.js"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 523516d..a6fd835 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -23,6 +23,8 @@ services: depends_on: logiflow-db: condition: service_healthy + volumes: + - ./migrations:/app/migrations healthcheck: test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:3000/api/health"] interval: 30s diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh old mode 100644 new mode 100755 index dd0f154..6ddde3e --- a/scripts/docker-entrypoint.sh +++ b/scripts/docker-entrypoint.sh @@ -1,37 +1,99 @@ #!/bin/bash -# Point d'entrĂ©e Docker avec migration automatique -# Ce script remplace le point d'entrĂ©e par dĂ©faut du conteneur + +# Script d'entrĂ©e Docker - Applique automatiquement les migrations au dĂ©marrage +# Auteur: SystĂšme de gestion automatisĂ© +# Date: 2025-08-18 set -e -echo "🚀 [ENTRYPOINT] DĂ©marrage du conteneur avec migration automatique..." +echo "🚀 [ENTRYPOINT] DĂ©marrage du conteneur de production" +echo "==================================================" -# Attendre que la base de donnĂ©es soit prĂȘte -echo "⏳ [ENTRYPOINT] Attente de la base de donnĂ©es..." -timeout=60 -counter=0 +# Fonction de logging avec timestamp +log() { + echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" +} -while ! psql "$DATABASE_URL" -c "SELECT 1;" > /dev/null 2>&1; do - counter=$((counter + 1)) - if [ $counter -gt $timeout ]; then - echo "❌ [ENTRYPOINT] Timeout: impossible de se connecter Ă  la base de donnĂ©es aprĂšs ${timeout}s" - exit 1 +log "🔧 Initialisation des variables d'environnement..." + +# Construire DATABASE_URL si nĂ©cessaire +if [ -z "$DATABASE_URL" ]; then + if [ -n "$POSTGRES_USER" ] && [ -n "$POSTGRES_PASSWORD" ] && [ -n "$POSTGRES_DB" ]; then + export DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@logiflow-db:5432/${POSTGRES_DB}" + log "✅ URL de base de donnĂ©es construite automatiquement" + else + log "⚠ Variables PostgreSQL manquantes, utilisation de DATABASE_URL existant" fi - echo "⏳ [ENTRYPOINT] Tentative $counter/$timeout..." - sleep 1 -done - -echo "✅ [ENTRYPOINT] Base de donnĂ©es accessible" - -# ExĂ©cuter les migrations automatiques -if [ -f "/app/scripts/auto-migrate-production.sh" ]; then - echo "🔄 [ENTRYPOINT] ExĂ©cution des migrations automatiques..." - chmod +x /app/scripts/auto-migrate-production.sh - /app/scripts/auto-migrate-production.sh -else - echo "⚠ [ENTRYPOINT] Script de migration non trouvĂ©, poursuite sans migration" fi -# DĂ©marrer l'application -echo "🎯 [ENTRYPOINT] DĂ©marrage de l'application..." +# Attendre que PostgreSQL soit prĂȘt +log "⏳ Attente de PostgreSQL..." +max_attempts=30 +attempt=1 + +while [ $attempt -le $max_attempts ]; do + if psql "$DATABASE_URL" -c "SELECT 1;" > /dev/null 2>&1; then + log "✅ PostgreSQL est prĂȘt" + break + fi + + if [ $attempt -eq $max_attempts ]; then + log "❌ PostgreSQL non accessible aprĂšs $max_attempts tentatives" + log "🔍 Variables DB: USER=${POSTGRES_USER:-'non dĂ©fini'} DB=${POSTGRES_DB:-'non dĂ©fini'}" + exit 1 + fi + + log "⏳ Tentative $attempt/$max_attempts - attente 2 secondes..." + sleep 2 + ((attempt++)) +done + +# ExĂ©cuter les migrations automatiques +log "🔄 ExĂ©cution des migrations automatiques..." +if [ -f "/app/scripts/auto-migrate-production.sh" ]; then + log "📂 Script de migration trouvĂ©, exĂ©cution..." + chmod +x /app/scripts/auto-migrate-production.sh + + if /app/scripts/auto-migrate-production.sh; then + log "✅ Migrations exĂ©cutĂ©es avec succĂšs" + else + log "❌ Erreur lors des migrations" + exit 1 + fi +else + log "⚠ Script de migration non trouvĂ© Ă  /app/scripts/auto-migrate-production.sh" + log "🔍 Contenu du rĂ©pertoire scripts:" + ls -la /app/scripts/ || echo "RĂ©pertoire scripts non trouvĂ©" +fi + +# VĂ©rification post-migration +log "🔍 VĂ©rification des colonnes DLC..." +if psql "$DATABASE_URL" -tAc "SELECT EXISTS (SELECT FROM information_schema.columns WHERE table_name='dlc_products' AND column_name='stock_epuise');" | grep -q "t"; then + log "✅ Colonnes DLC stock Ă©puisĂ© prĂ©sentes" +else + log "❌ Colonnes DLC stock Ă©puisĂ© manquantes" + log "đŸ› ïž Tentative de migration directe..." + + psql "$DATABASE_URL" << 'EOF' +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; + +CREATE INDEX IF NOT EXISTS idx_dlc_products_stock_epuise ON dlc_products(stock_epuise); +EOF + + if [ $? -eq 0 ]; then + log "✅ Migration directe rĂ©ussie" + else + log "❌ Migration directe Ă©chouĂ©e" + exit 1 + fi +fi + +# DĂ©marrage de l'application +log "🚀 DĂ©marrage de l'application..." +log "==================================================" + +# ExĂ©cuter la commande passĂ©e en paramĂštre (normalement "node dist/index.js") exec "$@" \ No newline at end of file diff --git a/scripts/production-deploy-dlc-stock.sh b/scripts/production-deploy-dlc-stock.sh old mode 100755 new mode 100644 index 126e66a..7562a77 --- a/scripts/production-deploy-dlc-stock.sh +++ b/scripts/production-deploy-dlc-stock.sh @@ -95,8 +95,8 @@ else log "⚠ Erreur lors de la migration - vĂ©rification manuelle nĂ©cessaire" fi -# DĂ©marrage complet de l'application -log "🚀 DĂ©marrage complet de l'application..." +# DĂ©marrage complet de l'application (la migration sera automatique) +log "🚀 DĂ©marrage complet de l'application avec migration automatique..." docker-compose up -d # Attendre que l'application soit prĂȘte