#!/bin/sh

WAREHOUSES=1
DBMS="pgsql"

if [ $# -ge 1 ]; then
	WAREHOUSES=$1
fi

if [ $# -ge 2 ]; then
	DBMS=$2
fi

CONTAINER_DIR="$(dirname "$0")"

"$CONTAINER_DIR/prepare-image" || exit 1

# The database creation runs its data load through the dbt2-driver image,
# so build the client and driver images first.
"$CONTAINER_DIR/build-client" &
CLIENTPID=$!
"$CONTAINER_DIR/build-driver" &
DRIVERPID=$!
RC=0
wait "$CLIENTPID" || RC=1
wait "$DRIVERPID" || RC=1
if [ $RC -ne 0 ]; then
	echo "ERROR: building the client or driver image failed"
	exit 1
fi

"$CONTAINER_DIR/build-database" "$WAREHOUSES" "$DBMS" || exit 1
