aboutsummaryrefslogtreecommitdiff
path: root/tests/cli
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cli')
-rw-r--r--tests/cli/test_database.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/cli/test_database.py b/tests/cli/test_database.py
index 1c36d1f..7095d51 100644
--- a/tests/cli/test_database.py
+++ b/tests/cli/test_database.py
@@ -213,3 +213,47 @@ def test_create_db_preserves_logging(
database_app.logger.warning("Logging still works after migration")
assert "Logging still works after migration" in caplog.text
+
+
+def test_upgrade_backfills_portable_digest_for_existing_received_rows(
+ database_app: Flask,
+) -> None:
+ """Upgrade a pre-fingerprint SQLite database without losing historical rows."""
+ from webmentions_ssg.url_digest import received_url_digest
+
+ with database_app.app_context():
+ migrate_upgrade(revision="c0272f25ce17")
+ with DATABASE.engine.begin() as connection:
+ connection.execute(
+ sa.text(
+ "INSERT INTO received_webmentions "
+ "(uuid, source, target, status, updated_at) "
+ "VALUES (:uuid, :source, :target, :status, :updated_at)"
+ ),
+ {
+ "uuid": "0" * 31 + "1",
+ "source": "https://source.example/old",
+ "target": "https://dennisfink.me/target",
+ "status": "verified",
+ "updated_at": "2026-01-01 00:00:00",
+ },
+ )
+ migrate_upgrade()
+ with DATABASE.engine.connect() as connection:
+ result = connection.execute(
+ sa.text(
+ "SELECT source, target, status, url_digest "
+ "FROM received_webmentions"
+ )
+ ).one()
+ assert result.status == "verified"
+ assert result.url_digest == received_url_digest(
+ result.source, result.target
+ )
+ constraints = inspect(connection).get_unique_constraints(
+ "received_webmentions"
+ )
+ assert any(
+ constraint["column_names"] == ["url_digest"]
+ for constraint in constraints
+ )