Skip to main content

safe_migrate/model/
role.rs

1use crate::ast::identifiers::ObjectId;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5pub enum Privilege {
6    Select,
7    Insert,
8    Update,
9    Delete,
10    Truncate,
11    References,
12    Trigger,
13    All,
14}
15
16#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
17pub struct PrivilegeGrant {
18    pub on: ObjectId,               // table/schema/database the grant targets
19    pub privileges: Vec<Privilege>, // SELECT, INSERT, UPDATE, DELETE, ALL, etc.
20    pub grantee: ObjectId,          // the role receiving it
21    pub with_grant_option: bool,
22}
23
24#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
25pub struct RoleState {
26    pub id: ObjectId, // role name, no schema
27    pub can_login: bool,
28    pub is_superuser: bool,
29    pub member_of: Vec<ObjectId>, // roles this role is a member of
30    /// Roles this role may select with `SET ROLE`. PostgreSQL 16+ can grant
31    /// membership without the SET option, so this is deliberately distinct
32    /// from inherited membership.
33    pub can_set_role_to: Vec<ObjectId>,
34    pub granted_privileges: Vec<PrivilegeGrant>,
35}
36
37#[derive(Debug, Clone, PartialEq)]
38pub enum RoleOverlay {
39    Present(RoleState),
40    Dropped,
41}