Introduction
Intallation

⚙️ Installation

Clone the repository.

git clone git@github.com:tyronejosee/project_drop_dash_api.git

Create a virtual environment (Optional, only if you have Python installed).

python -m venv env

Activate the virtual environment (Optional, only if you have Python installed).

env\Scripts\activate

Notes: (env) will appear in your terminal input.

Install dependencies for your local environment, for testing, linter and pre-commit configs, etc. (Optional, only if you have Python installed).

pip install -r requirements/local.txt

Create a copy of the .env.example file and rename it to .env.

cp .env.example .env

Update the values of the environment variables (Important).

Note: Make sure to correctly configure your variables before building the container.

🐳 Docker

Build your container; it will take time the first time, as Docker needs to download all dependencies and build the image. Use the -d (detached mode) flag to start your containers in the background. Use the --build flag if you have changes and need to rebuild.

docker compose up
docker compose up -d
docker compose up --build

Stop the running containers (does not remove them).

docker compose stop

Start previously created and stopped containers.

docker compose start

Show container logs in real-time.

docker compose logs -f

Restart a service with issues (Replace <service_name>).

docker compose restart <service_name>

Remove your container.

docker compose down

🐍 Django

Access the web service console that runs Django.

docker compose exec web bash

Inside the Django console, create the migrations.

python manage.py makemigrations

Run the migrations.

python manage.py migrate

If you need to be more specific, use:

python manage.py migrate <app_label> <migration_name>

List all available migrations and their status.

python manage.py showmigrations

Note: Manually create the migration if Django skips an app; this happens because Django did not find the /migrations folder.

Create a superuser to access the entire site without restrictions.

python manage.py createsuperuser

Log in to admin:

http://127.0.0.1:8200/admin/

Access Swagger or Redoc.

http://127.0.0.1:8200/api/schema/swagger/
http://127.0.0.1:8200/api/schema/redoc/

🚨 Important Notes

Check the creation of migrations before creating them.

docker compose exec web python manage.py makemigrations users

Note: Checking migrations before their creation is necessary to avoid inconsistencies in user models.

🐘 PostgreSQL

Access the PostgreSQL console.

docker compose exec db psql -U <database_user> -d <database_name>

List all the tables in the database.

\dt

Show the detailed structure of a specific table.

\d <table_name>

Create a backup of your database (Optional).

docker compose exec web python manage.py dumpdata > backup.json

Load the created backup if needed (Optional).

docker compose exec web python manage.py loaddata

🟥 Redis

Access the Redis console.

docker compose exec redis redis-cli

Retrieve all keys.

KEYS *

Delete a key from cache.

DEL <key_name>

Delete all keys.

FLUSHALL

⚖️ License

This project is under the Apache-2.0 license (opens in a new tab).