use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct SequencePrivileges {
#[serde(default)]
pub select: bool,
#[serde(default)]
pub update: bool,
#[serde(default)]
pub usage: bool,
}
impl SequencePrivileges {
pub const ALL: Self = Self {
select: true,
update: true,
usage: true,
};
#[must_use]
pub const fn is_empty(self) -> bool {
!self.select && !self.update && !self.usage
}
#[must_use]
pub const fn intersects(self, other: Self) -> bool {
self.select && other.select || self.update && other.update || self.usage && other.usage
}
pub fn insert(&mut self, other: Self) {
self.select |= other.select;
self.update |= other.update;
self.usage |= other.usage;
}
pub fn remove(&mut self, other: Self) {
self.select &= !other.select;
self.update &= !other.update;
self.usage &= !other.usage;
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SequenceAclEntry {
pub role: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub grantor: Option<String>,
#[serde(default)]
pub privileges: SequencePrivileges,
#[serde(default)]
pub grant_options: SequencePrivileges,
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SequenceOwnerDependency {
#[default]
Automatic,
Internal,
}
impl SequenceOwnerDependency {
#[must_use]
pub const fn catalog_code(self) -> &'static str {
match self {
Self::Automatic => "a",
Self::Internal => "i",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct SequenceOwner {
pub table_object_id: [u8; 16],
pub column_object_id: [u8; 16],
#[serde(default)]
pub dependency: SequenceOwnerDependency,
}
#[cfg(test)]
mod tests;