FROM postgres:16

ENV DEBIAN_FRONTEND=noninteractive

# Instala dependencias necesarias para compilar extensiones
RUN apt-get update && apt-get install -y \
    build-essential \
    git \
    wget \
    curl \
    ca-certificates \
    postgresql-server-dev-16 \
    cmake \
    pkg-config \
    zlib1g-dev \
    && rm -rf /var/lib/apt/lists/*

# Instala pgvector
RUN git clone --branch v0.7.0 https://github.com/pgvector/pgvector.git && \
    cd pgvector && make && make install && \
    cd .. && rm -rf pgvector

# Instala TimescaleDB
# Clona y compila TimescaleDB
RUN git clone --branch 2.14.2 https://github.com/timescale/timescaledb.git && \
    cd timescaledb && \
    mkdir build && cd build && \
    cmake -DCMAKE_BUILD_TYPE=Release -DREGRESS_CHECKS=OFF .. && \
    make && make install && \
    cd ../.. && rm -rf timescaledb

# Copia script de inicialización
COPY ./init.sql /docker-entrypoint-initdb.d/init.sql