safe-migrate 0.9.0

Check PostgreSQL migrations against a synchronized database baseline
Documentation
use crate::_internal::ast::identifiers::ObjectId;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub(crate) struct RoleState {
    pub id: ObjectId, // role name, no schema
    pub can_login: bool,
    pub is_superuser: bool,
    /// Whether memberships contribute privileges to this role on PostgreSQL
    /// 15 and earlier. PostgreSQL 16 made inheritance a property of each
    /// membership instead; keep this field because synchronized pre-16 caches
    /// still need the historical behavior.
    pub inherits: bool,
    pub member_of: Vec<ObjectId>, // roles this role is a member of
    /// Memberships for which this role has the PostgreSQL ADMIN option.
    pub can_administer_membership: Vec<ObjectId>,
    /// PostgreSQL 16+ memberships whose privileges this role inherits
    /// directly. For PostgreSQL 15 and earlier this contains every membership
    /// edge, while `inherits` decides whether those edges are effective.
    pub can_inherit_from: Vec<ObjectId>,
    /// Roles this role may select with `SET ROLE`. PostgreSQL 16+ can grant
    /// membership without the SET option, so this is deliberately distinct
    /// from inherited membership.
    pub can_set_role_to: Vec<ObjectId>,
}

/// PostgreSQL records the role that granted each membership alongside the
/// per-record options.  Keeping this provenance separate from the option
/// vectors lets revoke-CASCADE remove only memberships delegated by a
/// grantor whose authority was withdrawn.  PostgreSQL 16+ stores one row per
/// (member, role, grantor) triple, so several records may describe the same
/// edge with different grantors and option values.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub(crate) struct RoleMembershipGrantor {
    pub member: ObjectId,
    pub role: ObjectId,
    pub grantor: ObjectId,
    pub admin: bool,
    pub inherit: bool,
    pub set: bool,
}

#[derive(Debug, Clone, PartialEq)]
pub(crate) enum RoleOverlay {
    Present(RoleState),
    Dropped,
}