# federatedcomputer/superbrain-migrate — self-contained database bootstrap
# and migration runner. Ships db/ inside the image so the server never needs
# the source tree. Entrypoint: bootstrap.sh (empty database => schema.sql as
# DB_USER, then always the checksummed migration ledger).
#
# Also ships deploy/federated/ at /deploy (install.sh, update.sh and the
# suite integration files), so a core host needs nothing but this image:
#   docker run --rm federatedcomputer/superbrain-migrate cat /deploy/install.sh
# The files arrive via a named build context (BuildKit/buildx only; the dev
# compose never builds this image):
#   docker buildx build --build-context deploy=deploy/federated db/
#
# Base image = the same postgres alpine the dev stack's migrate service uses;
# only the psql client is exercised. Client 16 against a newer server (the
# federated suite runs 17.x) is the supported direction.
FROM postgres:16.15-alpine

COPY . /db
COPY --from=deploy . /deploy
RUN chmod +x /db/bootstrap.sh /db/migrate.sh /deploy/install.sh /deploy/update.sh

WORKDIR /db
CMD ["sh", "/db/bootstrap.sh"]
