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    /// PostgreSQL 17's table-maintenance privilege.
15    Maintain,
16}
17
18#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
19pub struct PrivilegeGrant {
20    pub on: ObjectId,               // table/schema/database the grant targets
21    pub privileges: Vec<Privilege>, // SELECT, INSERT, UPDATE, DELETE, ALL, etc.
22    pub grantee: ObjectId,          // the role receiving it
23    pub with_grant_option: bool,
24}
25
26#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
27pub struct RoleState {
28    pub id: ObjectId, // role name, no schema
29    pub can_login: bool,
30    pub is_superuser: bool,
31    pub member_of: Vec<ObjectId>, // roles this role is a member of
32    /// Roles this role may select with `SET ROLE`. PostgreSQL 16+ can grant
33    /// membership without the SET option, so this is deliberately distinct
34    /// from inherited membership.
35    pub can_set_role_to: Vec<ObjectId>,
36    pub granted_privileges: Vec<PrivilegeGrant>,
37}
38
39#[derive(Debug, Clone, PartialEq)]
40pub enum RoleOverlay {
41    Present(RoleState),
42    Dropped,
43}