From edb7e4315ca4b7b748f46df107b23d37c6df07e6 Mon Sep 17 00:00:00 2001 From: David Riegel <40246197+davidriegel@users.noreply.github.com> Date: Fri, 7 Aug 2026 14:31:06 +0200 Subject: [PATCH] feat: version the hard delete events instead of keeping them only in production --- .../20260807143052_add_hard_delete_events.sql | 22 +++++++++++++++++++ migrations/README.md | 13 +++++++++++ 2 files changed, 35 insertions(+) create mode 100644 migrations/20260807143052_add_hard_delete_events.sql diff --git a/migrations/20260807143052_add_hard_delete_events.sql b/migrations/20260807143052_add_hard_delete_events.sql new file mode 100644 index 0000000..1a59da2 --- /dev/null +++ b/migrations/20260807143052_add_hard_delete_events.sql @@ -0,0 +1,22 @@ +-- SQLSpec Migration +-- Version: 20260807143052 +-- Description: add hard delete events +-- Created: 2026-08-07T14:30:52.000000+00:00 +-- Author: David Riegel <40246197+davidriegel@users.noreply.github.com> + +-- name: migrate-20260807143052-up + +CREATE EVENT IF NOT EXISTS delete_soft_deleted_clothing + ON SCHEDULE EVERY 1 DAY + DO DELETE FROM clothing + WHERE deleted_at IS NOT NULL AND deleted_at < NOW() - INTERVAL 7 DAY; + +CREATE EVENT IF NOT EXISTS delete_soft_deleted_outfits + ON SCHEDULE EVERY 1 DAY + DO DELETE FROM outfits + WHERE deleted_at IS NOT NULL AND deleted_at < NOW() - INTERVAL 7 DAY; + +-- name: migrate-20260807143052-down + +DROP EVENT IF EXISTS delete_soft_deleted_clothing; +DROP EVENT IF EXISTS delete_soft_deleted_outfits; diff --git a/migrations/README.md b/migrations/README.md index e31d8c4..7808247 100644 --- a/migrations/README.md +++ b/migrations/README.md @@ -56,3 +56,16 @@ The timestamp is automatically generated in UTC timezone. Migrations are applied in chronological order based on their timestamps. The database tracks both version and execution order separately to handle out-of-order migrations gracefully (e.g., from late-merging branches). + +## Scheduled Events + +`20260807143052_add_hard_delete_events.sql` purges soft-deleted clothing and +outfits after 7 days. Two things depend on that window: + +- The MySQL event scheduler must be on (`--event-scheduler=ON`, set in both + compose files). Without it the rows accumulate silently. +- The iOS client learns about deletions from `deleted` in the sync response, and + a purged row no longer appears there. It falls back to a full, authoritative + sync once its cursor is older than 7 days (`SyncManager.shouldPerformFullSync`), + which is what keeps the two in step. Shortening the window here without + shortening it there would leave clients with items the server has forgotten.