20 lines
700 B
Python
20 lines
700 B
Python
from sqlalchemy import Column, String, DateTime, Index
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from sqlalchemy.sql import func
|
|
from core.database import Base
|
|
import uuid
|
|
|
|
class Grocery(Base):
|
|
__tablename__ = "groceries"
|
|
|
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
name = Column(String, nullable=False)
|
|
color = Column(String, nullable=True)
|
|
shape = Column(String, nullable=True)
|
|
created_at = Column(DateTime, default=func.now())
|
|
updated_at = Column(DateTime, default=func.now(), onupdate=func.now())
|
|
|
|
# Create a separate index for name to ensure proper indexing
|
|
__table_args__ = (
|
|
Index('ix_groceries_name', 'name'),
|
|
) |