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

  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. info Removing cache before migration
  30. rm -rf "$SERVICE_DATASTORE/var/cache/gogocarto/prod/"*
  31. info Launch migration
  32. symphony db:migrate
  33. } || {
  34. err "Mongo database migration failed."
  35. exit 1
  36. }
  37. exit 0
  38. fi
  39. ## came from ``Makefile`` in git's gogocarto source code. Target load-fixtures.
  40. symphony doctrine:mongodb:schema:create &&
  41. symphony doctrine:mongodb:generate:hydrators &&
  42. symphony doctrine:mongodb:generate:proxies &&
  43. symphony doctrine:mongodb:fixtures:load -n || {
  44. err "Mongo database initialization failed."
  45. exit 1
  46. }
  47. touch "$inited"