aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/migrations/versions/9a4e0c8211d6_clarify_webmention_names.py
diff options
context:
space:
mode:
authorDennis Fink2026-11-15 21:18:19 +0100
committerDennis Fink2026-11-15 21:18:19 +0100
commit9b00526ab79257b65cedd71595848f09ecf84279 (patch)
treef9dfc5c0934499d47499bf083bd864f72947958c /webmentions_ssg/migrations/versions/9a4e0c8211d6_clarify_webmention_names.py
parent509d93b2976e353d29441a7a7b7e78ca466dc4fd (diff)
downloadwebmentions-ssg-9b00526ab79257b65cedd71595848f09ecf84279.tar.gz
webmentions-ssg-9b00526ab79257b65cedd71595848f09ecf84279.zip
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.
Diffstat (limited to 'webmentions_ssg/migrations/versions/9a4e0c8211d6_clarify_webmention_names.py')
-rw-r--r--webmentions_ssg/migrations/versions/9a4e0c8211d6_clarify_webmention_names.py178
1 files changed, 178 insertions, 0 deletions
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 <me+coding@dennisfink.me>
+#
+# 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")