refactor: simplify mqtt pipeline state and remove event table
All checks were successful
Deploy to Production / deploy (push) Successful in 4m55s
All checks were successful
Deploy to Production / deploy (push) Successful in 4m55s
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
"""simplify mqtt parse tracking
|
||||
|
||||
Revision ID: b4c5d6e7f809
|
||||
Revises: a1b2c3d4e5f6
|
||||
Create Date: 2026-03-19 17:30:00.000000
|
||||
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "b4c5d6e7f809"
|
||||
down_revision = "a1b2c3d4e5f6"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.add_column(
|
||||
"terminal_message_raw",
|
||||
sa.Column("parsed_at", sa.DateTime(timezone=True), nullable=True),
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_terminal_message_raw_parsed_at"),
|
||||
"terminal_message_raw",
|
||||
["parsed_at"],
|
||||
unique=False,
|
||||
)
|
||||
|
||||
# Preserve historical parse outcomes before removing state-machine columns.
|
||||
op.execute(
|
||||
sa.text(
|
||||
"""
|
||||
UPDATE terminal_message_raw
|
||||
SET parsed_at = COALESCE(received_at, created_at)
|
||||
WHERE parse_status <> 'pending'
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
op.drop_index(
|
||||
op.f("ix_terminal_message_raw_next_retry_at"),
|
||||
table_name="terminal_message_raw",
|
||||
)
|
||||
op.drop_index(
|
||||
op.f("ix_terminal_message_raw_parse_status"),
|
||||
table_name="terminal_message_raw",
|
||||
)
|
||||
op.drop_column("terminal_message_raw", "next_retry_at")
|
||||
op.drop_column("terminal_message_raw", "parse_attempts")
|
||||
op.drop_column("terminal_message_raw", "parse_status")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.add_column(
|
||||
"terminal_message_raw",
|
||||
sa.Column(
|
||||
"parse_status",
|
||||
sa.String(length=32),
|
||||
nullable=False,
|
||||
server_default="pending",
|
||||
),
|
||||
)
|
||||
op.add_column(
|
||||
"terminal_message_raw",
|
||||
sa.Column("parse_attempts", sa.Integer(), nullable=False, server_default="0"),
|
||||
)
|
||||
op.add_column(
|
||||
"terminal_message_raw",
|
||||
sa.Column("next_retry_at", sa.DateTime(timezone=True), nullable=True),
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_terminal_message_raw_parse_status"),
|
||||
"terminal_message_raw",
|
||||
["parse_status"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_terminal_message_raw_next_retry_at"),
|
||||
"terminal_message_raw",
|
||||
["next_retry_at"],
|
||||
unique=False,
|
||||
)
|
||||
|
||||
op.execute(
|
||||
sa.text(
|
||||
"""
|
||||
UPDATE terminal_message_raw
|
||||
SET parse_status = CASE
|
||||
WHEN parsed_at IS NULL THEN 'pending'
|
||||
WHEN parse_error IS NULL THEN 'succeeded'
|
||||
ELSE 'failed'
|
||||
END,
|
||||
parse_attempts = CASE
|
||||
WHEN parsed_at IS NULL THEN 0
|
||||
ELSE 1
|
||||
END
|
||||
"""
|
||||
)
|
||||
)
|
||||
|
||||
op.drop_index(
|
||||
op.f("ix_terminal_message_raw_parsed_at"),
|
||||
table_name="terminal_message_raw",
|
||||
)
|
||||
op.drop_column("terminal_message_raw", "parsed_at")
|
||||
@@ -0,0 +1,60 @@
|
||||
"""drop terminal observation event table
|
||||
|
||||
Revision ID: c6d7e8f90123
|
||||
Revises: b4c5d6e7f809
|
||||
Create Date: 2026-03-19 18:20:00.000000
|
||||
|
||||
"""
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = "c6d7e8f90123"
|
||||
down_revision = "b4c5d6e7f809"
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.drop_table("terminal_observation_event")
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.create_table(
|
||||
"terminal_observation_event",
|
||||
sa.Column("id", sa.Uuid(), nullable=False),
|
||||
sa.Column("raw_id", sa.Uuid(), nullable=False),
|
||||
sa.Column("device_id", sa.String(length=255), nullable=False),
|
||||
sa.Column("event_time", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.Column("event_type", sa.String(length=64), nullable=False),
|
||||
sa.Column("payload_json", sa.JSON(), nullable=False),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False),
|
||||
sa.ForeignKeyConstraint(["raw_id"], ["terminal_message_raw.id"]),
|
||||
sa.PrimaryKeyConstraint("id"),
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_terminal_observation_event_device_id"),
|
||||
"terminal_observation_event",
|
||||
["device_id"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_terminal_observation_event_event_time"),
|
||||
"terminal_observation_event",
|
||||
["event_time"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_terminal_observation_event_event_type"),
|
||||
"terminal_observation_event",
|
||||
["event_type"],
|
||||
unique=False,
|
||||
)
|
||||
op.create_index(
|
||||
op.f("ix_terminal_observation_event_raw_id"),
|
||||
"terminal_observation_event",
|
||||
["raw_id"],
|
||||
unique=False,
|
||||
)
|
||||
Reference in New Issue
Block a user