Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/JorLOrT/rappi2/llms.txt

Use this file to discover all available pages before exploring further.

Rappi2 uses Alembic to manage the PostgreSQL schema and creates MongoDB indexes automatically on startup via ensure_all_indexes(). You need to run migrations once after cloning the project, and again whenever a new revision is added.

Running migrations

Apply all pending migrations to bring the schema to the latest revision:
alembic upgrade head
When using Docker Compose, run this inside the api container:
docker-compose exec api alembic upgrade head
The current migrations create 15 tables covering roles, permissions, users, clients, orders, payments, invoices, vehicles, drivers, assignments, routes, stops, and incidents, then convert all datetime columns to TIMESTAMP WITH TIME ZONE.

Creating a new migration

After modifying SQLAlchemy models, generate a migration automatically:
alembic revision --autogenerate -m "describe your change here"
Review the generated file in alembic/versions/, then apply it:
alembic upgrade head

MongoDB indexes

MongoDB indexes are created automatically every time the API starts, by calling ensure_all_indexes() during the application lifespan. You do not need to run any command manually. The following indexes are created across the configured MONGO_DB database:
CollectionIndexType
gps_trackinglocation2dsphere (geospatial)
gps_trackingasignacion_id + timestampCompound
geocercasgeometry2dsphere (geospatial)
geocercasruta_id + activaCompound
auditoriausuario_id + timestampCompound
auditoriatimestampTTL — records expire after 90 days
notificacionesdestinatario_tipo + destinatario_id + fechaCompound
notificacionesleidaSingle field
evidenciasincidencia_idSingle field
evidenciasarchivos.file_idSingle field

Seeding initial data

Run the seed script to create the default roles and admin user:
python scripts/seed_admin.py
When using Docker Compose:
docker-compose exec api python scripts/seed_admin.py
The script creates:
  • Roles: Admin, Despachador, Conductor, Cliente
  • Permissions: a wildcard *:* permission assigned to the Admin role
  • Admin user: username admin, password admin123, email admin@rappi2.com
The script is safe to re-run. It skips any records that already exist.

Checking database health

Verify that PostgreSQL is reachable and the schema is applied:
docker-compose exec postgres psql -U postgres -d rappi2 -c "\dt"
Verify that MongoDB is reachable:
docker-compose exec mongodb mongosh -u admin -p admin --authenticationDatabase admin --eval "db.adminCommand('ping')"
Alembic migrations are idempotent — running alembic upgrade head when the schema is already up to date completes without making any changes.
Always run alembic upgrade head before starting the API in production. The application does not apply migrations automatically on startup. Starting the API against an outdated schema will cause runtime errors.

Build docs developers (and LLMs) love