# ==============================================================================
# DATA PERSISTENCE TIER: POSTGRESQL EXTENDED DATABASE ENGINE (Dockerfile)
# ==============================================================================
# ARCHITECTURE INTENTION:
# This Dockerfile provisions an isolated, enterprise-grade relational database backplane
# featuring native vector search capability via the pgvector extension. It provides
# a deterministic data foundation suitable for AI-augmented enterprise applications 
# (such as intra-mart storage clusters and embedding retrieval models).
#
# DESIGN ADVANTAGES & AUTOMATION SEEDING:
# 1. Automatic Schema Initialisation: By copying the structural SQL script into the 
#    designated entrypoint directory (/docker-entrypoint-initdb.d/), the Postgres 
#    engine automatically triggers and mounts your schemas, extensions (vector), and 
#    seed structures during its first boot cycle without requiring external manual scripts.
# 2. Immutable Infrastructure Seeding: Permission configurations and module extensions 
#    are fully handled during image compilation time, ensuring high reliability across 
#    different staging environments (development, testing, production).
# ==============================================================================

# Uses the optimized PostgreSQL 17 engine base image pre-bundled with pgvector binary wrappers
FROM pgvector/pgvector:pg17

# ------------------------------------------------------------------------------
# 1. DATABASE STATE SEEDING PIPELINE
# ------------------------------------------------------------------------------
# Mounts the initialization script into the container engine startup sequence folder.
# Files matching *.sql in this directory are sequentially executed on a blank cluster init.
COPY ./init-db.sql /docker-entrypoint-initdb.d/01-init-vector.sql

# ------------------------------------------------------------------------------
# 2. SECURITY ENVIRONMENT & FILE ACCESS CORRECTION
# ------------------------------------------------------------------------------
# Enforces standard read permissions on the injected initialization file, ensuring 
# the internal non-root 'postgres' OS user can execute the schema initialization query.
RUN chmod 644 /docker-entrypoint-initdb.d/01-init-vector.sql

# ------------------------------------------------------------------------------
# 3. NETWORK EGRESS ENTRYPOINT BOUNDARY
# ------------------------------------------------------------------------------
# Declares that the container environment listens on the default PostgreSQL TCP runtime port.
EXPOSE 5432