fork 0k-charms
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

65 lines
1.3 KiB

#!/bin/bash
. lib/common
set -e
DBNAME="$(relation-get dbname)" || exit 1
initing="${GOGOCARTO_CODE}"/.initing-${DBNAME}
if [ -e "$initing" ]; then
exit 0
fi
inited="${GOGOCARTO_CODE}"/.inited-${DBNAME}
MONGO_URL=mongodb://${TARGET_SERVICE_NAME}:27017
cat <<EOF >> ${GOGOCARTO_CODE}/.env
###> doctrine/mongodb-odm-bundle ###
MONGODB_URL=$MONGO_URL
MONGODB_DATABASE=$DBNAME
###< doctrine/mongodb-odm-bundle ###
DATABASE_NAME=$DBNAME
EOF
touch "$initing"
trap_add EXIT,ERR "rm -v \"$initing\""
if [ -e "$inited" ]; then
{
## This is required for migrating to 3.4.10 correctly
compose --debug mongosh "$SERVICE_NAME" <<EOF &&
db.Configuration.findOneAndUpdate(
{ dbName : null },
{ \$set: { "dbName" : "$DBNAME"} }
);
EOF
info Removing cache before migration
rm -rf "$SERVICE_DATASTORE/var/cache/gogocarto/prod/"*
info Launch migration
symphony db:migrate
} || {
err "Mongo database migration failed."
exit 1
}
exit 0
fi
## came from ``Makefile`` in git's gogocarto source code. Target load-fixtures.
symphony doctrine:mongodb:schema:create &&
symphony doctrine:mongodb:generate:hydrators &&
symphony doctrine:mongodb:generate:proxies &&
symphony doctrine:mongodb:fixtures:load -n || {
err "Mongo database initialization failed."
exit 1
}
touch "$inited"