Skip to content

Commit

Permalink
WIP #282: add upgrade step
Browse files Browse the repository at this point in the history
  • Loading branch information
nutjob4life committed Sep 1, 2023
1 parent b2765c7 commit b22e586
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'<p><strong>New</strong>: explore the <a id="{page.pk}" linktype="page">{link_text}</a>.</p>')))
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
Expand Down
24 changes: 4 additions & 20 deletions support/cbiit-deploy-prod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
24 changes: 4 additions & 20 deletions support/cbiit-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 2 additions & 3 deletions support/devrebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b22e586

Please sign in to comment.