Database Technology Stack
PostgreSQL
Relational database
Drizzle ORM
Type-safe ORM (v0.40.0)
Drizzle Kit
Schema management (v0.30.5)
Prerequisites
Ensure you have:- PostgreSQL server installed and running
DATABASE_URLconfigured in.envfile- Dependencies installed via
pnpm install
Initial Database Setup
Push Schema to Database
Initialize the database schema using Drizzle Kit:This command:
- Reads the schema from
packages/database/src/schema.ts - Creates all tables, columns, and relationships
- Applies constraints and indexes
You should see output confirming table creation for users, airlines, brands, flights, and more.
Database Schema Overview
SkyTeam’s database schema is defined inpackages/database/src/schema.ts. Here’s an overview of the main tables:
Users Table
Stores user information and mileage points.Airlines Table
Represents airline organizations in SkyTeam.Brands Table
Airline brands with IATA/ICAO codes and styling.Flights Table
Tracks active and completed flights.Flight Passengers Table
Many-to-many relationship between flights and users.Miles Transactions Table
Audit log for all mileage changes.Miles Products Table
Rewards available for purchase with miles.Database Relationships
Database Package Structure
The database package (@skyteam/database) is organized as follows:
Drizzle Configuration
The Drizzle configuration is defined inpackages/database/drizzle.config.ts:
drizzle.config.ts
Database Operations
Available Commands
Database Client Usage
The database client is initialized inpackages/database/src/db.ts:
db.ts
Schema Management
Making Schema Changes
Generate Migration (Optional)
Create migration files for versioned changes:This creates SQL migration files in
packages/database/drizzle/.Development vs Production
- Development
- Production
Use Pros:
db:push for rapid prototyping:- Fast iteration
- No migration files
- Can lose data
- No version history
Connection Pooling
Thepostgres client provides automatic connection pooling. Configure pool settings:
Database Backup & Restore
Backup
Restore
Troubleshooting
Connection refused errors
Connection refused errors
Check PostgreSQL is running:
Authentication failed
Authentication failed
Verify credentials in Reset password if needed:
DATABASE_URL:Schema push fails
Schema push fails
Common issues:Foreign key violations:Permission errors:
Drizzle Studio won't start
Drizzle Studio won't start
Ensure DATABASE_URL is set:
Next Steps
Docker Setup
Deploy database with Docker
API Development
Use database in API endpoints