-- Rollback Phase 1 cleanup

-- ============================================
-- RECREATE: external_roles table
-- ============================================
CREATE TABLE external_roles (
    id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
    role_id uuid NOT NULL REFERENCES roles(id) ON DELETE CASCADE
);
CREATE UNIQUE INDEX external_roles_role_id_key ON external_roles(role_id);

-- ============================================
-- RENAME BACK: Tables to original names
-- ============================================
ALTER TABLE internal_role_details RENAME TO internal_roles;
ALTER TABLE role_admin_permissions RENAME TO role_permissions;
ALTER TABLE permission_definitions RENAME TO permissions;
ALTER TABLE role_sidebar_configs RENAME TO dashboard_configs;
ALTER TABLE role_runtime_configs RENAME TO runtime_configs;
ALTER TABLE user_role_assignments RENAME TO user_roles;
ALTER TABLE role_dashboard_widgets RENAME TO dashboard_widgets;
