Files
MealQuest/migrations/0015_google_reconnect_required.sql
T
dev_agentandClaude Opus 5.5 1c8092800a
CI / ci (push) Successful in 4m29s
CI / ci (pull_request) Successful in 4m21s
Handle Google token failures and report Google Calendar status
When Google refuses the stored grant (invalid_grant on refresh, or HTTP
401 from the Calendar API to the access token just refreshed) on any
Calendar call - listing, choosing or pushing - the connection becomes
reconnect required under the account lock: the refresh token is cleared
and last_sync_error set to "Google access was revoked or expired —
reconnect". The call answers 409 google_reconnect_required, and later
calls answer the same without contacting Google until a reconnect or a
disconnect. The chosen calendar and stored calendar event ids are kept:
the pushed events are still on that calendar, so forgetEvents is not
run.

HTTP 429 and 5xx from the token endpoint or the Calendar API are retried
at most twice with backoff, then answered 503 google_unavailable,
retryable, without clearing or disconnecting anything.

Add GET /api/v1/integrations/google, reporting not_connected, connected
or reconnect_required with the chosen calendar and last_sync_error.

Migration 0015 rebuilds integrations_google so refresh_token_ct can be
cleared, with a CHECK that a row without a token carries the reason.

Maestro task b8d8da5a-0450-4571-963e-b3dfead24283.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 23:41:50 -04:00

32 lines
1.2 KiB
SQL

-- 0015_google_reconnect_required: when Google refuses the stored grant
-- (invalid_grant on refresh, or HTTP 401 from the Calendar API) the
-- connection is kept as reconnect required: its refresh token is cleared
-- and last_sync_error says why. SQLite cannot drop a NOT NULL constraint,
-- so the table is rebuilt with refresh_token_ct nullable. A row without a
-- refresh token always carries the reason. No table references
-- integrations_google.
CREATE TABLE integrations_google_new (
id INTEGER PRIMARY KEY CHECK (id = 1),
refresh_token_ct BLOB,
calendar_id TEXT,
calendar_name TEXT,
connected_at TEXT NOT NULL,
last_sync_error TEXT,
created_at TEXT NOT NULL,
updated_at TEXT NOT NULL,
CHECK (refresh_token_ct IS NOT NULL OR last_sync_error IS NOT NULL)
);
INSERT INTO integrations_google_new (
id, refresh_token_ct, calendar_id, calendar_name, connected_at,
last_sync_error, created_at, updated_at
)
SELECT id, refresh_token_ct, calendar_id, calendar_name, connected_at,
last_sync_error, created_at, updated_at
FROM integrations_google;
DROP TABLE integrations_google;
ALTER TABLE integrations_google_new RENAME TO integrations_google;