Skip to content

Commit 5baf704

Browse files
authored
Merge pull request #62 from UCEAP/d11-upgrade-updb
Run updatedb before cache-rebuild on Drupal major upgrades
2 parents cfd8374 + 1780e49 commit 5baf704

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,49 @@
11
function _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+
943
function _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

Comments
 (0)