services:
  nordicstorium-app:
    build: .
    container_name: nordicstorium-app
    restart: unless-stopped
    ports:
      - "3000:3000"
    environment:
      NODE_ENV: development
      DB_HOST: nordicstorium-db
      DB_PORT: 3306
      DB_NAME: nordic_storium
      DB_USER: nordic_app_user
      DB_PASSWORD: ${APP_DB_PASSWORD}
      DATABASE_URL: "mysql://nordic_app_user:${APP_DB_PASSWORD}@nordicstorium-db:3306/nordic_storium"
      JWT_SECRET: ${JWT_SECRET}
    volumes:
      - ./:/app
      - /app/node_modules
      - /app/.next
    depends_on:
      nordicstorium-db:
        condition: service_healthy

  nordicstorium-db:
    image: mariadb:10.11.4
    container_name: nordicstorium-db
    restart: unless-stopped
    ports:
      - "3306:3306"
    environment:
      MARIADB_ROOT_PASSWORD: ${ROOT_DB_PASSWORD}
      MARIADB_DATABASE: nordic_storium
      MARIADB_USER: nordic_app_user
      MARIADB_PASSWORD: ${APP_DB_PASSWORD}
      MARIADB_ROOT_HOST: "%"
    command: 
      - --character-set-server=utf8mb4
      - --collation-server=utf8mb4_unicode_ci
      - --skip-name-resolve
      - --bind-address=0.0.0.0
    volumes:
      - nordicstorium-mysql-data:/var/lib/mysql
      - ./schemas:/docker-entrypoint-initdb.d
    healthcheck:
      test: ["CMD", "healthcheck.sh", "--connect"]
      start_period: 30s
      interval: 10s
      timeout: 5s
      retries: 5

  nordicstorium-phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    container_name: nordicstorium-phpmyadmin
    restart: unless-stopped
    ports:
      - "8081:80"
    environment:
      PMA_HOST: nordicstorium-db
      PMA_PORT: 3306
      PMA_ARBITRARY: 0
      UPLOAD_LIMIT: 50M
      # Remove auto-login - user must login manually
      # PMA_USER and PMA_PASSWORD are NOT set - this forces login
    volumes:
      - phpmyadmin-sessions:/sessions
    depends_on:
      nordicstorium-db:
        condition: service_healthy

volumes:
  nordicstorium-mysql-data:
  phpmyadmin-sessions: