Fix DB issues

This commit is contained in:
Urtzi Alfaro
2025-09-30 13:32:51 +02:00
parent ec6bcb4c7d
commit 147893015e
51 changed files with 341 additions and 1032 deletions

View File

@@ -17,6 +17,13 @@ COPY shared/ /app/shared/
# Copy application code
COPY services/alert_processor/app/ /app/app/
# Copy migrations and alembic config
COPY services/alert_processor/migrations/ /app/migrations/
COPY services/alert_processor/alembic.ini /app/alembic.ini
# Copy scripts directory
COPY scripts/ /app/scripts/
# Create non-root user
RUN useradd -m -u 1000 appuser && chown -R appuser:appuser /app
USER appuser

View File

@@ -1 +1,15 @@
# services/alert_processor/app/models/__init__.py
"""
Alert Processor Service Models Package
Import all models to ensure they are registered with SQLAlchemy Base.
"""
# Import all models to register them with the Base metadata
from .alerts import Alert, AlertStatus, AlertSeverity
# List all models for easier access
__all__ = [
"Alert",
"AlertStatus",
"AlertSeverity",
]

View File

@@ -1,29 +0,0 @@
"""Initial alert-processor service tables
Revision ID: 001_initial_alert_processor
Revises:
Create Date: 2024-01-01 12:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '001_initial_alert_processor'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# TODO: Add table creation statements for alert_processor service
# This is a placeholder migration - replace with actual table definitions
pass
def downgrade() -> None:
# TODO: Add table drop statements for alert_processor service
pass

View File

@@ -1,29 +0,0 @@
"""Initial auth service tables
Revision ID: 001_initial_auth
Revises:
Create Date: 2024-01-01 12:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '001_initial_auth'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# TODO: Add table creation statements for alert_processor service
# This is a placeholder migration - replace with actual table definitions
pass
def downgrade() -> None:
# TODO: Add table drop statements for alert_processor service
pass

View File

@@ -20,6 +20,10 @@ COPY shared/ /app/shared/
# Copy application code
COPY services/external/app/ /app/app/
# Copy migrations and alembic config
COPY services/external/migrations/ /app/migrations/
COPY services/external/alembic.ini /app/alembic.ini
# Copy scripts directory
COPY scripts/ /app/scripts/

View File

@@ -1,29 +0,0 @@
"""Initial external service tables
Revision ID: 001_initial_external
Revises:
Create Date: 2024-01-01 12:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '001_initial_external'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# TODO: Add table creation statements for external service
# This is a placeholder migration - replace with actual table definitions
pass
def downgrade() -> None:
# TODO: Add table drop statements for external service
pass

View File

@@ -26,6 +26,9 @@ COPY --from=shared /shared /app/shared
# Copy application code
COPY services/forecasting/ .
# Copy scripts directory
COPY scripts/ /app/scripts/
# Add shared libraries to Python path
ENV PYTHONPATH="/app:/app/shared:${PYTHONPATH:-}"

View File

@@ -0,0 +1,16 @@
"""
Forecasting Service Models Package
Import all models to ensure they are registered with SQLAlchemy Base.
"""
# Import all models to register them with the Base metadata
from .forecasts import Forecast
from .predictions import ModelPerformanceMetric, PredictionCache
# List all models for easier access
__all__ = [
"Forecast",
"ModelPerformanceMetric",
"PredictionCache",
]

View File

@@ -1,28 +0,0 @@
"""Initial forecasting service tables
Revision ID: 001_initial_forecasting
Create Date: 2024-01-01 12:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '001_initial_forecasting'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# TODO: Add table creation statements for forecasting service
# This is a placeholder migration - replace with actual table definitions
pass
def downgrade() -> None:
# TODO: Add table drop statements for forecasting service
pass

View File

@@ -19,6 +19,10 @@ COPY shared/ /app/shared/
# Copy application code
COPY services/inventory/app/ /app/app/
# Copy migrations and alembic config
COPY services/inventory/migrations/ /app/migrations/
COPY services/inventory/alembic.ini /app/alembic.ini
# Copy scripts directory
COPY scripts/ /app/scripts/

View File

@@ -1,28 +0,0 @@
"""Initial inventory service tables
Revision ID: 001_initial_inventory
Create Date: 2024-01-01 12:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '001_initial_inventory'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# TODO: Add table creation statements for inventory service
# This is a placeholder migration - replace with actual table definitions
pass
def downgrade() -> None:
# TODO: Add table drop statements for inventory service
pass

View File

@@ -26,6 +26,9 @@ COPY --from=shared /shared /app/shared
# Copy application code
COPY services/notification/ .
# Copy scripts directory
COPY scripts/ /app/scripts/
# Add shared libraries to Python path
ENV PYTHONPATH="/app:/app/shared:${PYTHONPATH:-}"

View File

@@ -0,0 +1,31 @@
"""
Notification Service Models Package
Import all models to ensure they are registered with SQLAlchemy Base.
"""
# Import all models to register them with the Base metadata
from .notifications import (
Notification,
NotificationType,
NotificationStatus,
NotificationPriority,
NotificationPreference,
NotificationLog,
)
from .templates import (
EmailTemplate,
WhatsAppTemplate,
)
# List all models for easier access
__all__ = [
"Notification",
"NotificationType",
"NotificationStatus",
"NotificationPriority",
"NotificationPreference",
"NotificationLog",
"EmailTemplate",
"WhatsAppTemplate",
]

View File

@@ -1,29 +0,0 @@
"""Initial notification service tables
Revision ID: 001_initial_notification
Revises:
Create Date: 2024-01-01 12:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '001_initial_notification'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# TODO: Add table creation statements for notification service
# This is a placeholder migration - replace with actual table definitions
pass
def downgrade() -> None:
# TODO: Add table drop statements for notification service
pass

View File

@@ -18,6 +18,13 @@ COPY shared/ ./shared/
# Copy application code
COPY services/orders/app/ ./app/
# Copy migrations and alembic config
COPY services/orders/migrations/ /app/migrations/
COPY services/orders/alembic.ini /app/alembic.ini
# Copy scripts directory
COPY scripts/ ./scripts/
# Create logs directory
RUN mkdir -p logs

View File

@@ -110,7 +110,7 @@ async def test_procurement_scheduler():
else:
return {"error": "Scheduler service not available"}
except Exception as e:
logger.error("Error testing procurement scheduler", error=str(e))
service.logger.error("Error testing procurement scheduler", error=str(e))
return {"error": f"Failed to trigger scheduler test: {str(e)}"}
@@ -118,17 +118,17 @@ async def test_procurement_scheduler():
async def logging_middleware(request: Request, call_next):
"""Add request logging middleware"""
import time
start_time = time.time()
response = await call_next(request)
process_time = time.time() - start_time
logger.info("HTTP request processed",
service.logger.info("HTTP request processed",
method=request.method,
url=str(request.url),
status_code=response.status_code,
process_time=round(process_time, 4))
return response

View File

@@ -0,0 +1,21 @@
"""
Orders Service Models Package
Import all models to ensure they are registered with SQLAlchemy Base.
"""
# Import all models to register them with the Base metadata
from .customer import Customer, CustomerContact
from .order import CustomerOrder, OrderItem, OrderStatusHistory
from .procurement import ProcurementPlan, ProcurementRequirement
# List all models for easier access
__all__ = [
"Customer",
"CustomerContact",
"CustomerOrder",
"OrderItem",
"OrderStatusHistory",
"ProcurementPlan",
"ProcurementRequirement"
]

View File

@@ -1,29 +0,0 @@
"""Initial orders service tables
Revision ID: 001_initial_orders
Revises:
Create Date: 2024-01-01 12:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '001_initial_orders'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# TODO: Add table creation statements for orders service
# This is a placeholder migration - replace with actual table definitions
pass
def downgrade() -> None:
# TODO: Add table drop statements for orders service
pass

View File

@@ -15,6 +15,13 @@ RUN pip install --no-cache-dir -r requirements.txt
COPY services/pos/app ./app
COPY shared ./shared
# Copy migrations and alembic config
COPY services/pos/migrations/ /app/migrations/
COPY services/pos/alembic.ini /app/alembic.ini
# Copy scripts directory
COPY scripts ./scripts
# Create necessary directories
RUN mkdir -p logs

View File

@@ -1,28 +0,0 @@
"""Initial POS service tables
Revision ID: 001_initial_pos
Create Date: 2024-01-01 12:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '001_initial_pos'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# TODO: Add table creation statements for POS service
# This is a placeholder migration - replace with actual table definitions
pass
def downgrade() -> None:
# TODO: Add table drop statements for POS service
pass

View File

@@ -18,6 +18,13 @@ COPY shared/ ./shared/
# Copy application code
COPY services/production/app/ ./app/
# Copy migrations and alembic config
COPY services/production/migrations/ /app/migrations/
COPY services/production/alembic.ini /app/alembic.ini
# Copy scripts directory
COPY scripts/ ./scripts/
# Create logs directory
RUN mkdir -p logs

View File

@@ -9,12 +9,26 @@ from .production import (
ProductionBatch,
ProductionSchedule,
ProductionCapacity,
QualityCheck
QualityCheckTemplate,
QualityCheck,
Equipment,
ProductionStatus,
ProductionPriority,
EquipmentStatus,
ProcessStage,
EquipmentType,
)
__all__ = [
"ProductionBatch",
"ProductionSchedule",
"ProductionSchedule",
"ProductionCapacity",
"QualityCheck"
"QualityCheckTemplate",
"QualityCheck",
"Equipment",
"ProductionStatus",
"ProductionPriority",
"EquipmentStatus",
"ProcessStage",
"EquipmentType",
]

View File

@@ -1,29 +0,0 @@
"""Initial production service tables
Revision ID: 001_initial_production
Revises:
Create Date: 2024-01-01 12:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '001_initial_production'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# TODO: Add table creation statements for production service
# This is a placeholder migration - replace with actual table definitions
pass
def downgrade() -> None:
# TODO: Add table drop statements for production service
pass

View File

@@ -18,6 +18,13 @@ COPY shared/ ./shared/
# Copy application code
COPY services/recipes/app/ ./app/
# Copy migrations and alembic config
COPY services/recipes/migrations/ /app/migrations/
COPY services/recipes/alembic.ini /app/alembic.ini
# Copy scripts directory
COPY scripts/ ./scripts/
# Create logs directory
RUN mkdir -p logs

View File

@@ -1,29 +0,0 @@
"""Initial ecipes service tables
Revision ID: 001_initial_recipes
Revises:
Create Date: 2024-01-01 12:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '001_initial_recipes'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# TODO: Add table creation statements for ecipes service
# This is a placeholder migration - replace with actual table definitions
pass
def downgrade() -> None:
# TODO: Add table drop statements for ecipes service
pass

View File

@@ -19,6 +19,13 @@ COPY shared/ /app/shared/
# Copy application code
COPY services/sales/app/ /app/app/
# Copy migrations and alembic config
COPY services/sales/migrations/ /app/migrations/
COPY services/sales/alembic.ini /app/alembic.ini
# Copy scripts directory
COPY scripts/ /app/scripts/
# Set Python path to include shared modules
ENV PYTHONPATH=/app

View File

@@ -1,29 +0,0 @@
"""Initial sales service tables
Revision ID: 001_initial_sales
Revises:
Create Date: 2024-01-01 12:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '001_initial_sales'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# TODO: Add table creation statements for sales service
# This is a placeholder migration - replace with actual table definitions
pass
def downgrade() -> None:
# TODO: Add table drop statements for sales service
pass

View File

@@ -19,6 +19,13 @@ COPY shared/ /app/shared/
# Copy application code
COPY services/suppliers/app/ /app/app/
# Copy migrations and alembic config
COPY services/suppliers/migrations/ /app/migrations/
COPY services/suppliers/alembic.ini /app/alembic.ini
# Copy scripts directory
COPY scripts/ /app/scripts/
# Set Python path to include shared modules
ENV PYTHONPATH=/app

View File

@@ -1,29 +0,0 @@
"""Initial supplioers service tables
Revision ID: 001_initial_suppliers
Revises:
Create Date: 2024-01-01 12:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '001_initial_suppliers'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# TODO: Add table creation statements for suppliers service
# This is a placeholder migration - replace with actual table definitions
pass
def downgrade() -> None:
# TODO: Add table drop statements for suppliers service
pass

View File

@@ -26,6 +26,9 @@ COPY --from=shared /shared /app/shared
# Copy application code
COPY services/tenant/ .
# Copy scripts directory
COPY scripts/ /app/scripts/
# Add shared libraries to Python path
ENV PYTHONPATH="/app:/app/shared:${PYTHONPATH:-}"

View File

@@ -0,0 +1,15 @@
"""
Tenant Service Models Package
Import all models to ensure they are registered with SQLAlchemy Base.
"""
# Import all models to register them with the Base metadata
from .tenants import Tenant, TenantMember, Subscription
# List all models for easier access
__all__ = [
"Tenant",
"TenantMember",
"Subscription",
]

View File

@@ -1,29 +0,0 @@
"""Initial tenant service tables
Revision ID: 001_initial_tenant
Revises:
Create Date: 2024-01-01 12:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '001_initial_tenant'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# TODO: Add table creation statements for tenant service
# This is a placeholder migration - replace with actual table definitions
pass
def downgrade() -> None:
# TODO: Add table drop statements for teannt service
pass

View File

@@ -26,6 +26,9 @@ COPY --from=shared /shared /app/shared
# Copy application code
COPY services/training/ .
# Copy scripts directory
COPY scripts/ /app/scripts/
# Add shared libraries to Python path
ENV PYTHONPATH="/app:/app/shared:${PYTHONPATH:-}"

View File

@@ -0,0 +1,23 @@
"""
Training Service Models Package
Import all models to ensure they are registered with SQLAlchemy Base.
"""
# Import all models to register them with the Base metadata
from .training import (
TrainedModel,
ModelTrainingLog,
ModelPerformanceMetric,
TrainingJobQueue,
ModelArtifact,
)
# List all models for easier access
__all__ = [
"TrainedModel",
"ModelTrainingLog",
"ModelPerformanceMetric",
"TrainingJobQueue",
"ModelArtifact",
]

View File

@@ -1,29 +0,0 @@
"""Initial training service tables
Revision ID: 001_initial_training
Revises:
Create Date: 2024-01-01 12:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql
# revision identifiers, used by Alembic.
revision: str = '001_initial_training'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# TODO: Add table creation statements for training service
# This is a placeholder migration - replace with actual table definitions
pass
def downgrade() -> None:
# TODO: Add table drop statements for training service
pass