risingwave_meta_model/
user.rs1use risingwave_pb::user::PbUserInfo;
16use sea_orm::ActiveValue::Set;
17use sea_orm::NotSet;
18use sea_orm::entity::prelude::*;
19use serde::{Deserialize, Serialize};
20
21use crate::{AuthInfo, UserId};
22
23#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
24#[sea_orm(table_name = "user")]
25pub struct Model {
26 #[sea_orm(primary_key)]
27 pub user_id: UserId,
28 #[sea_orm(unique)]
29 pub name: String,
30 pub is_super: bool,
31 pub can_create_db: bool,
32 pub can_create_user: bool,
33 pub can_login: bool,
34 pub auth_info: Option<AuthInfo>,
35}
36
37#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
38pub enum Relation {
39 #[sea_orm(has_many = "super::object::Entity")]
40 Object,
41}
42
43impl Related<super::object::Entity> for Entity {
44 fn to() -> RelationDef {
45 Relation::Object.def()
46 }
47}
48
49impl ActiveModelBehavior for ActiveModel {}
50
51impl From<PbUserInfo> for ActiveModel {
52 fn from(user: PbUserInfo) -> Self {
53 let user_id = if user.id == 0 {
54 NotSet
55 } else {
56 Set(user.id as _)
57 };
58 Self {
59 user_id,
60 name: Set(user.name),
61 is_super: Set(user.is_super),
62 can_create_db: Set(user.can_create_db),
63 can_create_user: Set(user.can_create_user),
64 can_login: Set(user.can_login),
65 auth_info: Set(user.auth_info.as_ref().map(AuthInfo::from)),
66 }
67 }
68}
69
70impl From<Model> for PbUserInfo {
71 fn from(val: Model) -> Self {
72 PbUserInfo {
73 id: val.user_id as _,
74 name: val.name,
75 is_super: val.is_super,
76 can_create_db: val.can_create_db,
77 can_create_user: val.can_create_user,
78 can_login: val.can_login,
79 auth_info: val.auth_info.map(|x| x.to_protobuf()),
80 grant_privileges: vec![], }
82 }
83}