Database Layer

This directory contains the database setup and query functions for the SmartRoutes application.

Files

  • migrations.ts - Contains the database schema definitions and migration functions
  • queries.ts - Contains typed query functions for interacting with the database

Database Schema

Users Table

Stores user account information:

  • id - Primary key
  • email - User's Gmail address (unique)
  • name - User's name (optional)
  • created_at - Account creation timestamp
  • last_login - Last login timestamp

Traffic Reports Table

Stores traffic congestion reports:

  • id - Primary key
  • user_id - Foreign key to users table
  • latitude - Geographic latitude
  • longitude - Geographic longitude
  • congestion_level - Traffic level (1: Light, 2: Moderate, 3: Heavy, 4: Standstill)
  • description - Optional text description
  • created_at - Report timestamp

Locations Table

Stores users' last known locations:

  • id - Primary key
  • user_id - Foreign key to users table
  • latitude - Geographic latitude
  • longitude - Geographic longitude
  • updated_at - Last update timestamp