prisma/schema.prisma and consists of six main models that handle users, F1 data, and betting functionality.
Overview
The database schema includes:- Users - User accounts and authentication
- Drivers - F1 driver information
- Teams - F1 constructor/team data
- Races - Race schedule and circuit information
- Results - Race results and driver positions
- Bets - User betting records and status
Models
Users
Stores user account information, authentication credentials, and balance data.Field descriptions
Field descriptions
| Field | Type | Description |
|---|---|---|
userId | Int | Primary key, auto-incrementing user identifier |
username | String | Unique username, max 255 characters |
email | String | Unique email address, max 255 characters |
password | String | Hashed password, max 255 characters |
balance | Decimal | User’s account balance for betting, defaults to 0.00 |
createdAt | DateTime | Account creation timestamp |
lastLogin | DateTime | Last login timestamp with timezone |
country | String | User’s country, max 50 characters |
userType | String | User type (e.g., “regular”), defaults to “regular” |
This table contains check constraints and requires additional setup for migrations. See the Prisma documentation for more information.
- One-to-many with Bets (a user can have multiple bets)
Drivers
Contains comprehensive information about F1 drivers including personal details and team affiliation.Field descriptions
Field descriptions
| Field | Type | Description |
|---|---|---|
driverId | String | Primary key, unique driver identifier (max 50 chars) |
code | String | Driver’s three-letter code (e.g., “VER”, “HAM”) |
permanentNumber | Int | Driver’s permanent racing number |
givenName | String | Driver’s first name |
familyName | String | Driver’s last name |
dateOfBirth | DateTime | Driver’s date of birth |
nationality | String | Driver’s nationality |
url | String | Reference URL for driver information |
driverImage | String | URL or path to driver’s image |
teamId | String | Foreign key to Teams table |
- Many-to-one with Teams (a driver belongs to one team)
- One-to-many with Bets (a driver can have multiple bets placed on them)
- One-to-many with Results (a driver can have multiple race results)
Teams
Stores F1 constructor/team information.Field descriptions
Field descriptions
| Field | Type | Description |
|---|---|---|
teamId | String | Primary key, unique team identifier (max 50 chars) |
name | String | Team/constructor name (e.g., “Red Bull Racing”) |
nationality | String | Team’s nationality |
url | String | Reference URL for team information |
teamLogo | String | URL or path to team’s logo image |
- One-to-many with Drivers (a team can have multiple drivers)
Races
Contains race schedule, circuit information, and event details.Field descriptions
Field descriptions
| Field | Type | Description |
|---|---|---|
raceId | Int | Primary key, auto-incrementing race identifier |
season | String | Season year (e.g., “2024”) |
round | Int | Round number in the season |
raceName | String | Official race name |
circuitId | String | Unique circuit identifier |
circuitName | String | Circuit name |
locality | String | City or locality of the circuit |
country | String | Country where the race takes place |
date | DateTime | Race date |
time | DateTime | Race start time |
url | String | Reference URL for race information |
- One-to-many with Bets (a race can have multiple bets)
- One-to-many with Results (a race has multiple driver results)
Results
Stores race results including driver positions and points earned.Field descriptions
Field descriptions
| Field | Type | Description |
|---|---|---|
resultId | Int | Primary key, auto-incrementing result identifier |
raceId | Int | Foreign key to Races table |
driverId | String | Foreign key to Drivers table |
position | Int | Finishing position in the race |
points | Int | Championship points earned |
- Many-to-one with Races (a result belongs to one race)
- Many-to-one with Drivers (a result belongs to one driver)
Bets
Tracks user betting activity including bet amounts, odds, and status.Field descriptions
Field descriptions
| Field | Type | Description |
|---|---|---|
betId | Int | Primary key, auto-incrementing bet identifier |
userId | Int | Foreign key to Users table |
raceId | Int | Foreign key to Races table |
driverId | String | Foreign key to Drivers table |
amount | Decimal | Bet amount with 2 decimal places |
odds | Decimal | Betting odds with 2 decimal places |
betStatus | String | Status of bet (“pending”, “won”, “lost”), defaults to “pending” |
createdAt | DateTime | Timestamp when bet was created |
This table contains check constraints and requires additional setup for migrations. See the Prisma documentation for more information.
- Many-to-one with Users (a bet belongs to one user)
- Many-to-one with Races (a bet is for one race)
- Many-to-one with Drivers (a bet is on one driver)
Database configuration
The database uses PostgreSQL as the provider and connects using theDATABASE_URL environment variable:
Entity relationship diagram
Key features
Foreign key relationships
Foreign key relationships
All foreign key relationships use
onDelete: NoAction and onUpdate: NoAction to prevent cascading deletes and updates. This ensures data integrity and prevents accidental data loss.Auto-incrementing IDs
Auto-incrementing IDs
Most tables (Users, Races, Results, Bets) use auto-incrementing integer primary keys. Drivers and Teams use string-based identifiers for compatibility with external F1 data sources.
Decimal precision
Decimal precision
Financial fields (balance, amount, odds) use appropriate decimal precision:
- Balance and amounts:
Decimal(10, 2)for currency values - Odds:
Decimal(5, 2)for betting odds
Timestamps
Timestamps
The schema uses various timestamp types:
@default(now())for automatic creation timestampsTimestamp(6)for standard timestampsTimestamptz(6)for timezone-aware timestamps (lastLogin)