From 48e61f49700409a2961f6195d49507658bb0ebc6 Mon Sep 17 00:00:00 2001 From: Urtzi Alfaro Date: Wed, 5 Nov 2025 14:46:04 +0100 Subject: [PATCH] Delete unused migrations --- .../20251029_1700_add_orchestration_runs.py | 112 ------------------ .../20251105_add_ai_insights_tracking.py | 88 -------------- 2 files changed, 200 deletions(-) delete mode 100644 services/orchestrator/migrations/versions/20251029_1700_add_orchestration_runs.py delete mode 100644 services/orchestrator/migrations/versions/20251105_add_ai_insights_tracking.py diff --git a/services/orchestrator/migrations/versions/20251029_1700_add_orchestration_runs.py b/services/orchestrator/migrations/versions/20251029_1700_add_orchestration_runs.py deleted file mode 100644 index f93d0c10..00000000 --- a/services/orchestrator/migrations/versions/20251029_1700_add_orchestration_runs.py +++ /dev/null @@ -1,112 +0,0 @@ -"""add orchestration runs table - -Revision ID: 20251029_1700 -Revises: -Create Date: 2025-10-29 17:00:00.000000 - -""" -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import postgresql - -# revision identifiers, used by Alembic. -revision = '20251029_1700' -down_revision = None -branch_labels = None -depends_on = None - - -def upgrade(): - # Create PostgreSQL enum type for orchestration status - orchestrationstatus_enum = postgresql.ENUM( - 'pending', 'running', 'completed', 'partial_success', 'failed', 'cancelled', - name='orchestrationstatus', - create_type=False - ) - orchestrationstatus_enum.create(op.get_bind(), checkfirst=True) - - # Create orchestration_runs table - op.create_table('orchestration_runs', - sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False), - sa.Column('tenant_id', postgresql.UUID(as_uuid=True), nullable=False), - sa.Column('run_number', sa.String(length=50), nullable=False), - sa.Column('status', orchestrationstatus_enum, nullable=False, server_default='pending'), - sa.Column('run_type', sa.String(length=50), nullable=False, server_default=sa.text("'scheduled'::character varying")), - sa.Column('priority', sa.String(length=20), nullable=False, server_default=sa.text("'normal'::character varying")), - sa.Column('started_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False), - sa.Column('completed_at', sa.DateTime(timezone=True), nullable=True), - sa.Column('duration_seconds', sa.Integer(), nullable=True), - sa.Column('forecasting_started_at', sa.DateTime(timezone=True), nullable=True), - sa.Column('forecasting_completed_at', sa.DateTime(timezone=True), nullable=True), - sa.Column('forecasting_status', sa.String(length=20), nullable=True), - sa.Column('forecasting_error', sa.Text(), nullable=True), - sa.Column('production_started_at', sa.DateTime(timezone=True), nullable=True), - sa.Column('production_completed_at', sa.DateTime(timezone=True), nullable=True), - sa.Column('production_status', sa.String(length=20), nullable=True), - sa.Column('production_error', sa.Text(), nullable=True), - sa.Column('procurement_started_at', sa.DateTime(timezone=True), nullable=True), - sa.Column('procurement_completed_at', sa.DateTime(timezone=True), nullable=True), - sa.Column('procurement_status', sa.String(length=20), nullable=True), - sa.Column('procurement_error', sa.Text(), nullable=True), - sa.Column('notification_started_at', sa.DateTime(timezone=True), nullable=True), - sa.Column('notification_completed_at', sa.DateTime(timezone=True), nullable=True), - sa.Column('notification_status', sa.String(length=20), nullable=True), - sa.Column('notification_error', sa.Text(), nullable=True), - sa.Column('forecasts_generated', sa.Integer(), nullable=False, server_default=sa.text('0')), - sa.Column('production_batches_created', sa.Integer(), nullable=False, server_default=sa.text('0')), - sa.Column('procurement_plans_created', sa.Integer(), nullable=False, server_default=sa.text('0')), - sa.Column('purchase_orders_created', sa.Integer(), nullable=False, server_default=sa.text('0')), - sa.Column('notifications_sent', sa.Integer(), nullable=False, server_default=sa.text('0')), - sa.Column('forecast_data', postgresql.JSONB(astext_type=sa.Text()), nullable=True), - sa.Column('retry_count', sa.Integer(), nullable=False, server_default=sa.text('0')), - sa.Column('max_retries_reached', sa.Boolean(), nullable=False, server_default=sa.text('false')), - sa.Column('error_message', sa.Text(), nullable=True), - sa.Column('error_details', postgresql.JSONB(astext_type=sa.Text()), nullable=True), - sa.Column('production_schedule_id', postgresql.UUID(as_uuid=True), nullable=True), - sa.Column('procurement_plan_id', postgresql.UUID(as_uuid=True), nullable=True), - sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False), - sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), onupdate=sa.text('now()'), nullable=False), - sa.Column('triggered_by', sa.String(length=100), nullable=True), - sa.Column('run_metadata', postgresql.JSONB(astext_type=sa.Text()), nullable=True), - sa.Column('fulfillment_rate', sa.Integer(), nullable=True), - sa.Column('on_time_delivery_rate', sa.Integer(), nullable=True), - sa.Column('cost_accuracy', sa.Integer(), nullable=True), - sa.Column('quality_score', sa.Integer(), nullable=True), - sa.PrimaryKeyConstraint('id', name=op.f('pk_orchestration_runs')) - ) - - # Create indexes - op.create_index('ix_orchestration_runs_tenant_id', 'orchestration_runs', ['tenant_id'], unique=False) - op.create_index('ix_orchestration_runs_run_number', 'orchestration_runs', ['run_number'], unique=True) - op.create_index('ix_orchestration_runs_status', 'orchestration_runs', ['status'], unique=False) - op.create_index('ix_orchestration_runs_started_at', 'orchestration_runs', ['started_at'], unique=False) - op.create_index('ix_orchestration_runs_completed_at', 'orchestration_runs', ['completed_at'], unique=False) - op.create_index('ix_orchestration_runs_run_type', 'orchestration_runs', ['run_type'], unique=False) - op.create_index('ix_orchestration_runs_trigger', 'orchestration_runs', ['triggered_by'], unique=False) - op.create_index('ix_orchestration_runs_tenant_status', 'orchestration_runs', ['tenant_id', 'status'], unique=False) - op.create_index('ix_orchestration_runs_tenant_type', 'orchestration_runs', ['tenant_id', 'run_type'], unique=False) - op.create_index('ix_orchestration_runs_tenant_started', 'orchestration_runs', ['tenant_id', 'started_at'], unique=False) - op.create_index('ix_orchestration_runs_fulfillment_rate', 'orchestration_runs', ['fulfillment_rate'], unique=False) - op.create_index('ix_orchestration_runs_on_time_delivery_rate', 'orchestration_runs', ['on_time_delivery_rate'], unique=False) - op.create_index('ix_orchestration_runs_cost_accuracy', 'orchestration_runs', ['cost_accuracy'], unique=False) - op.create_index('ix_orchestration_runs_quality_score', 'orchestration_runs', ['quality_score'], unique=False) - - -def downgrade(): - # Drop indexes - op.drop_index('ix_orchestration_runs_tenant_started', table_name='orchestration_runs') - op.drop_index('ix_orchestration_runs_tenant_type', table_name='orchestration_runs') - op.drop_index('ix_orchestration_runs_tenant_status', table_name='orchestration_runs') - op.drop_index('ix_orchestration_runs_trigger', table_name='orchestration_runs') - op.drop_index('ix_orchestration_runs_run_type', table_name='orchestration_runs') - op.drop_index('ix_orchestration_runs_completed_at', table_name='orchestration_runs') - op.drop_index('ix_orchestration_runs_started_at', table_name='orchestration_runs') - op.drop_index('ix_orchestration_runs_status', table_name='orchestration_runs') - op.drop_index('ix_orchestration_runs_run_number', table_name='orchestration_runs') - op.drop_index('ix_orchestration_runs_tenant_id', table_name='orchestration_runs') - - # Drop table - op.drop_table('orchestration_runs') - - # Drop enum type - op.execute("DROP TYPE IF EXISTS orchestrationstatus") diff --git a/services/orchestrator/migrations/versions/20251105_add_ai_insights_tracking.py b/services/orchestrator/migrations/versions/20251105_add_ai_insights_tracking.py deleted file mode 100644 index 0505cedd..00000000 --- a/services/orchestrator/migrations/versions/20251105_add_ai_insights_tracking.py +++ /dev/null @@ -1,88 +0,0 @@ -"""Add AI insights tracking and indexes - -Revision ID: 20251105_add_ai_insights -Revises: 20251029_1700_add_orchestration_runs -Create Date: 2025-11-05 12:00:00.000000 - -""" -from alembic import op -import sqlalchemy as sa -from sqlalchemy.dialects import postgresql - -# revision identifiers, used by Alembic. -revision = '20251105_add_ai_insights' -down_revision = '20251029_1700_add_orchestration_runs' -branch_labels = None -depends_on = None - - -def upgrade(): - """Add AI insights tracking columns, saga tracking, and performance indexes""" - - # Add AI Insights tracking columns - op.add_column('orchestration_runs', - sa.Column('ai_insights_started_at', sa.DateTime(timezone=True), nullable=True)) - op.add_column('orchestration_runs', - sa.Column('ai_insights_completed_at', sa.DateTime(timezone=True), nullable=True)) - op.add_column('orchestration_runs', - sa.Column('ai_insights_status', sa.String(20), nullable=True)) - op.add_column('orchestration_runs', - sa.Column('ai_insights_error', sa.Text(), nullable=True)) - op.add_column('orchestration_runs', - sa.Column('ai_insights_generated', sa.Integer(), nullable=False, server_default='0')) - op.add_column('orchestration_runs', - sa.Column('ai_insights_posted', sa.Integer(), nullable=False, server_default='0')) - - # Add forecast_id reference (was missing) - op.add_column('orchestration_runs', - sa.Column('forecast_id', postgresql.UUID(as_uuid=True), nullable=True)) - - # Add saga tracking columns - op.add_column('orchestration_runs', - sa.Column('saga_steps_total', sa.Integer(), nullable=False, server_default='0')) - op.add_column('orchestration_runs', - sa.Column('saga_steps_completed', sa.Integer(), nullable=False, server_default='0')) - - # Add performance indexes - # Index for querying by tenant_id and date range - op.create_index( - 'ix_orchestration_runs_tenant_started', - 'orchestration_runs', - ['tenant_id', 'started_at'], - unique=False - ) - - # Index for querying by status and date - op.create_index( - 'ix_orchestration_runs_status_started', - 'orchestration_runs', - ['status', 'started_at'], - unique=False - ) - - # Index for run number lookups (already unique, but add explicit index for performance) - # run_number already has index from unique constraint, so this is redundant - # op.create_index('ix_orchestration_runs_run_number', 'orchestration_runs', ['run_number'], unique=False) - - -def downgrade(): - """Remove AI insights tracking columns, saga tracking, and indexes""" - - # Remove indexes - op.drop_index('ix_orchestration_runs_status_started', table_name='orchestration_runs') - op.drop_index('ix_orchestration_runs_tenant_started', table_name='orchestration_runs') - - # Remove saga tracking columns - op.drop_column('orchestration_runs', 'saga_steps_completed') - op.drop_column('orchestration_runs', 'saga_steps_total') - - # Remove forecast_id reference - op.drop_column('orchestration_runs', 'forecast_id') - - # Remove AI insights tracking columns - op.drop_column('orchestration_runs', 'ai_insights_posted') - op.drop_column('orchestration_runs', 'ai_insights_generated') - op.drop_column('orchestration_runs', 'ai_insights_error') - op.drop_column('orchestration_runs', 'ai_insights_status') - op.drop_column('orchestration_runs', 'ai_insights_completed_at') - op.drop_column('orchestration_runs', 'ai_insights_started_at')