-- Create external calendar cache table for storing ICS data
CREATE TABLE external_calendar_cache (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    external_calendar_id INTEGER NOT NULL,
    ics_data TEXT NOT NULL,
    cached_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    etag TEXT,
    FOREIGN KEY (external_calendar_id) REFERENCES external_calendars(id) ON DELETE CASCADE,
    UNIQUE(external_calendar_id)
);

-- Index for faster lookups
CREATE INDEX idx_external_calendar_cache_calendar_id ON external_calendar_cache(external_calendar_id);
CREATE INDEX idx_external_calendar_cache_cached_at ON external_calendar_cache(cached_at);