Improve backend
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
"""add_sales_data_updates_table
|
||||
|
||||
Revision ID: 00003
|
||||
Revises: 00002
|
||||
Create Date: 2025-11-17 17: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 = '00003'
|
||||
down_revision: Union[str, None] = '00002'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Create sales_data_updates table
|
||||
op.create_table(
|
||||
'sales_data_updates',
|
||||
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('tenant_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('update_date_start', sa.Date(), nullable=False),
|
||||
sa.Column('update_date_end', sa.Date(), nullable=False),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column('update_source', sa.String(length=100), nullable=True),
|
||||
sa.Column('records_affected', sa.Integer(), nullable=True),
|
||||
sa.Column('validation_status', sa.String(length=50), nullable=True),
|
||||
sa.Column('validation_run_id', postgresql.UUID(as_uuid=True), nullable=True),
|
||||
sa.Column('validated_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column('validation_error', sa.String(length=500), nullable=True),
|
||||
sa.Column('requires_validation', sa.Boolean(), nullable=True),
|
||||
sa.Column('import_job_id', sa.String(length=255), nullable=True),
|
||||
sa.Column('notes', sa.String(length=500), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
|
||||
# Create indexes for sales_data_updates
|
||||
op.create_index(
|
||||
'ix_sales_data_updates_tenant_id',
|
||||
'sales_data_updates',
|
||||
['tenant_id'],
|
||||
unique=False
|
||||
)
|
||||
op.create_index(
|
||||
'ix_sales_data_updates_update_date_start',
|
||||
'sales_data_updates',
|
||||
['update_date_start'],
|
||||
unique=False
|
||||
)
|
||||
op.create_index(
|
||||
'ix_sales_data_updates_update_date_end',
|
||||
'sales_data_updates',
|
||||
['update_date_end'],
|
||||
unique=False
|
||||
)
|
||||
op.create_index(
|
||||
'ix_sales_updates_tenant_status',
|
||||
'sales_data_updates',
|
||||
['tenant_id', 'validation_status', 'created_at'],
|
||||
unique=False
|
||||
)
|
||||
op.create_index(
|
||||
'ix_sales_updates_date_range',
|
||||
'sales_data_updates',
|
||||
['tenant_id', 'update_date_start', 'update_date_end'],
|
||||
unique=False
|
||||
)
|
||||
op.create_index(
|
||||
'ix_sales_updates_validation_status',
|
||||
'sales_data_updates',
|
||||
['validation_status'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# Drop indexes
|
||||
op.drop_index('ix_sales_updates_validation_status', table_name='sales_data_updates')
|
||||
op.drop_index('ix_sales_updates_date_range', table_name='sales_data_updates')
|
||||
op.drop_index('ix_sales_updates_tenant_status', table_name='sales_data_updates')
|
||||
op.drop_index('ix_sales_data_updates_update_date_end', table_name='sales_data_updates')
|
||||
op.drop_index('ix_sales_data_updates_update_date_start', table_name='sales_data_updates')
|
||||
op.drop_index('ix_sales_data_updates_tenant_id', table_name='sales_data_updates')
|
||||
|
||||
# Drop table
|
||||
op.drop_table('sales_data_updates')
|
||||
@@ -0,0 +1,89 @@
|
||||
"""add_validation_runs_table
|
||||
|
||||
Revision ID: 00002
|
||||
Revises: 301bc59f6dfb
|
||||
Create Date: 2025-11-17 16:30: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 = '00002'
|
||||
down_revision: Union[str, None] = '301bc59f6dfb'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# Create validation_runs table
|
||||
op.create_table(
|
||||
'validation_runs',
|
||||
sa.Column('id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('tenant_id', postgresql.UUID(as_uuid=True), nullable=False),
|
||||
sa.Column('orchestration_run_id', postgresql.UUID(as_uuid=True), nullable=True),
|
||||
sa.Column('validation_start_date', sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column('validation_end_date', sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column('started_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column('completed_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column('duration_seconds', sa.Float(), nullable=True),
|
||||
sa.Column('status', sa.String(length=50), nullable=True),
|
||||
sa.Column('total_forecasts_evaluated', sa.Integer(), nullable=True),
|
||||
sa.Column('forecasts_with_actuals', sa.Integer(), nullable=True),
|
||||
sa.Column('forecasts_without_actuals', sa.Integer(), nullable=True),
|
||||
sa.Column('overall_mae', sa.Float(), nullable=True),
|
||||
sa.Column('overall_mape', sa.Float(), nullable=True),
|
||||
sa.Column('overall_rmse', sa.Float(), nullable=True),
|
||||
sa.Column('overall_r2_score', sa.Float(), nullable=True),
|
||||
sa.Column('overall_accuracy_percentage', sa.Float(), nullable=True),
|
||||
sa.Column('total_predicted_demand', sa.Float(), nullable=True),
|
||||
sa.Column('total_actual_demand', sa.Float(), nullable=True),
|
||||
sa.Column('metrics_by_product', postgresql.JSON(astext_type=sa.Text()), nullable=True),
|
||||
sa.Column('metrics_by_location', postgresql.JSON(astext_type=sa.Text()), nullable=True),
|
||||
sa.Column('metrics_records_created', sa.Integer(), nullable=True),
|
||||
sa.Column('error_message', sa.Text(), nullable=True),
|
||||
sa.Column('error_details', postgresql.JSON(astext_type=sa.Text()), nullable=True),
|
||||
sa.Column('triggered_by', sa.String(length=100), nullable=True),
|
||||
sa.Column('execution_mode', sa.String(length=50), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
|
||||
# Create indexes for validation_runs
|
||||
op.create_index(
|
||||
'ix_validation_runs_tenant_id',
|
||||
'validation_runs',
|
||||
['tenant_id'],
|
||||
unique=False
|
||||
)
|
||||
op.create_index(
|
||||
'ix_validation_runs_tenant_created',
|
||||
'validation_runs',
|
||||
['tenant_id', 'started_at'],
|
||||
unique=False
|
||||
)
|
||||
op.create_index(
|
||||
'ix_validation_runs_status',
|
||||
'validation_runs',
|
||||
['status', 'started_at'],
|
||||
unique=False
|
||||
)
|
||||
op.create_index(
|
||||
'ix_validation_runs_orchestration',
|
||||
'validation_runs',
|
||||
['orchestration_run_id'],
|
||||
unique=False
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# Drop indexes
|
||||
op.drop_index('ix_validation_runs_orchestration', table_name='validation_runs')
|
||||
op.drop_index('ix_validation_runs_status', table_name='validation_runs')
|
||||
op.drop_index('ix_validation_runs_tenant_created', table_name='validation_runs')
|
||||
op.drop_index('ix_validation_runs_tenant_id', table_name='validation_runs')
|
||||
|
||||
# Drop table
|
||||
op.drop_table('validation_runs')
|
||||
Reference in New Issue
Block a user