-- Unique index on public_token for fast lookups of public iCal feeds CREATE UNIQUE INDEX idx_calendars_public_token ON calendars (public_token) WHERE public_token IS NOT NULL; -- Track calendars imported from external iCal URLs CREATE TABLE calendar_subscriptions ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), calendar_id UUID NOT NULL REFERENCES calendars(id), source_url TEXT NOT NULL, last_synced_at TIMESTAMPTZ, created_at TIMESTAMPTZ NOT NULL DEFAULT now() ); CREATE INDEX idx_calendar_subscriptions_calendar_id ON calendar_subscriptions (calendar_id);