
- Create project structure with FastAPI and SQLAlchemy - Implement database models for items, categories, suppliers, and stock movements - Add CRUD operations for all models - Configure Alembic for database migrations - Create RESTful API endpoints for inventory management - Add health endpoint for system monitoring - Update README with setup and usage instructions generated with BackendIM... (backend.im)
25 lines
1.2 KiB
Python
25 lines
1.2 KiB
Python
from sqlalchemy import Column, Integer, String, Float, Boolean, ForeignKey
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
from sqlalchemy.sql.sqltypes import TIMESTAMP
|
|
from app.database import Base
|
|
|
|
class Item(Base):
|
|
__tablename__ = "items"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String, nullable=False)
|
|
sku = Column(String, nullable=False, unique=True)
|
|
description = Column(String, nullable=True)
|
|
unit_price = Column(Float, nullable=False, default=0.0)
|
|
quantity = Column(Integer, nullable=False, default=0)
|
|
reorder_level = Column(Integer, nullable=False, default=0)
|
|
category_id = Column(Integer, ForeignKey("categories.id"), nullable=True)
|
|
supplier_id = Column(Integer, ForeignKey("suppliers.id"), nullable=True)
|
|
is_active = Column(Boolean, default=True)
|
|
created_at = Column(TIMESTAMP(timezone=True), server_default=func.now())
|
|
updated_at = Column(TIMESTAMP(timezone=True), server_default=func.now(), onupdate=func.now())
|
|
|
|
# Relationships
|
|
category = relationship("Category", foreign_keys=[category_id])
|
|
supplier = relationship("Supplier", foreign_keys=[supplier_id]) |