-- Add requester_id to calendar_events
ALTER TABLE if exists calendar_events
    ADD COLUMN IF NOT EXISTS requester_id uuid;

-- Copy created_by to requester_id for all current records
UPDATE calendar_events
    SET requester_id = created_by;

-- Add rbac data
insert into role_permissions (item, created_by, updated_by, role_id)
    select 'calendar:personal:*', u.id, u.id, r.id from users u, roles r where email = 'admin@jean-marie.ca' and r.name = 'normal';

insert into role_permissions (item, created_by, updated_by, role_id)
    select 'calendar:read:*', u.id, u.id, r.id from users u, roles r where email = 'admin@jean-marie.ca' and r.name = 'calendar';

insert into role_permissions (item, created_by, updated_by, role_id)
    select 'calendar:admin:*', u.id, u.id, r.id from users u, roles r where email = 'admin@jean-marie.ca' and r.name = 'admin';
