Add database migrations for mockupAWS v0.2.0: - DB-003: scenario_logs table * Stores received log entries with SHA256 hash for deduplication * PII detection flags * Metrics: size_bytes, token_count, sqs_blocks * Indexes on scenario_id, received_at, message_hash, has_pii - DB-004: scenario_metrics table * Time-series storage for metrics aggregation * Supports: sqs, lambda, bedrock, safety metric types * Flexible JSONB metadata field * BRIN index on timestamp for efficient queries - DB-005: aws_pricing table * Stores AWS service pricing by region * Supports price history with effective_from/to dates * Active pricing flag for current rates * Index on service, region, tier combination - DB-006: reports table * Generated report tracking * Supports PDF and CSV formats * File path and size tracking * Metadata JSONB for extensibility All tables include: - UUID primary keys with auto-generation - Foreign key constraints with CASCADE delete - Appropriate indexes for query performance - Check constraints for data validation Tasks: DB-003, DB-004, DB-005, DB-006 complete
82 lines
2.5 KiB
Python
82 lines
2.5 KiB
Python
"""create scenario_metrics table
|
|
|
|
Revision ID: 5e247ed57b77
|
|
Revises: e46de4b0264a
|
|
Create Date: 2026-04-07 13:49:11.267167
|
|
|
|
"""
|
|
|
|
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 = "5e247ed57b77"
|
|
down_revision: Union[str, Sequence[str], None] = "e46de4b0264a"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
"""Upgrade schema."""
|
|
op.create_table(
|
|
"scenario_metrics",
|
|
sa.Column(
|
|
"id",
|
|
postgresql.UUID(as_uuid=True),
|
|
primary_key=True,
|
|
server_default=sa.text("uuid_generate_v4()"),
|
|
),
|
|
sa.Column(
|
|
"scenario_id",
|
|
postgresql.UUID(as_uuid=True),
|
|
sa.ForeignKey("scenarios.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
),
|
|
sa.Column(
|
|
"timestamp",
|
|
sa.TIMESTAMP(timezone=True),
|
|
server_default=sa.text("NOW()"),
|
|
nullable=False,
|
|
),
|
|
sa.Column(
|
|
"metric_type", sa.String(50), nullable=False
|
|
), # 'sqs', 'lambda', 'bedrock', 'safety'
|
|
sa.Column("metric_name", sa.String(100), nullable=False),
|
|
sa.Column(
|
|
"value", sa.DECIMAL(15, 6), server_default="0.000000", nullable=False
|
|
),
|
|
sa.Column(
|
|
"unit", sa.String(20), nullable=False
|
|
), # 'count', 'bytes', 'tokens', 'usd', 'invocations'
|
|
sa.Column("metadata", postgresql.JSONB(), server_default="{}"),
|
|
)
|
|
|
|
# Add indexes
|
|
op.create_index("idx_metrics_scenario_id", "scenario_metrics", ["scenario_id"])
|
|
op.create_index(
|
|
"idx_metrics_timestamp",
|
|
"scenario_metrics",
|
|
["timestamp"],
|
|
postgresql_using="brin",
|
|
)
|
|
op.create_index("idx_metrics_type", "scenario_metrics", ["metric_type"])
|
|
op.create_index(
|
|
"idx_metrics_scenario_type", "scenario_metrics", ["scenario_id", "metric_type"]
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
"""Downgrade schema."""
|
|
# Drop indexes
|
|
op.drop_index("idx_metrics_scenario_type", table_name="scenario_metrics")
|
|
op.drop_index("idx_metrics_type", table_name="scenario_metrics")
|
|
op.drop_index("idx_metrics_timestamp", table_name="scenario_metrics")
|
|
op.drop_index("idx_metrics_scenario_id", table_name="scenario_metrics")
|
|
|
|
# Drop table
|
|
op.drop_table("scenario_metrics")
|