aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/migrations/versions
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--webmentions_ssg/migrations/versions/ef8a9b6c2d41_received_status_history.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/webmentions_ssg/migrations/versions/ef8a9b6c2d41_received_status_history.py b/webmentions_ssg/migrations/versions/ef8a9b6c2d41_received_status_history.py
new file mode 100644
index 0000000..db63011
--- /dev/null
+++ b/webmentions_ssg/migrations/versions/ef8a9b6c2d41_received_status_history.py
@@ -0,0 +1,71 @@
+# SPDX-FileCopyrightText: 2026 Dennis Fink <me+coding@dennisfink.me>
+#
+# 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")