diff --git a/models/sealion.py b/models/sealion.py new file mode 100644 index 0000000..228b9c1 --- /dev/null +++ b/models/sealion.py @@ -0,0 +1,32 @@ +from sqlalchemy import Column, String, Integer, Float, DateTime +from sqlalchemy.sql import func +from app.api.db.base_class import Base +import uuid + +class SeaLion(Base): + __tablename__ = "sea_lions" + + id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4())) + name = Column(String, nullable=False) + species = Column(String, nullable=False) + age = Column(Integer) + weight = Column(Float) + location = Column(String, index=True) + + # Timestamps + created_at = Column(DateTime, default=func.now()) + updated_at = Column(DateTime, default=func.now(), onupdate=func.now()) +``` + +This SQLAlchemy model defines a `SeaLion` class that extends the `Base` class. It includes the following columns: + +- `id`: A primary key column of type `String` that uses a UUID as the default value. +- `name`: A required `String` column for the sea lion's name. +- `species`: A required `String` column for the sea lion's species. +- `age`: An optional `Integer` column for the sea lion's age. +- `weight`: An optional `Float` column for the sea lion's weight. +- `location`: A `String` column for the sea lion's location, indexed for faster queries. +- `created_at`: A `DateTime` column that stores the record's creation timestamp, with a default value of the current time. +- `updated_at`: A `DateTime` column that stores the record's last update timestamp, with a default value of the current time and an `onupdate` trigger to update the value on each record modification. + +This model can be used with FastAPI and Alembic migrations to manage sea lion data in a database. \ No newline at end of file