Skip to content

Commit ddfe3f5

Browse files
authored
Feed the cloud membership mirror from login and member writes (#2004)
1 parent 89f4246 commit ddfe3f5

33 files changed

Lines changed: 5374 additions & 606 deletions
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- Backfill completeness per organization (`organizations.backfilled_at`: when
2+
-- its membership list was last fully scanned from WorkOS), the organization
3+
-- tombstone (`organizations.deleted_at`: kept by the local purge so a delayed
4+
-- login cannot re-mint a deleted organization), the organization name stamp
5+
-- (`organizations.workos_updated_at`: a name write stamped earlier is refused,
6+
-- so a delayed login cannot revert a rename), and on the "events" row of
7+
-- `workos_sync` the Events API replay boundary (`range_start`) the
8+
-- reconciler's first run reads from plus the backfill completion mark
9+
-- (`backfill_completed_at`) the authorization path checks before it trusts
10+
-- the mirror over WorkOS. A database with no organizations has nothing to
11+
-- backfill, so seed both there (fresh dev, test, and e2e databases); a
12+
-- database that already holds organizations gets them from the backfill
13+
-- script (scripts/backfill-workos-mirror.ts).
14+
ALTER TABLE "organizations" ADD COLUMN "backfilled_at" timestamp with time zone;--> statement-breakpoint
15+
ALTER TABLE "organizations" ADD COLUMN "deleted_at" timestamp with time zone;--> statement-breakpoint
16+
ALTER TABLE "organizations" ADD COLUMN "workos_updated_at" timestamp with time zone;--> statement-breakpoint
17+
ALTER TABLE "workos_sync" ADD COLUMN "range_start" timestamp with time zone;--> statement-breakpoint
18+
ALTER TABLE "workos_sync" ADD COLUMN "backfill_completed_at" timestamp with time zone;--> statement-breakpoint
19+
INSERT INTO "workos_sync" ("id", "cursor", "range_start", "backfill_completed_at", "updated_at")
20+
SELECT 'events', NULL, now(), now(), now()
21+
WHERE NOT EXISTS (SELECT 1 FROM "organizations");

0 commit comments

Comments
 (0)