FROM postgres:15-alpine

# Set timezone
ENV TZ=UTC

# Copy initialization script
COPY init.sql /docker-entrypoint-initdb.d/

# Copy backup script
COPY backup.sh /usr/local/bin/backup.sh
RUN chmod +x /usr/local/bin/backup.sh

# Create backup directory
RUN mkdir -p /backups && chown postgres:postgres /backups

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
  CMD pg_isready -U ${POSTGRES_USER} || exit 1

# Run as non-root
USER postgres