Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/lffiesco-svg/gastromovil/llms.txt

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

GastroMóvil uses MySQL as its only supported database engine. There is no SQLite fallback — the DATABASES setting in settings.py is always configured for django.db.backends.mysql, relying on PyMySQL as the drop-in MySQLdb adapter. All primary keys across every model are 64-bit integers (BigAutoField), and sessions are stored in the same MySQL database using Django’s default session backend.

How PyMySQL is Wired In

At the very top of settings.py, before any Django import, PyMySQL patches itself to masquerade as MySQLdb:
import pymysql
pymysql.version_info = (2, 2, 1, "final", 0)
pymysql.install_as_MySQLdb()
This call must remain at the top of the file. Moving it after Django’s setup imports will cause an ImproperlyConfigured error at startup because the database backend is resolved during the DATABASES parsing phase.

DATABASES Configuration

The full database block from settings.py reads all connection parameters from environment variables via python-decouple. When USE_DB_SSL=True the connection is wrapped in an SSL context using the certifi CA bundle:
USE_DB_SSL = config('USE_DB_SSL', default='False') == 'True'

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': config('DB_NAME'),
        'USER': config('DB_USER'),
        'PASSWORD': config('DB_PASSWORD'),
        'HOST': config('DB_HOST'),
        'PORT': config('DB_PORT', default='3306'),
        'OPTIONS': {
            'ssl': {'ca': certifi.where(), 'check_hostname': False}
        } if USE_DB_SSL else {},
    }
}
check_hostname is intentionally set to False because cloud-managed MySQL endpoints (Railway, PlanetScale, etc.) frequently serve a certificate whose Common Name does not match the connection hostname.
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' is set globally, so every model table uses a BIGINT UNSIGNED auto-increment primary key unless the model explicitly overrides it.

Local Setup

1

Install MySQL

Install MySQL 8.x on your machine. On macOS you can use Homebrew (brew install mysql); on Ubuntu/Debian use apt install mysql-server. Make sure the MySQL service is running before proceeding.
2

Create the database

Connect to MySQL as root and create the application database with full Unicode support:
CREATE DATABASE gastromovil
  CHARACTER SET utf8mb4
  COLLATE utf8mb4_unicode_ci;
Then create a dedicated user and grant privileges:
CREATE USER 'gastro_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON gastromovil.* TO 'gastro_user'@'localhost';
FLUSH PRIVILEGES;
3

Configure environment variables

Add the connection details to your .env file:
DB_NAME=gastromovil
DB_USER=gastro_user
DB_PASSWORD=your_password
DB_HOST=localhost
DB_PORT=3306
USE_DB_SSL=False
4

Install Python dependencies

Ensure pymysql and certifi are installed in your virtual environment:
pip install pymysql certifi
5

Run migrations

Apply all pending migrations to create the full schema:
python manage.py migrate
This will apply migrations from every app listed in INSTALLED_APPS that ships its own migration history.

Apps with Migrations

The following first-party Django apps each carry their own migration history and will have tables created during migrate:
AppDescription
usuariosCustom user model, addresses, ratings, password-recovery codes
restaurantesRestaurants, categories, and products
pedidosOrder lifecycle and line items
repartidoresDelivery driver profiles and assignments
coreSite-wide pages and shared models
Third-party apps installed alongside these — django.contrib.auth, django.contrib.sessions, allauth, rest_framework, etc. — also create their own tables on first migration.

Session Storage

GastroMóvil uses Django’s default database-backed session engine. Sessions expire after 30 minutes of inactivity and are also destroyed when the browser closes:
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
SESSION_COOKIE_AGE = 1800       # seconds
SESSION_SAVE_EVERY_REQUEST = True
SESSION_SAVE_EVERY_REQUEST = True resets the 30-minute timer on every authenticated request, keeping active users from being unexpectedly logged out mid-session.

Railway Deployment

1

Provision the MySQL plugin

In your Railway project dashboard, click NewDatabaseMySQL. Railway automatically provisions a MySQL 8 instance and injects a DATABASE_URL variable — but GastroMóvil uses individual variables, so you need to copy the components manually.
2

Copy connection variables

Open the Railway MySQL service, navigate to the Variables tab, and set the following in your GastroMóvil service’s environment:
DB_NAME=railway
DB_USER=root
DB_PASSWORD=<Railway-provided password>
DB_HOST=<Railway-provided host>
DB_PORT=3306
USE_DB_SSL=True
3

Deploy

Railway runs the startCommand from railway.toml on every deploy, which automatically applies outstanding migrations before starting Daphne:
[deploy]
startCommand = "python manage.py migrate && daphne -b 0.0.0.0 -p $PORT gastromovil.asgi:application"
No manual migration step is required in Railway pipelines.
Always set USE_DB_SSL=True on Railway. Railway’s MySQL endpoint requires an encrypted connection; plain-text connections will be refused at the TLS handshake stage.
If you need to reset the schema during development, run python manage.py flush --no-input to empty all tables without dropping them, or drop and recreate the database and re-run migrate.

Build docs developers (and LLMs) love