| 1 | """Add ai review tables |
| 2 | |
| 3 | Revision ID: f75a3f9bb316 |
| 4 | Revises: 41a7b41cd83a |
| 5 | Create Date: 2026-04-22 11:19:24.303540 |
| 6 | |
| 7 | """ |
| 8 | from typing import Sequence |
| 9 | from typing import Union |
| 10 | |
| 11 | import sqlalchemy as sa |
| 12 | |
| 13 | from alembic import op |
| 14 | |
| 15 | # revision identifiers, used by Alembic. |
| 16 | revision: str = "f75a3f9bb316" |
| 17 | down_revision: Union[str, None] = "41a7b41cd83a" |
| 18 | branch_labels: Union[str, Sequence[str], None] = None |
| 19 | depends_on: Union[str, Sequence[str], None] = None |
| 20 | |
| 21 | |
| 22 | def upgrade() -> None: |
| 23 | # ### commands auto generated by Alembic - please adjust! ### |
| 24 | op.create_table( |
| 25 | "ai_analyst_review", |
| 26 | sa.Column("missing_steps", sa.Text(), nullable=True), |
| 27 | sa.Column("suggested_edits", sa.Text(), nullable=True), |
| 28 | sa.Column("id", sa.Integer(), nullable=False), |
| 29 | sa.Column("report_id", sa.Integer(), nullable=False), |
| 30 | sa.Column("alert_id", sa.Integer(), nullable=False), |
| 31 | sa.Column("customer_code", sa.String(length=64), nullable=False), |
| 32 | sa.Column("reviewer_user_id", sa.Integer(), nullable=False), |
| 33 | sa.Column("overall_verdict", sa.String(length=4), nullable=True), |
| 34 | sa.Column("template_choice", sa.String(length=7), nullable=True), |
| 35 | sa.Column("template_used", sa.String(length=128), nullable=True), |
| 36 | sa.Column("rating_instructions", sa.Integer(), nullable=True), |
| 37 | sa.Column("rating_artifacts", sa.Integer(), nullable=True), |
| 38 | sa.Column("rating_severity", sa.Integer(), nullable=True), |
| 39 | sa.Column("created_at", sa.DateTime(), nullable=False), |
| 40 | sa.ForeignKeyConstraint( |
| 41 | ["customer_code"], |
| 42 | ["customers.customer_code"], |
| 43 | ), |
| 44 | sa.ForeignKeyConstraint( |
| 45 | ["report_id"], |
| 46 | ["ai_analyst_report.id"], |
| 47 | ), |
| 48 | sa.PrimaryKeyConstraint("id"), |
| 49 | ) |
| 50 | op.create_index(op.f("ix_ai_analyst_review_alert_id"), "ai_analyst_review", ["alert_id"], unique=False) |
| 51 | op.create_index(op.f("ix_ai_analyst_review_created_at"), "ai_analyst_review", ["created_at"], unique=False) |
| 52 | op.create_index(op.f("ix_ai_analyst_review_customer_code"), "ai_analyst_review", ["customer_code"], unique=False) |
| 53 | op.create_index(op.f("ix_ai_analyst_review_report_id"), "ai_analyst_review", ["report_id"], unique=False) |
| 54 | op.create_index(op.f("ix_ai_analyst_review_reviewer_user_id"), "ai_analyst_review", ["reviewer_user_id"], unique=False) |
| 55 | op.create_table( |
| 56 | "ai_analyst_ioc_review", |
| 57 | sa.Column("note", sa.Text(), nullable=True), |
| 58 | sa.Column("id", sa.Integer(), nullable=False), |
| 59 | sa.Column("review_id", sa.Integer(), nullable=False), |
| 60 | sa.Column("ioc_id", sa.Integer(), nullable=False), |
| 61 | sa.Column("verdict_correct", sa.Boolean(), nullable=False), |
| 62 | sa.Column("created_at", sa.DateTime(), nullable=False), |
| 63 | sa.ForeignKeyConstraint( |
| 64 | ["ioc_id"], |
| 65 | ["ai_analyst_ioc.id"], |
| 66 | ), |
| 67 | sa.ForeignKeyConstraint( |
| 68 | ["review_id"], |
| 69 | ["ai_analyst_review.id"], |
| 70 | ), |
| 71 | sa.PrimaryKeyConstraint("id"), |
| 72 | ) |
| 73 | op.create_index(op.f("ix_ai_analyst_ioc_review_created_at"), "ai_analyst_ioc_review", ["created_at"], unique=False) |
| 74 | op.create_index(op.f("ix_ai_analyst_ioc_review_ioc_id"), "ai_analyst_ioc_review", ["ioc_id"], unique=False) |
| 75 | op.create_index(op.f("ix_ai_analyst_ioc_review_review_id"), "ai_analyst_ioc_review", ["review_id"], unique=False) |
| 76 | op.create_table( |
| 77 | "ai_analyst_palace_lesson", |
| 78 | sa.Column("lesson_text", sa.Text(), nullable=True), |
| 79 | sa.Column("id", sa.Integer(), nullable=False), |
| 80 | sa.Column("review_id", sa.Integer(), nullable=True), |
| 81 | sa.Column("customer_code", sa.String(length=64), nullable=False), |
| 82 | sa.Column("lesson_type", sa.String(length=20), nullable=False), |
| 83 | sa.Column("durability", sa.String(length=8), nullable=False), |
| 84 | sa.Column("status", sa.String(length=8), nullable=False), |
| 85 | sa.Column("ingested_at", sa.DateTime(), nullable=True), |
| 86 | sa.Column("created_at", sa.DateTime(), nullable=False), |
| 87 | sa.ForeignKeyConstraint( |
| 88 | ["customer_code"], |
| 89 | ["customers.customer_code"], |
| 90 | ), |
| 91 | sa.ForeignKeyConstraint( |
| 92 | ["review_id"], |
| 93 | ["ai_analyst_review.id"], |
| 94 | ), |
| 95 | sa.PrimaryKeyConstraint("id"), |
| 96 | ) |
| 97 | op.create_index(op.f("ix_ai_analyst_palace_lesson_created_at"), "ai_analyst_palace_lesson", ["created_at"], unique=False) |
| 98 | op.create_index(op.f("ix_ai_analyst_palace_lesson_customer_code"), "ai_analyst_palace_lesson", ["customer_code"], unique=False) |
| 99 | op.create_index(op.f("ix_ai_analyst_palace_lesson_review_id"), "ai_analyst_palace_lesson", ["review_id"], unique=False) |
| 100 | op.create_index(op.f("ix_ai_analyst_palace_lesson_status"), "ai_analyst_palace_lesson", ["status"], unique=False) |
| 101 | # ### end Alembic commands ### |
| 102 | |
| 103 | |
| 104 | def downgrade() -> None: |
| 105 | # ### commands auto generated by Alembic - please adjust! ### |
| 106 | op.drop_index(op.f("ix_ai_analyst_palace_lesson_status"), table_name="ai_analyst_palace_lesson") |
| 107 | op.drop_index(op.f("ix_ai_analyst_palace_lesson_review_id"), table_name="ai_analyst_palace_lesson") |
| 108 | op.drop_index(op.f("ix_ai_analyst_palace_lesson_customer_code"), table_name="ai_analyst_palace_lesson") |
| 109 | op.drop_index(op.f("ix_ai_analyst_palace_lesson_created_at"), table_name="ai_analyst_palace_lesson") |
| 110 | op.drop_table("ai_analyst_palace_lesson") |
| 111 | op.drop_index(op.f("ix_ai_analyst_ioc_review_review_id"), table_name="ai_analyst_ioc_review") |
| 112 | op.drop_index(op.f("ix_ai_analyst_ioc_review_ioc_id"), table_name="ai_analyst_ioc_review") |
| 113 | op.drop_index(op.f("ix_ai_analyst_ioc_review_created_at"), table_name="ai_analyst_ioc_review") |
| 114 | op.drop_table("ai_analyst_ioc_review") |
| 115 | op.drop_index(op.f("ix_ai_analyst_review_reviewer_user_id"), table_name="ai_analyst_review") |
| 116 | op.drop_index(op.f("ix_ai_analyst_review_report_id"), table_name="ai_analyst_review") |
| 117 | op.drop_index(op.f("ix_ai_analyst_review_customer_code"), table_name="ai_analyst_review") |
| 118 | op.drop_index(op.f("ix_ai_analyst_review_created_at"), table_name="ai_analyst_review") |
| 119 | op.drop_index(op.f("ix_ai_analyst_review_alert_id"), table_name="ai_analyst_review") |
| 120 | op.drop_table("ai_analyst_review") |
| 121 | # ### end Alembic commands ### |