fire-planner/alembic/versions/0006_fire_examples.py
Viktor Barzin b5bfe8b73c
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
examples: alembic 0006 — fire_example table
2026-05-28 22:06:37 +00:00

63 lines
2.8 KiB
Python

"""add fire_example table for Reddit-sourced FIRE examples
Revision ID: 0006
Revises: 0005
Create Date: 2026-05-28 00:00:00.000000
Backs the fire_planner.examples module: one row per Reddit post that
was extracted into a structured FIRE example. reddit_id UNIQUE makes
re-ingest idempotent.
"""
from collections.abc import Sequence
import sqlalchemy as sa
from alembic import op
revision: str = "0006"
down_revision: str | None = "0005"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None
SCHEMA = "fire_planner"
def upgrade() -> None:
op.create_table(
"fire_example",
sa.Column("id", sa.Integer(), nullable=False, autoincrement=True),
sa.Column("reddit_id", sa.String(length=16), nullable=False),
sa.Column("source_sub", sa.String(length=64), nullable=False),
sa.Column("post_url", sa.String(), nullable=False),
sa.Column("post_date", sa.Date(), nullable=False),
sa.Column("post_title", sa.String(), nullable=False),
sa.Column("country", sa.String(length=64), nullable=True),
sa.Column("city", sa.String(length=128), nullable=True),
sa.Column("portfolio_gbp", sa.Numeric(14, 2), nullable=True),
sa.Column("annual_exp_gbp", sa.Numeric(12, 2), nullable=True),
sa.Column("age", sa.SmallInteger(), nullable=True),
sa.Column("family_size", sa.SmallInteger(), nullable=True),
sa.Column("fi_status", sa.String(length=24), nullable=True),
sa.Column("is_retired", sa.Boolean(), nullable=True),
sa.Column("raw_currency", sa.String(length=3), nullable=True),
sa.Column("raw_excerpt", sa.String(), nullable=True),
sa.Column("llm_model", sa.String(length=64), nullable=False),
sa.Column("llm_confidence", sa.Numeric(3, 2), nullable=True),
sa.Column("extracted_at", sa.TIMESTAMP(timezone=True), nullable=False,
server_default=sa.func.now()),
sa.Column("ingested_at", sa.TIMESTAMP(timezone=True), nullable=False,
server_default=sa.func.now()),
sa.PrimaryKeyConstraint("id"),
sa.UniqueConstraint("reddit_id", name="uq_fire_example_reddit_id"),
schema=SCHEMA,
)
op.create_index("ix_fire_example_country", "fire_example", ["country"], schema=SCHEMA)
op.create_index("ix_fire_example_fi_status", "fire_example", ["fi_status"], schema=SCHEMA)
op.create_index("ix_fire_example_post_date", "fire_example", ["post_date"], schema=SCHEMA)
def downgrade() -> None:
op.drop_index("ix_fire_example_post_date", table_name="fire_example", schema=SCHEMA)
op.drop_index("ix_fire_example_fi_status", table_name="fire_example", schema=SCHEMA)
op.drop_index("ix_fire_example_country", table_name="fire_example", schema=SCHEMA)
op.drop_table("fire_example", schema=SCHEMA)