From 9b00526ab79257b65cedd71595848f09ecf84279 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sun, 15 Nov 2026 21:18:19 +0100 Subject: refactor(core)!: clarify Webmention domain terminology Rename ambiguous models, statuses, task modules, fields, and helpers so names reflect source documents, verification, endpoint discovery, and delivery state. Migrate persisted status values and database identifiers without losing existing Webmention data. BREAKING CHANGE: persisted status values and database schema names have changed, and several public Python names have been renamed. --- .../9a4e0c8211d6_clarify_webmention_names.py | 178 +++++++++++++++++++++ .../d845aa7fbc19_portable_url_fingerprints.py | 3 +- 2 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 webmentions_ssg/migrations/versions/9a4e0c8211d6_clarify_webmention_names.py (limited to 'webmentions_ssg/migrations') diff --git a/webmentions_ssg/migrations/versions/9a4e0c8211d6_clarify_webmention_names.py b/webmentions_ssg/migrations/versions/9a4e0c8211d6_clarify_webmention_names.py new file mode 100644 index 0000000..23ff56a --- /dev/null +++ b/webmentions_ssg/migrations/versions/9a4e0c8211d6_clarify_webmention_names.py @@ -0,0 +1,178 @@ +# SPDX-FileCopyrightText: 2026 Dennis Fink +# +# SPDX-License-Identifier: BSD-3-Clause + +"""Clarify source-document and Webmention lifecycle names. + +Revision ID: 9a4e0c8211d6 +Revises: 7c38bb1a935e +""" + +import sqlalchemy as sa +from alembic import op + +revision = "9a4e0c8211d6" +down_revision = "7c38bb1a935e" +branch_labels = None +depends_on = None + + +_OLD_RECEIVED_STATUS = sa.Enum( + "received", + "verifying", + "verified", + "failed", + "deleted", + name="received_webmention_status", + native_enum=False, +) +_NEW_RECEIVED_STATUS = sa.Enum( + "received", + "verifying", + "verified", + "failed", + "source_removed", + name="received_webmention_status", + native_enum=False, +) + + +def upgrade() -> None: + # RENAME TABLE retains existing source UUIDs and updates referencing FKs. + op.rename_table("sources", "source_documents") + + with op.batch_alter_table("received_webmentions") as batch: + batch.drop_constraint("uq_webmention_url_digest", type_="unique") + batch.alter_column( + "url_digest", + new_column_name="source_target_digest", + existing_type=sa.String(64), + existing_nullable=False, + ) + # The new enum string is 14 characters, not the old VARCHAR(9). + batch.alter_column( + "status", + existing_type=_OLD_RECEIVED_STATUS, + type_=_NEW_RECEIVED_STATUS, + existing_nullable=False, + ) + + with op.batch_alter_table("received_webmentions") as batch: + batch.create_unique_constraint( + "uq_webmention_source_target_digest", ["source_target_digest"] + ) + + with op.batch_alter_table("sent_webmentions") as batch: + batch.drop_index("ix_sent_webmentions_source_id") + batch.drop_constraint("uq_sent_webmention_source_target_digest", type_="unique") + batch.alter_column( + "source_id", + new_column_name="source_uuid", + existing_type=sa.Uuid(), + existing_nullable=False, + ) + batch.alter_column( + "active", + new_column_name="linked", + existing_type=sa.Boolean(), + existing_nullable=False, + ) + batch.alter_column( + "endpoint", + new_column_name="webmention_endpoint", + existing_type=sa.Text(), + existing_nullable=True, + ) + batch.alter_column( + "response_status", + new_column_name="endpoint_response_status", + existing_type=sa.Integer(), + existing_nullable=True, + ) + + with op.batch_alter_table("sent_webmentions") as batch: + batch.create_unique_constraint( + "uq_sent_webmention_source_uuid_target_digest", + ["source_uuid", "target_digest"], + ) + + op.create_index( + "ix_sent_webmentions_source_uuid", "sent_webmentions", ["source_uuid"] + ) + + op.execute( + "UPDATE received_webmentions SET status = 'source_removed' " + "WHERE status = 'deleted'" + ) + op.execute( + "UPDATE sent_webmentions SET status = 'no_endpoint' " + "WHERE status = 'unsupported'" + ) + + +def downgrade() -> None: + op.execute( + "UPDATE received_webmentions SET status = 'deleted' " + "WHERE status = 'source_removed'" + ) + op.execute( + "UPDATE sent_webmentions SET status = 'unsupported' " + "WHERE status = 'no_endpoint'" + ) + + with op.batch_alter_table("sent_webmentions") as batch: + batch.drop_index("ix_sent_webmentions_source_uuid") + batch.drop_constraint( + "uq_sent_webmention_source_uuid_target_digest", type_="unique" + ) + batch.alter_column( + "source_uuid", + new_column_name="source_id", + existing_type=sa.Uuid(), + existing_nullable=False, + ) + batch.alter_column( + "linked", + new_column_name="active", + existing_type=sa.Boolean(), + existing_nullable=False, + ) + batch.alter_column( + "webmention_endpoint", + new_column_name="endpoint", + existing_type=sa.Text(), + existing_nullable=True, + ) + batch.alter_column( + "endpoint_response_status", + new_column_name="response_status", + existing_type=sa.Integer(), + existing_nullable=True, + ) + + with op.batch_alter_table("sent_webmentions") as batch: + batch.create_unique_constraint( + "uq_sent_webmention_source_target_digest", ["source_id", "target_digest"] + ) + + op.create_index("ix_sent_webmentions_source_id", "sent_webmentions", ["source_id"]) + + with op.batch_alter_table("received_webmentions") as batch: + batch.drop_constraint("uq_webmention_source_target_digest", type_="unique") + batch.alter_column( + "source_target_digest", + new_column_name="url_digest", + existing_type=sa.String(64), + existing_nullable=False, + ) + batch.alter_column( + "status", + existing_type=_NEW_RECEIVED_STATUS, + type_=_OLD_RECEIVED_STATUS, + existing_nullable=False, + ) + + with op.batch_alter_table("received_webmentions") as batch: + batch.create_unique_constraint("uq_webmention_url_digest", ["url_digest"]) + + op.rename_table("source_documents", "sources") diff --git a/webmentions_ssg/migrations/versions/d845aa7fbc19_portable_url_fingerprints.py b/webmentions_ssg/migrations/versions/d845aa7fbc19_portable_url_fingerprints.py index 41c5376..8518b15 100644 --- a/webmentions_ssg/migrations/versions/d845aa7fbc19_portable_url_fingerprints.py +++ b/webmentions_ssg/migrations/versions/d845aa7fbc19_portable_url_fingerprints.py @@ -11,7 +11,8 @@ Revises: c0272f25ce17 import sqlalchemy as sa from alembic import op -from webmentions_ssg.models import received_url_digest, sent_target_digest +from webmentions_ssg.models import source_target_digest as received_url_digest +from webmentions_ssg.models import target_digest as sent_target_digest revision = "d845aa7fbc19" down_revision = "c0272f25ce17" -- cgit v1.3.1