Improve DB reset for caprover deployment

This commit is contained in:
Daniel Egger 2022-06-28 13:42:40 +02:00
parent ad380f741e
commit 4b02991f0d
5 changed files with 20 additions and 16 deletions

View File

@ -4,15 +4,9 @@ set -o errexit
set -o pipefail set -o pipefail
set -o nounset set -o nounset
python /app/manage.py collectstatic --noinput
# TODO remove after stabilisation # TODO remove after stabilisation
python /app/manage.py reset_schema python /app/manage.py reset_schema
python /app/manage.py collectstatic --noinput
python /app/manage.py createcachetable
python /app/manage.py migrate
# TODO remove after stabilisation
python /app/manage.py create_default_users
python /app/manage.py create_default_learning_path
/usr/local/bin/gunicorn config.asgi --bind 0.0.0.0:80 --chdir=/app -k uvicorn.workers.UvicornWorker /usr/local/bin/gunicorn config.asgi --bind 0.0.0.0:80 --chdir=/app -k uvicorn.workers.UvicornWorker

View File

@ -17,8 +17,7 @@ from vbv_lernwelt.core.middleware.auth import django_view_authentication_exempt
from vbv_lernwelt.core.views import ( from vbv_lernwelt.core.views import (
rate_limit_exceeded_view, rate_limit_exceeded_view,
permission_denied_view, permission_denied_view,
check_rate_limit, cypress_reset_view, vue_home, check_rate_limit, cypress_reset_view, vue_home, )
)
from .wagtail_api import wagtail_api_router from .wagtail_api import wagtail_api_router
@ -67,7 +66,7 @@ urlpatterns += [
if settings.APP_ENVIRONMENT != 'production': if settings.APP_ENVIRONMENT != 'production':
urlpatterns += [ urlpatterns += [
re_path(r'cypressreset/$', cypress_reset_view, name='cypress_reset_view'), re_path(r'core/cypressreset/$', cypress_reset_view, name='cypress_reset_view'),
] ]
# fmt: on # fmt: on

View File

@ -1,5 +1,6 @@
import djclick as click import djclick as click
from django.conf import settings from django.conf import settings
from django.core.management import call_command
from django.db import transaction, connection from django.db import transaction, connection
@ -24,3 +25,7 @@ def command():
print(user) print(user)
reset_schema(db_config_user=user) reset_schema(db_config_user=user)
call_command('createcachetable')
call_command('migrate')
call_command('create_default_users')
call_command('create_default_learning_path')

View File

@ -5,7 +5,8 @@ from wagtail.models import Site, Page, Locale
from wagtail_localize.models import LocaleSynchronization from wagtail_localize.models import LocaleSynchronization
from vbv_lernwelt.core.admin import User from vbv_lernwelt.core.admin import User
from vbv_lernwelt.learnpath.models import LearningPath, Topic, Circle, LearningSequence, LearningContent from vbv_lernwelt.learnpath.models import LearningPath, Topic, Circle, LearningSequence, LearningContent, LearningUnit, \
LearningUnitQuestion
from vbv_lernwelt.learnpath.tests.learning_path_factories import LearningPathFactory, TopicFactory, CircleFactory, \ from vbv_lernwelt.learnpath.tests.learning_path_factories import LearningPathFactory, TopicFactory, CircleFactory, \
LearningSequenceFactory, LearningContentFactory, VideoBlockFactory, PodcastBlockFactory, CompetenceBlockFactory, \ LearningSequenceFactory, LearningContentFactory, VideoBlockFactory, PodcastBlockFactory, CompetenceBlockFactory, \
ExerciseBlockFactory, DocumentBlockFactory, LearningUnitFactory, LearningUnitQuestionFactory ExerciseBlockFactory, DocumentBlockFactory, LearningUnitFactory, LearningUnitQuestionFactory
@ -407,7 +408,6 @@ Fachspezialisten bei.
# tp = TopicFactory.create(title="Prüfung", is_visible=False, learning_path=lp) # tp = TopicFactory.create(title="Prüfung", is_visible=False, learning_path=lp)
# circle_7 = CircleFactory.create(title="Prüfungsvorbereitung", parent=lp, topic=tp) # circle_7 = CircleFactory.create(title="Prüfungsvorbereitung", parent=lp, topic=tp)
# locales # locales
locale_de = Locale.objects.get(language_code='de-CH') locale_de = Locale.objects.get(language_code='de-CH')
locale_fr, _ = Locale.objects.get_or_create(language_code='fr-CH') locale_fr, _ = Locale.objects.get_or_create(language_code='fr-CH')
@ -421,13 +421,15 @@ Fachspezialisten bei.
sync_from_id=locale_de.id sync_from_id=locale_de.id
) )
call_command('sync_locale_trees') call_command('sync_locale_trees')
# all pages belong to 'admin' by default # all pages belong to 'admin' by default
Page.objects.update(owner=user) Page.objects.update(owner=user)
def delete_default_learning_path(): def delete_default_learning_path():
LearningContent.objects.all().delete() LearningContent.objects.all().delete()
LearningUnitQuestion.objects.all().delete()
LearningUnit.objects.all().delete()
LearningSequence.objects.all().delete() LearningSequence.objects.all().delete()
Circle.objects.all().delete() Circle.objects.all().delete()
Topic.objects.all().delete() Topic.objects.all().delete()

View File

@ -5,9 +5,13 @@
{% include "admin/app_list.html" with app_list=app_list show_changelinks=True %} {% include "admin/app_list.html" with app_list=app_list show_changelinks=True %}
<div class="content"> <div class="content">
<form action="/cypressreset/" method="post"> <form action="/core/cypressreset/" method="post">
{% csrf_token %} {% csrf_token %}
<button class="" name="">Testdaten zurück setzen</button> <button class="btn" name="">Testdaten zurück setzen</button>
</form>
<form action="/core/schemareset/" method="post">
{% csrf_token %}
<button class="btn" name="">Datenbank zurück setzen</button>
</form> </form>
</div> </div>
</div> </div>