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.

61 lines
1.2 KiB

  1. #!/bin/bash
  2. . lib/common
  3. set -e
  4. DBNAME="$(relation-get dbname)" || exit 1
  5. initing="${GOGOCARTO_CODE}"/.initing-${DBNAME}
  6. if [ -e "$initing" ]; then
  7. exit 0
  8. fi
  9. inited="${GOGOCARTO_CODE}"/.inited-${DBNAME}
  10. MONGO_URL=mongodb://${TARGET_SERVICE_NAME}:27017
  11. cat <<EOF >> ${GOGOCARTO_CODE}/.env
  12. ###> doctrine/mongodb-odm-bundle ###
  13. MONGODB_URL=$MONGO_URL
  14. MONGODB_DATABASE=$DBNAME
  15. ###< doctrine/mongodb-odm-bundle ###
  16. DATABASE_NAME=$DBNAME
  17. EOF
  18. touch "$initing"
  19. trap_add EXIT,ERR "rm -v \"$initing\""
  20. if [ -e "$inited" ]; then
  21. {
  22. ## This is required for migrating to 3.4.10 correctly
  23. compose --debug mongosh "$SERVICE_NAME" <<EOF &&
  24. db.Configuration.findOneAndUpdate(
  25. { dbName : null },
  26. { \$set: { "dbName" : "$DBNAME"} }
  27. );
  28. EOF
  29. symphony db:migrate
  30. } || {
  31. err "Mongo database migration failed."
  32. exit 1
  33. }
  34. exit 0
  35. fi
  36. ## came from ``Makefile`` in git's gogocarto source code. Target load-fixtures.
  37. symphony doctrine:mongodb:schema:create &&
  38. symphony doctrine:mongodb:generate:hydrators &&
  39. symphony doctrine:mongodb:generate:proxies &&
  40. symphony doctrine:mongodb:fixtures:load -n || {
  41. err "Mongo database initialization failed."
  42. exit 1
  43. }
  44. touch "$inited"