Allow to restore a database instead of creating from scratch
Provide an option or an environmental variable to decide to create base from scratch or to restore it from a pg dump. Example below for a kubernetes deployment (from FA, not in prod):
apiVersion: apps/v1
kind: Deployment
metadata:
name: francearchives
spec:
template:
spec:
initContainers:
- name: francearchives-db-create
args:
- "-c"
- |
echo "checking postgresql database $CW_DB_NAME if it doesn't exist, create it with pg_restore";
if [ "$(PGPASSWORD=$CW_DB_PASSWORD psql -h $CW_DB_HOST -p $CW_DB_PORT -d template1 -tAc "SELECT 1 FROM pg_database WHERE datname='$CW_DB_NAME'")" = '1' ]; then
echo "database exists"
else
echo "download dump"
wget https://example.org/database.tgz
echo "uncompress dump"
tar xvfz database.tgz
echo "createdb"
PGPASSWORD=$CW_DB_PASSWORD createdb -h $CW_DB_HOST -p $CW_DB_PORT $CW_DB_NAME
echo "pg_restore"
PGPASSWORD=$CW_DB_PASSWORD pg_restore -h $CW_DB_HOST -p $CW_DB_PORT -d $CW_DB_NAME --no-owner -F d database
echo "reset password"
cubicweb-ctl reset-admin-pwd -p $CW_PASSWORD $CW_INSTANCE
echo "upgrade"
cubicweb-ctl upgrade --backup-db=n --fs-only --force --verbosity=0 "$(CW_INSTANCE)"
fi
echo "done"
This could be useful for reviewapps.