From b22e586670f1c3032ebb304bb8d48980155599dd Mon Sep 17 00:00:00 2001 From: Sean Kelly Date: Fri, 1 Sep 2023 13:25:52 -0500 Subject: [PATCH] WIP #282: add upgrade step --- .../management/commands/edrn_explorer.py | 45 +++---------------- support/cbiit-deploy-prod.sh | 24 ++-------- support/cbiit-deploy.sh | 24 ++-------- support/devrebuild.sh | 5 +-- 4 files changed, 16 insertions(+), 82 deletions(-) diff --git a/src/edrnsite.content/src/edrnsite/content/management/commands/edrn_explorer.py b/src/edrnsite.content/src/edrnsite/content/management/commands/edrn_explorer.py index 2e8c156f..690bbb1f 100644 --- a/src/edrnsite.content/src/edrnsite/content/management/commands/edrn_explorer.py +++ b/src/edrnsite.content/src/edrnsite/content/management/commands/edrn_explorer.py @@ -4,59 +4,26 @@ from django.conf import settings from django.core.management.base import BaseCommand -from edrnsite.content.models import FlexPage, CDEExplorerPage +from edrnsite.content.models import CDEExplorerPage from edrnsite.policy.management.commands.utils import set_site -from wagtail.rich_text import RichText class Command(BaseCommand): help = 'Install explorers' - def _append_link_to_page(self, dest, link_text, page): - '''Append a link to a ``page`` with the given ``link_text`` to the body stream on the ``dest`` page. - - There has GOT to be a better way of doing this! - ''' - blocks = dest.body.get_prep_value() - while True: - try: - dest.body.pop() - except IndexError: - break - for block in blocks: - if block['type'] == 'rich_text': - dest.body.append(('rich_text', RichText(block['value']))) - else: - raise ValueError(f'Unexpected block type {block["type"]}') - dest.body.append(('rich_text', RichText(f'

New: explore the {link_text}.

'))) - dest.save() - - def _install_cde_explorer(self, home_page): - self.stdout.write('Installing the official CDE Explorer') - - CDEExplorerPage.objects.all().delete() - dest = FlexPage.objects.descendant_of(home_page).filter(slug='cde').first() - assert dest is not None - - page = CDEExplorerPage( - title='EDRN Data Model', live=True, show_in_menus=False, - spreadsheet_id='1PAVUvmi0J-j6fK5dpltRIW8vRzVjh4kzpNReGFOQIe4', - search_description='A tree-like explorer of the Common Data Elements (CDEs) of the Early Detection Research Network.', - ) - dest.add_child(instance=page) - page.save() - page.update_nodes() - self._append_link_to_page(dest, 'EDRN Data Model', page) + def _update_cde_explorer(self, home_page): + for page in CDEExplorerPage.objects.all(): + page.update_nodes() def handle(self, *args, **options): - self.stdout.write('Installing explorers') + self.stdout.write('Updating CDE explorer') old = getattr(settings, 'WAGTAILREDIRECTS_AUTO_CREATE', True) try: settings.WAGTAILREDIRECTS_AUTO_CREATE = False settings.WAGTAILSEARCH_BACKENDS['default']['AUTO_UPDATE'] = False site, home_page = set_site() - self._install_cde_explorer(home_page) + self._update_cde_explorer(home_page) finally: settings.WAGTAILREDIRECTS_AUTO_CREATE = old diff --git a/support/cbiit-deploy-prod.sh b/support/cbiit-deploy-prod.sh index a012948f..9f630413 100755 --- a/support/cbiit-deploy-prod.sh +++ b/support/cbiit-deploy-prod.sh @@ -134,26 +134,10 @@ docker compose --project-name edrn stop search &&\ sleep 60 &&\ docker compose --project-name edrn start portal" || exit 1 -# There are on upgrade steps at this time - -# echo "" -# echo "🆙 Applying upgrades" -# ssh -q $USER@$WEBSERVER "cd $WEBROOT ; \ -# docker compose --project-name edrn exec portal django-admin edrn_explorer && -# docker compose --project-name edrn exec portal django-admin edrn_pubmed || true && -# docker compose --project-name edrn exec portal django-admin edrn_pubmed || true && -# docker compose --project-name edrn exec portal django-admin edrn_pubmed || true && -# docker compose --project-name edrn exec portal django-admin edrn_pubmed || true && -# docker compose --project-name edrn exec portal django-admin edrn_pubmed || true && -# docker compose --project-name edrn exec portal django-admin edrn_pubmed || true && -# docker compose --project-name edrn exec portal django-admin edrn_pubmed || true && -# docker compose --project-name edrn exec portal django-admin edrn_pubmed || true && -# docker compose --project-name edrn exec portal django-admin edrn_pubmed || true && -# docker compose --project-name edrn exec portal django-admin edrn_pubmed || true && -# docker compose --project-name edrn exec portal django-admin edrn_pubmed && -# docker compose --project-name edrn exec portal django-admin edrn_forms" || exit 1 - -# ↑ We might need to repeat that edrn_pubmed step several times if memory is an issue +echo "" +echo "🆙 Applying upgrades" +ssh -q $USER@$WEBSERVER "cd $WEBROOT ; \ +docker compose --project-name edrn exec portal django-admin edrn_explorer" || exit 1 echo "" echo "🤷‍♀️ Final portal restart and restart of search engine" diff --git a/support/cbiit-deploy.sh b/support/cbiit-deploy.sh index 1a8e1e7a..66fe21d7 100755 --- a/support/cbiit-deploy.sh +++ b/support/cbiit-deploy.sh @@ -139,26 +139,10 @@ docker compose --project-name edrn stop search &&\ sleep 60 &&\ docker compose --project-name edrn start portal" || exit 1 -# There are no upgrade steps at this time - -# echo "" -# echo "🆙 Applying upgrades" -# ssh -q $USER@$WEBSERVER "cd $WEBROOT ; \ -# docker compose --project-name edrn exec portal django-admin edrn_explorer && -# docker compose --project-name edrn exec portal django-admin edrn_pubmed || true && -# docker compose --project-name edrn exec portal django-admin edrn_pubmed || true && -# docker compose --project-name edrn exec portal django-admin edrn_pubmed || true && -# docker compose --project-name edrn exec portal django-admin edrn_pubmed || true && -# docker compose --project-name edrn exec portal django-admin edrn_pubmed || true && -# docker compose --project-name edrn exec portal django-admin edrn_pubmed || true && -# docker compose --project-name edrn exec portal django-admin edrn_pubmed || true && -# docker compose --project-name edrn exec portal django-admin edrn_pubmed || true && -# docker compose --project-name edrn exec portal django-admin edrn_pubmed || true && -# docker compose --project-name edrn exec portal django-admin edrn_pubmed || true && -# docker compose --project-name edrn exec portal django-admin edrn_pubmed && -# docker compose --project-name edrn exec portal django-admin edrn_forms" || exit 1 - -# ↑ We might need to repeat that edrn_pubmed step several times if memory is an issue +echo "" +echo "🆙 Applying upgrades" +ssh -q $USER@$WEBSERVER "cd $WEBROOT ; \ +docker compose --project-name edrn exec portal django-admin edrn_explorer" || exit 1 echo "" echo "🤷‍♀️ Final portal restart and restart of search engine" diff --git a/support/devrebuild.sh b/support/devrebuild.sh index 598e16c5..31ae904e 100755 --- a/support/devrebuild.sh +++ b/support/devrebuild.sh @@ -53,9 +53,8 @@ bzip2 --decompress --stdout edrn.sql.bz2 | psql --dbname=edrn --echo-errors --qu ./manage.sh edrndevreset # Add additional upgrade steps here: -# ./manage.sh edrn_explorer -# ./manage.sh edrn_pubmed -# ./manage.sh edrn_forms +./manage.sh edrn_explorer + # This may be optional if you want to save time: ./manage.sh rdfingest