diff --git a/.env.example b/.env.example index f704c0086f..d8f7afd607 100644 --- a/.env.example +++ b/.env.example @@ -3,12 +3,12 @@ DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1 DJANGO_BIND_ADDRESS=0.0.0.0 DJANGO_PORT=8000 DJANGO_DEBUG=False -# select one of [production|devel] +# Select one of [production|devel] DJANGO_SETTINGS_MODULE=config.django.[production|devel] -# select one of [ndjson|human_readable] +# Select one of [ndjson|human_readable] DJANGO_LOGGING_FORMATTER=[ndjson|human_readable] -# select one of [DEBUG|INFO|WARNING|ERROR|CRITICAL] -# applies to both Django and Celery Workers +# Select one of [DEBUG|INFO|WARNING|ERROR|CRITICAL] +# Applies to both Django and Celery Workers DJANGO_LOGGING_LEVEL=INFO DJANGO_WORKERS=4 # Defaults to the maximum available based on CPU cores if not set. DJANGO_TOKEN_SIGNING_KEY="" @@ -19,6 +19,8 @@ DJANGO_REFRESH_TOKEN_LIFETIME=1440 DJANGO_CACHE_MAX_AGE=3600 DJANGO_STALE_WHILE_REVALIDATE=60 DJANGO_SECRETS_ENCRYPTION_KEY="" +# Decide whether to allow Djanto manage database table partitions +DJANGO_MANAGE_DB_PARTITIONS=[True|False] # PostgreSQL settings # If running django and celery on host, use 'localhost', else use 'postgres-db' diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 527f227df7..8e9165aebe 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -31,14 +31,25 @@ start_worker() { poetry run python -m celery -A config.celery worker -l "${DJANGO_LOGGING_LEVEL:-info}" -Q celery,scans -E } +manage_db_partitions() { + if [ "${DJANGO_MANAGE_DB_PARTITIONS}" = "True" ]; then + echo "Managing DB partitions..." + # For now we skip the deletion of partitions until we define the data retention policy + # --yes auto approves the operation without the need of an interactive terminal + poetry run python manage.py pgpartition --using admin --skip-delete --yes + fi +} + case "$1" in dev) apply_migrations apply_fixtures + manage_db_partitions start_dev_server ;; prod) apply_migrations + manage_db_partitions start_prod_server ;; worker)