code-review/backend
Marco Castelluccio 788f525ee2 Use 'black' profile for isort 2023-04-17 12:33:51 +02:00
..
code_review_backend Use 'black' profile for isort 2023-04-17 12:33:51 +02:00
fixtures bot: Ingest autoland revisions (#272) 2019-12-04 09:07:21 +01:00
Dockerfile build(deps): bump python from 3.10.7-slim to 3.11.2-slim in /backend (#1542) 2023-03-07 10:35:22 +01:00
README.md Support django-extension for development (#1461) 2022-12-13 14:27:51 +01:00
VERSION Release 1.6.5 2023-04-06 18:29:19 +02:00
build.sh Add Dockerflow to the backend application (#1277) 2022-08-18 14:10:31 +03:00
manage.py backend: Add django base web application (#161) 2019-10-18 12:29:51 +02:00
requirements-dev.txt build(deps-dev): bump django-debug-toolbar in /backend (#1631) 2023-04-03 17:26:47 +02:00
requirements.txt build(deps): bump dj-database-url from 1.2.0 to 1.3.0 in /backend (#1632) 2023-04-03 17:39:16 +02:00
setup.py backend: Add django base web application (#161) 2019-10-18 12:29:51 +02:00

README.md

Code Review Backend

Developer setup

Run the application

You may want to install dependencies in a virtual environment an run the development test server with a base fixure for development purpose:

mkvirtualenv -p /usr/bin/python3 code-review-backend
cd backend
pip install -r requirements.txt
./manage.py migrate
./manage.py createsuperuser
./manage.py loaddata fixtures/repositories.json
./manage.py runserver

At this point, you can log into http://127.0.0.1:8000/admin/ with the credentials you mentioned during the createsuperuser step.

Debugging tools

Run pip install -r requirements-dev.txt to install all the available optional dev tools for the backend.

Django Debug Toolbar provides you with a neat debug sidebar that will help diagnosing slow API endpoints.

Django Extensions adds a lot of manage.py commands ; the most important one is ./manage.py shell_plus which runs the usual shell but with all the available models pre-imported.

You may also want to use IPython (pip install ipython) to get a nicer shell with syntax highlighting, auto reloading and much more via ./manage.py shell.

Load existing issues

To load remote issues from production (default configuration):

./manage.py load_issues

To load already retrieved issues

./manage.py load_issues --offline

To load from testing

./manage.py load_issues --environment=testing

Use a DB dump from testing or production

You can retrieve a Database dump from an Heroku instance on your computer using (process documented on Heroku):

heroku pg:backups:capture -a code-review-backend-testing
heroku pg:backups:download -a code-review-backend-testing

This will produce a local Postgres binary dump named latest.dump.

To use this dump, you'll need a local PostgreSQL instance running. The following Docker configuration works well for local development:

  • a code_review database is created,
  • with user/password credentials postgres / crdev1234,
  • data is stored in a Docker volume named code_review_postgres,
  • default Postgres port 5432 on the host is mapped to the container.
docker run --rm -p 5432:5432 \
  -e POSTGRES_DB=code_review \
  -e POSTGRES_PASSWORD=crdev1234 \
  -v code_review_postgres:/var/lib/postgresql/data \
  postgres

To restore the dump, use the following command (using the password used to start the database):

pg_restore --verbose --clean --no-acl --no-owner -h localhost -U postgres -d code_review latest.dump

It's also possible to use a direct one-step command from Heroku, but you need to have a compatible version of pg_dump on your system (moght be tricky in some scenarios):

heroku pg:pull  postgresql-concave-XXX --app code-review-backend-production postgresql://postgres@localhost:5432/prod

The postgresql database name can be found through the CLI pg:info tool, or on the Heroku dashboard. More information on the official documentation

Finally you can use that database with the backend as:

export DATABASE_URL=postgres://postgres:crdev1234@localhost/code_review
./manage.py runserver