Overview
SASCOP BME SubTec uses PostgreSQL as its primary database. The application supports both local development and production configurations through environment variables.Database Configuration
The database configuration is defined inbme_subtec/settings.py:82-94:
bme_subtec/settings.py
The configuration uses environment variables with sensible defaults for local development.
Environment Variables
Configure these environment variables in your.env file:
| Variable | Description | Default | Required |
|---|---|---|---|
RDS_DB_NAME | Database name | postgres | Yes |
RDS_USERNAME | Database user | postgres | Yes |
RDS_PASSWORD | Database password | Empty string | Yes |
RDS_HOSTNAME | Database host | localhost | Yes |
RDS_PORT | Database port | 5432 | No |
Local Development Setup
Alternative Local Configuration
The codebase includes a commented-out alternative for pure local development inbme_subtec/settings.py:97-106:
bme_subtec/settings.py
Production Configuration
For production deployments (AWS RDS, Vercel Postgres, etc.):SSL Connection
The production configuration requires SSL connections:Ensure your database provider supports SSL connections.
Database Models
The application uses several model categories:Core Models
Module System (core/models.py:4-17):
core/models.py
Operations Models
Theoperaciones app contains several model files:
- catalogos_models.py - Catalog entities (Tipo, Frente, Estatus, Sitio, etc.)
- pte_models.py - PTE (Project Task Entry) management
- ote_models.py - OTE (Work Order) management
- produccion_models.py - Production tracking and estimations
- registro_actividad_models.py - Activity logging
Database Maintenance
Creating Migrations
When you modify models, create new migrations:Viewing Migration Status
Check which migrations have been applied:Rolling Back Migrations
To revert to a specific migration:Database Shell
Access the database shell for direct queries:Connection Pooling
For high-traffic production environments, consider implementing connection pooling using
django-db-connection-pool or pgBouncer.Backup and Restore
Backup Database
Restore Database
Django Fixtures
Export data as JSON fixtures:Troubleshooting
Connection Refused
If you see “connection refused” errors:-
Verify PostgreSQL is running:
-
Check if PostgreSQL is listening on the correct port:
-
Verify
pg_hba.confallows connections from your IP
SSL Connection Issues
For SSL-related errors in production:- Download the RDS certificate bundle (for AWS)
- Configure SSL certificate path in database settings
- Verify SSL is enabled on your database instance
Performance Issues
-
Enable query logging to identify slow queries:
- Create database indexes for frequently queried fields
- Use select_related() and prefetch_related() to optimize queries
Next Steps
Data Models
Explore the complete data model structure
Database Migrations
Learn about managing migrations in production