11function _pantheon_deploy() {
22 _assert_terminus_vars
3+ local major_upgrade=false
4+ if _drupal_major_upgrade_pending; then
5+ major_upgrade=true
6+ fi
37 terminus drush -- state-set system.maintenance_mode TRUE
48 terminus env:clear-cache
59 terminus env:deploy $deploy_args
10+ if $major_upgrade ; then
11+ # A new major version of core can't rebuild its cache against the old
12+ # schema, so the database updates must run before cache-rebuild.
13+ terminus drush -- updatedb -y
14+ fi
615 _pantheon_complete_deployment
716}
817
18+ # Succeeds when the code being deployed runs a newer Drupal major version than
19+ # the database that will end up in the target environment.
20+ function _drupal_major_upgrade_pending() {
21+ local code_env db_env code_version db_version
22+ case " $TERMINUS_ENV " in
23+ test) code_env=" dev" ;;
24+ live) code_env=" test" ;;
25+ * ) return 1 ;;
26+ esac
27+ # --sync-content replaces the target's database with LIVE's.
28+ if [[ " $deploy_args " == * " --sync-content " * ]]; then
29+ db_env=" live"
30+ else
31+ db_env=" $TERMINUS_ENV "
32+ fi
33+ code_version=$( terminus drush " $TERMINUS_SITE .$code_env " -- status --field=drupal-version) || return 1
34+ db_version=$( terminus drush " $TERMINUS_SITE .$db_env " -- status --field=drupal-version) || return 1
35+ echo " Drupal core: $code_version on $code_env , $db_version on $db_env "
36+ if [ " ${code_version%% .* } " -gt " ${db_version%% .* } " ]; then
37+ echo " Major version upgrade detected; database updates will run before cache-rebuild."
38+ return 0
39+ fi
40+ return 1
41+ }
42+
943function _pantheon_complete_deployment() {
1044 terminus drush -- cache-rebuild
1145 terminus drush -- deploy
1246 sleep 60
1347 terminus drush -- state-set system.maintenance_mode FALSE
1448 terminus env:clear-cache
15- }
49+ }
0 commit comments