Skip to main content

max / makenotwork

717 B · 14 lines History Blame Raw
1 -- Backfill missing `sync_app_usage_current` rows (Run 21, HIGH availability).
2 --
3 -- Migration 117 seeded one usage row per app that existed at the time, but
4 -- nothing inserted a row for apps created afterward — `create_sync_app` only
5 -- wrote to `sync_apps`. Every billing/blob path locks the usage row with
6 -- `SELECT ... FOR UPDATE` and errors when it's absent, so every app created
7 -- between 117 and this migration 500s on its storage/billing surface.
8 --
9 -- `create_sync_app` now inserts the usage row transactionally on create; this
10 -- repairs the apps that slipped through in between. Idempotent.
11 INSERT INTO sync_app_usage_current (app_id)
12 SELECT id FROM sync_apps
13 ON CONFLICT (app_id) DO NOTHING;
14