-- +mixmaker Up
ALTER TABLE discord_managed_roles DROP CONSTRAINT IF EXISTS discord_managed_roles_kind_check;
ALTER TABLE discord_managed_roles ADD CONSTRAINT discord_managed_roles_kind_check CHECK (
    kind IN ('tank', 'damage', 'support', 'team', 'captain', 'registered', 'going', 'maybe', 'not_going')
);

ALTER TABLE discord_role_sync_jobs DROP CONSTRAINT IF EXISTS discord_role_sync_jobs_action_check;
ALTER TABLE discord_role_sync_jobs ADD CONSTRAINT discord_role_sync_jobs_action_check CHECK (
    action IN ('reconcile', 'rsvp', 'teardown')
);

-- +mixmaker Down
DELETE FROM discord_role_assignments
WHERE discord_role_id IN (
    SELECT discord_role_id FROM discord_managed_roles
    WHERE kind IN ('registered', 'going', 'maybe', 'not_going')
);
DELETE FROM discord_managed_roles
WHERE kind IN ('registered', 'going', 'maybe', 'not_going');
DELETE FROM discord_role_sync_jobs WHERE action='rsvp';

ALTER TABLE discord_managed_roles DROP CONSTRAINT IF EXISTS discord_managed_roles_kind_check;
ALTER TABLE discord_managed_roles ADD CONSTRAINT discord_managed_roles_kind_check CHECK (
    kind IN ('tank', 'damage', 'support', 'team', 'captain')
);
ALTER TABLE discord_role_sync_jobs DROP CONSTRAINT IF EXISTS discord_role_sync_jobs_action_check;
ALTER TABLE discord_role_sync_jobs ADD CONSTRAINT discord_role_sync_jobs_action_check CHECK (
    action IN ('reconcile', 'teardown')
);
