From f43e37ea99cb177554c1ef9a8fbe82479a304525 Mon Sep 17 00:00:00 2001 From: Jennifer Richards <jennifer@painless-security.com> Date: Thu, 27 Oct 2022 16:58:36 -0300 Subject: [PATCH] ci: Do the USE_TZ dance when running migrations --- dev/deploy-to-container/start.sh | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/dev/deploy-to-container/start.sh b/dev/deploy-to-container/start.sh index 37843c437..03e26d77d 100644 --- a/dev/deploy-to-container/start.sh +++ b/dev/deploy-to-container/start.sh @@ -9,7 +9,31 @@ chmod +x ./app-create-dirs.sh ./app-create-dirs.sh echo "Running Datatracker checks..." ./ietf/manage.py check -echo "Running Datatracker migrations..." -./ietf/manage.py migrate + +# Migrate, adjusting to what the current state of the underlying database might be: +WORKSPACEDIR=. +if ietf/manage.py showmigrations | grep "\[ \] 0003_pause_to_change_use_tz"; then + if grep "USE_TZ" $WORKSPACEDIR/ietf/settings_local.py; then + cat $WORKSPACEDIR/ietf/settings_local.py | sed 's/USE_TZ.*$/USE_TZ = False/' > /tmp/settings_local.py && mv /tmp/settings_local.py $WORKSPACEDIR/ietf/settings_local.py + else + echo "USE_TZ = False" >> $WORKSPACEDIR/ietf/settings_local.py + fi + echo "Running Datatracker migrations with USE_TZ = False..." + # This is expected to exit non-zero at the pause + /usr/local/bin/python $WORKSPACEDIR/ietf/manage.py migrate --settings=settings_local || true + cat $WORKSPACEDIR/ietf/settings_local.py | sed 's/USE_TZ.*$/USE_TZ = True/' > /tmp/settings_local.py && mv /tmp/settings_local.py $WORKSPACEDIR/ietf/settings_local.py + echo "Running Datatracker migrations with USE_TZ = True..." + /usr/local/bin/python $WORKSPACEDIR/ietf/manage.py migrate --settings=settings_local + +else + if grep "USE_TZ" $WORKSPACEDIR/ietf/settings_local.py; then + cat $WORKSPACEDIR/ietf/settings_local.py | sed 's/USE_TZ.*$/USE_TZ = True/' > /tmp/settings_local.py && mv /tmp/settings_local.py $WORKSPACEDIR/ietf/settings_local.py + else + echo "USE_TZ = True" >> $WORKSPACEDIR/ietf/settings_local.py + echo "Running Datatracker migrations..." + /usr/local/bin/python $WORKSPACEDIR/ietf/manage.py migrate --settings=settings_local + fi +fi + echo "Starting Datatracker..." ./ietf/manage.py runserver 0.0.0.0:8000 --settings=settings_local