Add SeaLion model
This commit is contained in:
parent
bfce3ad07e
commit
641d0f3c70
32
models/sealion.py
Normal file
32
models/sealion.py
Normal file
@ -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.
|
Loading…
x
Reference in New Issue
Block a user