services:
  postgres:
    image: postgres:17-alpine
    environment:
      POSTGRES_DB: n8n
      POSTGRES_USER: n8n
      POSTGRES_PASSWORD: ${N8N_FIXTURE_PG_PASSWORD:?Choose a local database password}
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD", "pg_isready", "-U", "n8n", "-d", "n8n"]
      interval: 3s
      timeout: 3s
      retries: 12
  n8n:
    image: n8nio/n8n:2.49.7
    depends_on:
      postgres:
        condition: service_healthy
    ports:
      - '127.0.0.1:45770:5678'
    volumes:
      - n8ndata:/home/node/.n8n
    environment:
      DB_TYPE: postgresdb
      DB_POSTGRESDB_HOST: postgres
      DB_POSTGRESDB_DATABASE: n8n
      DB_POSTGRESDB_USER: n8n
      DB_POSTGRESDB_PASSWORD: ${N8N_FIXTURE_PG_PASSWORD:?Choose a local database password}
      N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS: 'true'
      N8N_DIAGNOSTICS_ENABLED: 'false'
    healthcheck:
      test: ["CMD", "node", "-e", "fetch('http://127.0.0.1:5678/healthz/readiness').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"]
      interval: 5s
      timeout: 3s
      retries: 15
volumes:
  pgdata:
  n8ndata:
