# SPDX-FileCopyrightText: 2026 Dennis Fink # # SPDX-License-Identifier: BSD-3-Clause """Record received Webmention lifecycle transitions. Revision ID: ef8a9b6c2d41 Revises: a4f91c2e08d7 """ import sqlalchemy as sa from alembic import op revision = "ef8a9b6c2d41" down_revision = "a4f91c2e08d7" branch_labels = None depends_on = None def upgrade(): op.create_table( "received_webmention_status_events", sa.Column("id", sa.Integer(), primary_key=True, autoincrement=True), sa.Column("webmention_uuid", sa.Uuid(), nullable=False), sa.Column( "status", sa.Enum( "received", "verifying", "verified", "failed", "source_removed", name="received_webmention_status", native_enum=False, ), nullable=False, ), sa.Column("action", sa.String(length=80), nullable=False), sa.Column("failure_reason", sa.Text(), nullable=True), sa.Column("recovery_attempts", sa.Integer(), nullable=False), sa.Column("occurred_at", sa.DateTime(timezone=True), nullable=False), sa.ForeignKeyConstraint( ["webmention_uuid"], ["received_webmentions.uuid"], ondelete="CASCADE", ), ) op.create_index( "ix_received_webmention_status_events_webmention_id", "received_webmention_status_events", ["webmention_uuid", "id"], ) # Existing rows have no saved transitions; record just the last known state. op.execute( sa.text( """INSERT INTO received_webmention_status_events (webmention_uuid, status, action, failure_reason, recovery_attempts, occurred_at) SELECT uuid, status, 'Existing status at upgrade', failure_reason, recovery_attempts, updated_at FROM received_webmentions""" ) ) def downgrade(): op.drop_index( "ix_received_webmention_status_events_webmention_id", table_name="received_webmention_status_events", ) op.drop_table("received_webmention_status_events")