diff --git a/.gitea/workflows/build-and-deploy.yml b/.gitea/workflows/build-and-deploy.yml index 3ed0779..62a1397 100644 --- a/.gitea/workflows/build-and-deploy.yml +++ b/.gitea/workflows/build-and-deploy.yml @@ -45,3 +45,17 @@ jobs: docker compose pull docker compose --project-name $APP_NAME down docker compose --project-name $APP_NAME up -d --remove-orphans --wait + + # Inicializar base de datos si es necesario + echo "🗄️ Inicializando base de datos..." + # Verificar si las tablas existen + TABLE_EXISTS=$(docker exec $APP_NAME-postgres psql -U $POSTGRES_USER -d $POSTGRES_DB -tAc "SELECT EXISTS (SELECT FROM information_schema.tables WHERE table_name = 'lotes');") + + if [ "$TABLE_EXISTS" = "f" ]; then + echo "📝 Ejecutando scripts de inicialización..." + docker exec -i $APP_NAME-postgres psql -U $POSTGRES_USER -d $POSTGRES_DB < nuxt4/server/database/01_schema.sql + docker exec -i $APP_NAME-postgres psql -U $POSTGRES_USER -d $POSTGRES_DB < nuxt4/server/database/02_seed.sql + echo "✅ Base de datos inicializada" + else + echo "ℹ️ Base de datos ya inicializada" + fi