From 62986245a2ea7e8bdcff74370f6624a7e9a77783 Mon Sep 17 00:00:00 2001 From: Artyom Date: Thu, 29 Oct 2026 03:11:59 +0300 Subject: [PATCH] Add the quarantine columns for the storage reconciler Migration 0004 adds a nullable quarantine reason (missing, size or digest mismatch) and the time it was set, both null or both present. Nullable columns without a default only touch the catalogue, so the running version keeps working while the migration is applied. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01V1d3RLHNBBMA6UqBLLJv27 --- openspec/changes/add-lab4-storage-reconciler/tasks.md | 4 ++-- src/messenger/migrations/0004_attachment_quarantine.sql | 6 ++++++ student-tests/api/test_migrations.py | 7 ++++++- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 src/messenger/migrations/0004_attachment_quarantine.sql diff --git a/openspec/changes/add-lab4-storage-reconciler/tasks.md b/openspec/changes/add-lab4-storage-reconciler/tasks.md index 93f27b0a..1deabe08 100644 --- a/openspec/changes/add-lab4-storage-reconciler/tasks.md +++ b/openspec/changes/add-lab4-storage-reconciler/tasks.md @@ -1,7 +1,7 @@ ## 1. Схема и миграции -- [ ] 1.1 `0004_attachment_quarantine.sql`: `quarantine_reason` с `CHECK`, `quarantined_at`, согласованность пары -- [ ] 1.2 Проверка группы: `make student-test` (`test_migrations.py`: повтор без изменений) +- [x] 1.1 `0004_attachment_quarantine.sql`: `quarantine_reason` с `CHECK`, `quarantined_at`, согласованность пары +- [x] 1.2 Проверка группы: `make student-test` (`test_migrations.py`: повтор без изменений) ## 2. Зона `attachments`: домен и приложение diff --git a/src/messenger/migrations/0004_attachment_quarantine.sql b/src/messenger/migrations/0004_attachment_quarantine.sql new file mode 100644 index 00000000..7108f5f0 --- /dev/null +++ b/src/messenger/migrations/0004_attachment_quarantine.sql @@ -0,0 +1,6 @@ +ALTER TABLE attachments + ADD COLUMN quarantine_reason text + CHECK (quarantine_reason IN ('missing', 'size_mismatch', 'sha_mismatch')), + ADD COLUMN quarantined_at timestamptz, + ADD CONSTRAINT attachments_quarantine_check + CHECK ((quarantine_reason IS NULL) = (quarantined_at IS NULL)); diff --git a/student-tests/api/test_migrations.py b/student-tests/api/test_migrations.py index 9fa6e7ef..8c5c269b 100644 --- a/student-tests/api/test_migrations.py +++ b/student-tests/api/test_migrations.py @@ -25,7 +25,12 @@ async def counts() -> list[int]: async def test_migrations_are_ordered_and_versioned() -> None: versions = [version for version, _ in migrations()] assert versions == sorted(versions) - assert versions[:3] == ["0001_init", "0002_idempotency_keys", "0003_attachments"] + assert versions == [ + "0001_init", + "0002_idempotency_keys", + "0003_attachments", + "0004_attachment_quarantine", + ] applied = await scalar("SELECT array_agg(version ORDER BY version) FROM schema_migrations") assert applied == versions