CREATE TABLE calendar_subscriptions (
    id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
    tablo_id TEXT NOT NULL UNIQUE REFERENCES tablos(id) ON DELETE CASCADE,
    token TEXT NOT NULL UNIQUE,
    created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
);

-- Create index on token for fast lookups
CREATE INDEX idx_calendar_subscriptions_token ON calendar_subscriptions(token);

-- Note: Index on tablo_id is automatically created due to UNIQUE constraint

-- Enable Row Level Security
ALTER TABLE calendar_subscriptions ENABLE ROW LEVEL SECURITY;
