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:
@@ -18,7 +18,7 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { RefreshCw, ExternalLink } from 'lucide-react';
|
import { RefreshCw, ExternalLink } from 'lucide-react';
|
||||||
import { useAppContext } from '../../contexts/AppContext';
|
import { useTenant } from '../../stores/tenant.store';
|
||||||
import {
|
import {
|
||||||
useBakeryHealthStatus,
|
useBakeryHealthStatus,
|
||||||
useOrchestrationSummary,
|
useOrchestrationSummary,
|
||||||
@@ -37,8 +37,8 @@ import { InsightsGrid } from '../../components/dashboard/InsightsGrid';
|
|||||||
|
|
||||||
export function NewDashboardPage() {
|
export function NewDashboardPage() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { selectedTenant } = useAppContext();
|
const { currentTenant } = useTenant();
|
||||||
const tenantId = selectedTenant?.id || '';
|
const tenantId = currentTenant?.id || '';
|
||||||
|
|
||||||
// Data fetching
|
// Data fetching
|
||||||
const {
|
const {
|
||||||
|
|||||||
@@ -13,9 +13,7 @@ from datetime import datetime
|
|||||||
import logging
|
import logging
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
from shared.database.session import get_db
|
from app.core.database import get_db
|
||||||
from shared.auth.dependencies import require_user, get_current_user_id
|
|
||||||
from shared.auth.permissions import require_subscription_tier
|
|
||||||
from ..services.dashboard_service import DashboardService
|
from ..services.dashboard_service import DashboardService
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -164,7 +162,6 @@ class InsightsResponse(BaseModel):
|
|||||||
@router.get("/health-status", response_model=BakeryHealthStatusResponse)
|
@router.get("/health-status", response_model=BakeryHealthStatusResponse)
|
||||||
async def get_bakery_health_status(
|
async def get_bakery_health_status(
|
||||||
tenant_id: str,
|
tenant_id: str,
|
||||||
user_id: str = Depends(get_current_user_id),
|
|
||||||
db: AsyncSession = Depends(get_db)
|
db: AsyncSession = Depends(get_db)
|
||||||
) -> BakeryHealthStatusResponse:
|
) -> BakeryHealthStatusResponse:
|
||||||
"""
|
"""
|
||||||
@@ -251,7 +248,6 @@ async def get_bakery_health_status(
|
|||||||
async def get_orchestration_summary(
|
async def get_orchestration_summary(
|
||||||
tenant_id: str,
|
tenant_id: str,
|
||||||
run_id: Optional[str] = Query(None, description="Specific run ID, or latest if not provided"),
|
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)
|
db: AsyncSession = Depends(get_db)
|
||||||
) -> OrchestrationSummaryResponse:
|
) -> OrchestrationSummaryResponse:
|
||||||
"""
|
"""
|
||||||
@@ -319,7 +315,6 @@ async def get_orchestration_summary(
|
|||||||
@router.get("/action-queue", response_model=ActionQueueResponse)
|
@router.get("/action-queue", response_model=ActionQueueResponse)
|
||||||
async def get_action_queue(
|
async def get_action_queue(
|
||||||
tenant_id: str,
|
tenant_id: str,
|
||||||
user_id: str = Depends(get_current_user_id),
|
|
||||||
db: AsyncSession = Depends(get_db)
|
db: AsyncSession = Depends(get_db)
|
||||||
) -> ActionQueueResponse:
|
) -> ActionQueueResponse:
|
||||||
"""
|
"""
|
||||||
@@ -399,7 +394,6 @@ async def get_action_queue(
|
|||||||
@router.get("/production-timeline", response_model=ProductionTimelineResponse)
|
@router.get("/production-timeline", response_model=ProductionTimelineResponse)
|
||||||
async def get_production_timeline(
|
async def get_production_timeline(
|
||||||
tenant_id: str,
|
tenant_id: str,
|
||||||
user_id: str = Depends(get_current_user_id),
|
|
||||||
db: AsyncSession = Depends(get_db)
|
db: AsyncSession = Depends(get_db)
|
||||||
) -> ProductionTimelineResponse:
|
) -> ProductionTimelineResponse:
|
||||||
"""
|
"""
|
||||||
@@ -449,7 +443,6 @@ async def get_production_timeline(
|
|||||||
@router.get("/insights", response_model=InsightsResponse)
|
@router.get("/insights", response_model=InsightsResponse)
|
||||||
async def get_insights(
|
async def get_insights(
|
||||||
tenant_id: str,
|
tenant_id: str,
|
||||||
user_id: str = Depends(get_current_user_id),
|
|
||||||
db: AsyncSession = Depends(get_db)
|
db: AsyncSession = Depends(get_db)
|
||||||
) -> InsightsResponse:
|
) -> InsightsResponse:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -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')
|
||||||
@@ -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')
|
||||||
Reference in New Issue
Block a user