-
Notifications
You must be signed in to change notification settings - Fork 43
Description
Hey team,
I'm building an offline-first app for event management and running into the NOW() limitation in sync rules. My use case is pretty straightforward, I only want to sync events from the last 7 days and next 30 days to mobile devices. Don't want years of old events bloating the local db.
Obviously can't do WHERE starts_at >= NOW() - INTERVAL '7 days' since sync rules need to be deterministic.
I've been looking at two approaches and wondering what you'd recommend:
Option A: Server-side boolean flag
Add a sync_active column and run a daily cron job that flips it based on event dates. Sync rule just does WHERE sync_active = true. Simple but feels hacky and creates unnecessary writes.
Option B: Client parameters with time buckets
Add a generated column like time_bucket_key (ISO week format), then use client params to request specific weeks:
parameters: |
SELECT value as bucket_id
FROM json_each(request.parameters() -> 'time_buckets')
data:
- SELECT * FROM events WHERE time_bucket_key = bucket.bucket_idClient calculates which weeks it needs and passes them on connect. Filter locally for the exact date range.
Is option B the recommended pattern here? Any gotchas I should know about?
Also curious if Sync Streams (saw it's in alpha) changes the calculus here at all. The TTL stuff looks interesting for this use case.
Thanks!