Skip to main content

Update

This guide explains how to update PCH-SIG to a new version.

Preparation

Check current version

# Backend version
docker exec pch_backend php bin/console --version

# Frontend version (in package.json)
cat frontend/package.json | grep version

Backup before update

Important

Always perform a complete backup before any update.

# Quick backup
docker exec pch_postgres pg_dump -U pch_admin pch_sig > backup_before_update.sql

Frontend Update

Step 1: Get changes

cd frontend

# Get latest changes
git pull origin main

# Install new dependencies
npm install

Step 2: Production build

npm run build

Step 3: Deploy to server

# Create PowerShell session
$cred = Get-Credential
$session = New-PSSession -ComputerName serveur-production -Credential $cred

# Copy the build
Copy-Item -Path ".\build\*" -Destination "C:\pch-sig\frontend\build" -ToSession $session -Recurse -Force

# Restart the container
Invoke-Command -Session $session -ScriptBlock {
docker-machine ssh default "docker restart pch_frontend"
}

Remove-PSSession $session

Step 4: Update Service Worker

Increment cache version in frontend/public/service-worker.js:

// Before
const CACHE_NAME = 'pch-sig-cache-v2';

// After
const CACHE_NAME = 'pch-sig-cache-v3';

Backend Update

Step 1: Get changes

cd backend

# Get latest changes
git pull origin main

# Install dependencies
composer install --no-dev --optimize-autoloader

Step 2: Run migrations

# Check pending migrations
php bin/console doctrine:migrations:status

# Run migrations
php bin/console doctrine:migrations:migrate --no-interaction

Step 3: Clear cache

php bin/console cache:clear --env=prod
php bin/console cache:warmup --env=prod

Step 4: Deploy to server

# Copy backend files
Copy-Item -Path ".\src\*" -Destination "C:\pch-sig\backend\src" -ToSession $session -Recurse -Force
Copy-Item -Path ".\config\*" -Destination "C:\pch-sig\backend\config" -ToSession $session -Recurse -Force

# Run migrations on server
Invoke-Command -Session $session -ScriptBlock {
docker exec pch_backend php bin/console doctrine:migrations:migrate --no-interaction
docker exec pch_backend php bin/console cache:clear --env=prod
}

Docker Container Update

Update images

cd deploy

# Download new images
docker compose pull

# Restart with new images
docker compose up -d

Rebuild a custom image

If you modified a Dockerfile:

# Rebuild backend image
docker compose build backend

# Restart the container
docker compose up -d backend

Database Migration Management

Check migration status

docker exec pch_backend php bin/console doctrine:migrations:status

Create a new migration

docker exec pch_backend php bin/console make:migration

Revert last migration

docker exec pch_backend php bin/console doctrine:migrations:migrate prev

Execute a specific migration

docker exec pch_backend php bin/console doctrine:migrations:execute 'DoctrineMigrations\Version20240115120000' --up

Rollback in case of problems

Restore frontend

# Backups are in C:\pch-sig\backups\
Copy-Item -Path "C:\pch-sig\backups\frontend-YYYYMMDD\*" -Destination "C:\pch-sig\frontend\build" -Recurse -Force

docker restart pch_frontend

Restore backend

# Revert to previous code version
git checkout HEAD~1

# Revert migrations
docker exec pch_backend php bin/console doctrine:migrations:migrate prev

Restore database

# Restore from backup
docker exec -i pch_postgres psql -U pch_admin -d pch_sig < backup_before_update.sql

Major updates

PHP version change

  1. Update image in docker-compose.yml
  2. Check Composer dependency compatibility
  3. Test in development environment
  4. Deploy to production

PostgreSQL version change

  1. Export all data
  2. Stop old container
  3. Update image
  4. Restore data
# Full export
docker exec pch_postgres pg_dumpall -U pch_admin > full_backup.sql

# Update and restore
docker compose down postgres
# Modify version in docker-compose.yml
docker compose up -d postgres
docker exec -i pch_postgres psql -U pch_admin < full_backup.sql

Update checklist

  • Backup database
  • Backup configuration files
  • Note current version
  • Get changes (git pull)
  • Install dependencies
  • Run migrations
  • Clear cache
  • Deploy to server
  • Test application
  • Update Service Worker version
  • Inform users

Next steps