feat: Add Ride model
This commit is contained in:
parent
72c3ec2b19
commit
31489d3b2d
43
models/ride.py
Normal file
43
models/ride.py
Normal file
@ -0,0 +1,43 @@
|
||||
from sqlalchemy import Column, String, Integer, Boolean, DateTime, ForeignKey, Float
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
from core.database import Base
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
|
||||
class Ride(Base):
|
||||
__tablename__ = "rides"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
pickup_location = Column(String, nullable=False)
|
||||
drop_location = Column(String, nullable=False)
|
||||
pickup_latitude = Column(Float, nullable=False)
|
||||
pickup_longitude = Column(Float, nullable=False)
|
||||
drop_latitude = Column(Float, nullable=False)
|
||||
drop_longitude = Column(Float, nullable=False)
|
||||
rider_id = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=False)
|
||||
driver_id = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=True)
|
||||
ride_status = Column(String, nullable=False, default="requested")
|
||||
ride_distance = Column(Float, nullable=True)
|
||||
ride_duration = Column(Integer, nullable=True)
|
||||
ride_fare = Column(Float, nullable=True)
|
||||
created_at = Column(DateTime, default=func.now())
|
||||
updated_at = Column(DateTime, default=func.now(), onupdate=func.now())
|
||||
|
||||
rider = relationship("User", foreign_keys=[rider_id], backref="rider_rides")
|
||||
driver = relationship("User", foreign_keys=[driver_id], backref="driver_rides")
|
||||
```
|
||||
|
||||
This model includes the following columns:
|
||||
|
||||
- `id`: A UUID primary key for the ride.
|
||||
- `pickup_location` and `drop_location`: Strings for the pickup and drop-off locations.
|
||||
- `pickup_latitude`, `pickup_longitude`, `drop_latitude`, and `drop_longitude`: Floats for the pickup and drop-off coordinates.
|
||||
- `rider_id` and `driver_id`: UUIDs for the rider and driver user IDs, with foreign key relationships to the `users` table.
|
||||
- `ride_status`: A string for the current status of the ride (e.g., "requested", "accepted", "completed").
|
||||
- `ride_distance` and `ride_duration`: Floats and integers for the distance and duration of the ride.
|
||||
- `ride_fare`: A float for the fare amount of the ride.
|
||||
- `created_at` and `updated_at`: Datetime columns for when the ride was created and last updated.
|
||||
|
||||
The model also includes relationships to the `User` model for the rider and driver, using the `rider_id` and `driver_id` foreign keys.
|
Loading…
x
Reference in New Issue
Block a user