?
TRCKR-174
sync phase-3
Created: 2025-12-09 Updated: 2025-12-16
Relationships Loading...
Attachments
Loading...
Comments (1)
agent · 2025-12-09
Implemented snapshot creation function as specified. ## Changes Made ### 1. create_snapshot() function (server/routes/sync.py:783-863) - Queries all non-deleted entities using existing store.list_*() methods - These methods already exclude soft-deleted entities (where deleted_at IS NOT NULL) - Builds snapshot data structure with server_version, created_at, and entities dict - Compresses JSON using zlib.compress() at level 6 - Stores compressed data as latin-1 string in sync_snapshots table - Records entity_counts and size_bytes for metadata - Returns SyncSnapshot model with all metadata ### 2. POST /api/sync/snapshot endpoint (server/routes/sync.py:866-891) - Admin-only endpoint requiring valid API key - Calls create_snapshot() and returns SnapshotResponse - Returns 401 for missing or invalid authentication ### 3. Comprehensive E2E tests (tests/test_snapshot_e2e.py) All 6 tests pass: - test_create_snapshot_empty_database - Verifies snapshot creation with no entities - test_create_snapshot_with_entities - Creates full snapshot with all entity types - test_create_snapshot_excludes_deleted - Confirms soft-deleted entities are excluded - test_create_snapshot_records_correct_version - Verifies server_version tracking - test_create_snapshot_without_auth - Ensures 401 without auth - test_create_snapshot_invalid_auth - Ensures 401 with invalid auth ## Data Format Snapshot data field contains zlib-compressed JSON: ```json { "server_version": 1500, "created_at": "2024-01-15T10:00:00Z", "entities": { "projects": [...], "milestones": [...], "issues": [...], "comments": [...], "relationships": [...] } } ``` ## Test Results ``` tests/test_snapshot_e2e.py::TestSnapshotCreation::test_create_snapshot_empty_database PASSED tests/test_snapshot_e2e.py::TestSnapshotCreation::test_create_snapshot_with_entities PASSED tests/test_snapshot_e2e.py::TestSnapshotCreation::test_create_snapshot_excludes_deleted PASSED tests/test_snapshot_e2e.py::TestSnapshotCreation::test_create_snapshot_records_correct_version PASSED tests/test_snapshot_e2e.py::TestSnapshotCreation::test_create_snapshot_without_auth PASSED tests/test_snapshot_e2e.py::TestSnapshotCreation::test_create_snapshot_invalid_auth PASSED All 59 sync and snapshot E2E tests pass. ``` ## Implementation Notes - Snapshots exclude soft-deleted entities automatically via store.list_*() methods - server_version comes from sync_history table (max server_version) - Empty database has server_version=0 - Compression reduces snapshot size significantly (typical 80-90% reduction) - latin-1 encoding used for SQLite TEXT storage of compressed bytes Committed to TRCKR-174 branch and pushed to remote. Ready for review.