Skip to content

Commit

Permalink
chore: Ensure we don't wipe the database between docker-runs.
Browse files Browse the repository at this point in the history
Wiping the database is:
- slow. It adds over a minute to the boot process of a docker compose up
- cumbersome. We start with a blank slate after every boot, which means
  issued badges, accounts, logins, etc all are gone.

Ideally the blank state is useful in itself, but it's lacking data and
setup currently. So after booting we need quite a few manual tasks each
time, to get relevant badges into users' backpack.

This feature was commented out in the commit:

  commit 2916276
  Author: Okke Harsta <[email protected]>
  Date:   Wed Aug 18 14:24:39 2021 +0200

      Temporary comment to fix deployment

  Δ apps/mainsite/management/commands/seed.py

But, as "temporary fixes" tend to do, it remained in, and now causes
work and delays when developing.

We also add a persistent volume to docker-compose so that the data for
the mysql database is stored outside of the container and can live
across container lifecycles.
  • Loading branch information
berkes committed Dec 17, 2024
1 parent 76fd8b1 commit 1f12a4c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions apps/mainsite/management/commands/seed.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ def add_arguments(self, parser):

def handle(self, *args, **options):
if settings.ALLOW_SEEDS:
# if options['clean']:
clear_data()
if options['clean']:
clear_data()

run_seeds()
if options['add_assertions']:
nr_of_assertions = options['add_assertions']
Expand Down
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ services:
retries: 5
start_period: 30s
timeout: 10s
volumes:
- db-data:/var/lib/mysql
networks:
- edubadges-server

Expand All @@ -98,3 +100,6 @@ networks:
external: true
edubadges-server:
driver: bridge

volumes:
db-data:
3 changes: 1 addition & 2 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ set -x
echo "Running migrations"
python ./manage.py migrate

# Reset (-c) and Seed the database
echo "Seeding the database"
python ./manage.py seed -c
python ./manage.py seed

# Run the server
echo "Starting the server"
Expand Down

0 comments on commit 1f12a4c

Please sign in to comment.