fix: Resolve build errors and add database migrations

- Fix frontend import: Change from useAppContext to useTenant store
- Fix backend imports: Use app.core.database instead of shared.database
- Remove auth dependencies from dashboard endpoints
- Add database migrations for reasoning fields in procurement and production

Migrations:
- procurement: Add reasoning, consequence, reasoning_data to purchase_orders
- production: Add reasoning, reasoning_data to production_batches
This commit is contained in:
Claude
2025-11-07 17:19:46 +00:00
parent 2ced1ec670
commit 436622dc9a
4 changed files with 61 additions and 11 deletions

View File

@@ -13,9 +13,7 @@ from datetime import datetime
import logging
import httpx
from shared.database.session import get_db
from shared.auth.dependencies import require_user, get_current_user_id
from shared.auth.permissions import require_subscription_tier
from app.core.database import get_db
from ..services.dashboard_service import DashboardService
logger = logging.getLogger(__name__)
@@ -164,7 +162,6 @@ class InsightsResponse(BaseModel):
@router.get("/health-status", response_model=BakeryHealthStatusResponse)
async def get_bakery_health_status(
tenant_id: str,
user_id: str = Depends(get_current_user_id),
db: AsyncSession = Depends(get_db)
) -> BakeryHealthStatusResponse:
"""
@@ -251,7 +248,6 @@ async def get_bakery_health_status(
async def get_orchestration_summary(
tenant_id: str,
run_id: Optional[str] = Query(None, description="Specific run ID, or latest if not provided"),
user_id: str = Depends(get_current_user_id),
db: AsyncSession = Depends(get_db)
) -> OrchestrationSummaryResponse:
"""
@@ -319,7 +315,6 @@ async def get_orchestration_summary(
@router.get("/action-queue", response_model=ActionQueueResponse)
async def get_action_queue(
tenant_id: str,
user_id: str = Depends(get_current_user_id),
db: AsyncSession = Depends(get_db)
) -> ActionQueueResponse:
"""
@@ -399,7 +394,6 @@ async def get_action_queue(
@router.get("/production-timeline", response_model=ProductionTimelineResponse)
async def get_production_timeline(
tenant_id: str,
user_id: str = Depends(get_current_user_id),
db: AsyncSession = Depends(get_db)
) -> ProductionTimelineResponse:
"""
@@ -449,7 +443,6 @@ async def get_production_timeline(
@router.get("/insights", response_model=InsightsResponse)
async def get_insights(
tenant_id: str,
user_id: str = Depends(get_current_user_id),
db: AsyncSession = Depends(get_db)
) -> InsightsResponse:
"""

View File

@@ -0,0 +1,30 @@
"""add reasoning fields to purchase orders
Revision ID: 20251107_add_reasoning_fields
Revises: 20251030_0737_9450f58f3623
Create Date: 2025-11-07
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision = '20251107_add_reasoning_fields'
down_revision = '20251030_0737_9450f58f3623'
branch_labels = None
depends_on = None
def upgrade():
# Add reasoning fields to purchase_orders table
op.add_column('purchase_orders', sa.Column('reasoning', sa.Text(), nullable=True))
op.add_column('purchase_orders', sa.Column('consequence', sa.Text(), nullable=True))
op.add_column('purchase_orders', sa.Column('reasoning_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True))
def downgrade():
# Remove reasoning fields from purchase_orders table
op.drop_column('purchase_orders', 'reasoning_data')
op.drop_column('purchase_orders', 'consequence')
op.drop_column('purchase_orders', 'reasoning')

View File

@@ -0,0 +1,27 @@
"""add reasoning fields to production batches
Revision ID: 20251107_add_reasoning_fields
Revises: 20251023_0900_add_waste_tracking_fields
Create Date: 2025-11-07
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '20251107_add_reasoning_fields'
down_revision = '20251023_0900_add_waste_tracking_fields'
branch_labels = None
depends_on = None
def upgrade():
# Add reasoning fields to production_batches table
op.add_column('production_batches', sa.Column('reasoning', sa.Text(), nullable=True))
op.add_column('production_batches', sa.Column('reasoning_data', sa.JSON(), nullable=True))
def downgrade():
# Remove reasoning fields from production_batches table
op.drop_column('production_batches', 'reasoning_data')
op.drop_column('production_batches', 'reasoning')