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
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,10 @@ repos:
- repo: meta
hooks:
- id: check-useless-excludes
- repo: https://github.com/adamchainz/django-upgrade
rev: 1.31.1
hooks:
- id: django-upgrade

default_language_version:
python: python3
7 changes: 3 additions & 4 deletions backend/code_review_backend/issues/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from code_review_backend.issues.models import Diff, Issue, Repository, Revision


@admin.register(Repository)
class RepositoryAdmin(admin.ModelAdmin):
list_display = ("slug", "url")

Expand All @@ -23,6 +24,7 @@ class DiffInline(admin.TabularInline):
)


@admin.register(Revision)
class RevisionAdmin(admin.ModelAdmin):
list_display = (
"id",
Expand All @@ -41,6 +43,7 @@ class RevisionAdmin(admin.ModelAdmin):
inlines = (DiffInline,)


@admin.register(Issue)
class IssueAdmin(admin.ModelAdmin):
list_filter = ("analyzer",)
list_display = (
Expand All @@ -55,9 +58,5 @@ class IssueAdmin(admin.ModelAdmin):
ordering = ("-created",)


admin.site.register(Repository, RepositoryAdmin)
admin.site.register(Revision, RevisionAdmin)
admin.site.register(Issue, IssueAdmin)

# Naming
admin.site.site_header = "Mozilla Code Review Backend"
2 changes: 1 addition & 1 deletion backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Django==5.1.15
Django==6.0.8
django-cors-headers==4.9.0
django-environ==0.14.0
djangorestframework==3.17.1
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ services:

db:
container_name: code-review-db
image: postgres:16-alpine
image: postgres:18-alpine

ports:
- 127.0.0.1:5432:5432
volumes:
- pgdata:/var/lib/postgresql/data
- pgdata:/var/lib/postgresql
environment:
POSTGRES_USER: devuser
POSTGRES_PASSWORD: devdata
Expand Down
49 changes: 49 additions & 0 deletions docs/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,52 @@ You can download the backup from the Heroku datastore dedicated page.
export PGPASSWORD=devdata
pg_restore -h localhost --user devuser -d code_review_dev path/to/dump
```

## Upgrade an existing PostgreSQL database

The PostgreSQL data is stored through a Docker volume. To avoid any data loss, we advice to save a copy of the volume before following the below instructions. The volume is usually located at `/var/lib/docker/volumes/code-review_pgdata/`.

We recommend performing the update using `pg_dump`, as it simplifies handling multiple major PostgreSQL updates.
Make sure you ran all the latest migrations and checked out to the latest version before continuing.

1. Back up the existing data using `pg_dump`

```sh=
docker run -d --rm --name=old-database \
-e POSTGRES_PASSWORD=devdata \
-e POSTGRES_USER=devuser \
-e POSTGRES_DB=code_review_dev \
-v code-review_pgdata:/var/lib/postgresql/data -p 127.0.0.1:5432:5432 postgres:<old_version>-alpine
PGPASSWORD=devdata pg_dump -h localhost -p 5432 -U devuser -d code_review_dev > dump.sql
```

There should be no error and the size of `dump.sql` should be approximately the size of the volume.

2. ⚠ Trash the previously used volume:

```sh=
docker kill old-database
docker volume rm code-review_pgdata
```

You will need to kill all database access first. In case docker complains about a container using the volume, you may also have to delete the container first:

```sh=
docker rm <container_id>
```

3. You can then run the up-to-date PostgreSQL via `docker-compose.yml` and restore the data:

```sh=
docker compose up db -d
docker exec code-review-db postgres -V # Should return the latest PostgreSQL version
PGPASSWORD=devdata psql --user=devuser --host=localhost -d code_review_dev < dump.sql
```

4. Check the application runs as expected by starting a development server: all your data should be there.

5. ⚠ Cleanup the local file used for the dump:

```sh=
rm dump.sql
```