-
-
Notifications
You must be signed in to change notification settings - Fork 19
Log Background Sync #3135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Log Background Sync #3135
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7b7b34e
feat: add migration of workspace_calendar_sync_log relation
DennieDan 9cea4a2
feat: add logging for background
DennieDan f0b4fcb
fix: log gg email instead of token for security
DennieDan 2627fd8
feat: add tobe upserted and to be deleted events
DennieDan 5c158c4
chore: merge from main
DennieDan 070695c
Merge branch 'main' into feat/log-background-sync
vhpx e3d15bf
fix(db): remove redundant RLS permissions
vhpx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
apps/db/supabase/migrations/20250620134409_add_workspace_calendar_sync_log.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
-- Add workspace_calendar_sync_log table to track calendar sync operations | ||
|
||
-- Create workspace_calendar_sync_log table | ||
CREATE TABLE "public"."workspace_calendar_sync_log" ( | ||
"id" uuid NOT NULL DEFAULT uuid_generate_v4(), | ||
"ws_id" uuid NOT NULL REFERENCES "workspaces"("id") ON DELETE CASCADE, | ||
"google_account_email" text, | ||
"sync_started_at" timestamp with time zone NOT NULL, | ||
"sync_ended_at" timestamp with time zone, | ||
"status" text NOT NULL, | ||
"error_message" text, | ||
"event_snapshot_before" jsonb NOT NULL, | ||
"upserted_events" jsonb, | ||
"deleted_events" jsonb, | ||
"triggered_by" text NOT NULL, | ||
"created_at" timestamp with time zone NOT NULL DEFAULT now() | ||
); | ||
|
||
-- Enable Row Level Security | ||
ALTER TABLE "public"."workspace_calendar_sync_log" ENABLE ROW LEVEL SECURITY; | ||
|
||
-- Create primary key | ||
CREATE UNIQUE INDEX workspace_calendar_sync_log_pkey ON public.workspace_calendar_sync_log USING btree (id); | ||
ALTER TABLE "public"."workspace_calendar_sync_log" ADD CONSTRAINT "workspace_calendar_sync_log_pkey" PRIMARY KEY using index "workspace_calendar_sync_log_pkey"; | ||
|
||
-- Create indexes for better query performance | ||
CREATE INDEX workspace_calendar_sync_log_workspace_id_idx ON public.workspace_calendar_sync_log USING btree (ws_id); | ||
CREATE INDEX workspace_calendar_sync_log_status_idx ON public.workspace_calendar_sync_log USING btree (status); | ||
CREATE INDEX workspace_calendar_sync_log_sync_started_at_idx ON public.workspace_calendar_sync_log USING btree (sync_started_at); | ||
|
||
-- RLS Policies | ||
-- Users can see sync logs for workspaces they are members of | ||
CREATE POLICY "Users can view sync logs for their workspaces" | ||
ON public.workspace_calendar_sync_log | ||
FOR SELECT | ||
TO authenticated | ||
USING ( | ||
EXISTS ( | ||
SELECT 1 FROM public.workspace_members wm | ||
WHERE wm.ws_id = ws_id | ||
AND wm.user_id = auth.uid() | ||
) | ||
); | ||
|
||
-- Add check constraint for status values | ||
ALTER TABLE "public"."workspace_calendar_sync_log" | ||
ADD CONSTRAINT "workspace_calendar_sync_log_status_check" | ||
CHECK (status IN ('success', 'failed', 'in_progress', 'cancelled', 'partial_success')); | ||
|
||
-- Add check constraint for triggered_by values | ||
ALTER TABLE "public"."workspace_calendar_sync_log" | ||
ADD CONSTRAINT "workspace_calendar_sync_log_triggered_by_check" | ||
CHECK (triggered_by IN ('active_sync', 'trigger_dot_dev', 'manual')); | ||
|
||
-- Add check constraint to ensure sync_ended_at is after sync_started_at when both are present | ||
ALTER TABLE "public"."workspace_calendar_sync_log" | ||
ADD CONSTRAINT "workspace_calendar_sync_log_timestamps_check" | ||
CHECK (sync_ended_at IS NULL OR sync_ended_at >= sync_started_at); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.