Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ ALLOWED_HOSTS=["backend", "localhost"]
CORS_ALLOWED_ORIGINS=[]
DEBUG=False
SKIP_CRONJOBS=False
RUN_APP_MIGRATIONS_ON_STARTUP=False

# -----------------------------------------------------------------------------
# Debug Flags (uncomment to enable)
Expand Down
9 changes: 5 additions & 4 deletions DEPLOYMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,12 @@ the `Publish GHCR Images` workflow is triggered manually.
The GitHub workflow for production is defined at: [deploy-production](.github/workflows/deploy-production.yaml)

> [!WARNING]
> It is important to point out that the backend entrypoint in Docker container
> will run database migrations.
> By default, backend startup skips app migrations.
> To run them automatically on startup, set `RUN_APP_MIGRATIONS_ON_STARTUP=true` in the `.env` file.
> Changes that involve alterations in database schema should be previously communicated
> via [Discord channel](https://discord.com/channels/1245820301053530313/1301896040349433957).


### Setup

```bash
Expand All @@ -163,6 +164,7 @@ cp .env.example .env
# DJANGO_SECRET_KEY → a strong random string
# ALLOWED_HOSTS → e.g. ["backend", "your-domain.com"]
# CORS_ALLOWED_ORIGINS → e.g. ["https://your-domain.com"]
# RUN_APP_MIGRATIONS_ON_STARTUP → true (if you want backend startup to apply app migrations)

# 3. Start services
docker compose -f docker-compose-next.yml up -d
Expand Down Expand Up @@ -208,8 +210,7 @@ significantly impact the database.
A GitHub workflow for staging is defined at [deploy-staging](.github/workflows/deploy-staging.yaml)

> [!WARNING]
> Migrations are automatically executed in the backend entrypoint
> when the docker container is executed.
> Migrations can be automatically executed by setting `RUN_APP_MIGRATIONS_ON_STARTUP=true` in the `.env` file.
> And as the staging environment is shared with production, the same precautions should follow.
> Changes that involve alterations in database schema should be previously communicated
> via [Discord channel](https://discord.com/channels/1245820301053530313/1301896040349433957).
Expand Down
10 changes: 8 additions & 2 deletions backend/utils/docker/backend_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ chmod +x ./migrate-cache-db.sh
./migrate-cache-db.sh

# Update the MAIN db
chmod +x ./migrate-app-db.sh
./migrate-app-db.sh
RUN_APP_MIGRATIONS_ON_STARTUP=$(echo "${RUN_APP_MIGRATIONS_ON_STARTUP:-false}" | tr '[:upper:]' '[:lower:]')
if [ "$RUN_APP_MIGRATIONS_ON_STARTUP" = "true" ]; then
echo "Applying app DB migrations..."
chmod +x ./migrate-app-db.sh
./migrate-app-db.sh
else
echo "Skipping app DB migrations at startup (set RUN_APP_MIGRATIONS_ON_STARTUP=true to enable)."
fi

# Add and start cronjobs in background and emit logs to container stdout.
poetry run ./manage.py crontab add
Expand Down
Loading