risingwave_meta_model/
user_default_privilege.rs

1// Copyright 2025 RisingWave Labs
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use sea_orm::entity::prelude::*;
16
17use crate::object::ObjectType;
18use crate::user_privilege::Action;
19use crate::{DatabaseId, DefaultPrivilegeId, SchemaId, UserId};
20
21#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
22#[sea_orm(table_name = "user_default_privilege")]
23pub struct Model {
24    #[sea_orm(primary_key)]
25    pub id: DefaultPrivilegeId,
26    pub database_id: DatabaseId,
27    pub schema_id: Option<SchemaId>,
28    pub object_type: ObjectType,
29    pub for_materialized_view: bool,
30    pub user_id: UserId,
31    pub grantee: UserId,
32    pub granted_by: UserId,
33    pub action: Action,
34    pub with_grant_option: bool,
35}
36
37#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
38pub enum Relation {
39    #[sea_orm(
40        belongs_to = "super::database::Entity",
41        from = "Column::DatabaseId",
42        to = "super::database::Column::DatabaseId",
43        on_update = "NoAction",
44        on_delete = "Cascade"
45    )]
46    Database,
47    #[sea_orm(
48        belongs_to = "super::schema::Entity",
49        from = "Column::SchemaId",
50        to = "super::schema::Column::SchemaId",
51        on_update = "NoAction",
52        on_delete = "Cascade"
53    )]
54    Schema,
55    #[sea_orm(
56        belongs_to = "super::user::Entity",
57        from = "Column::UserId",
58        to = "super::user::Column::UserId",
59        on_update = "NoAction",
60        on_delete = "Cascade"
61    )]
62    User3,
63    #[sea_orm(
64        belongs_to = "super::user::Entity",
65        from = "Column::Grantee",
66        to = "super::user::Column::UserId",
67        on_update = "NoAction",
68        on_delete = "Cascade"
69    )]
70    User2,
71    #[sea_orm(
72        belongs_to = "super::user::Entity",
73        from = "Column::GrantedBy",
74        to = "super::user::Column::UserId",
75        on_update = "NoAction",
76        on_delete = "Cascade"
77    )]
78    User1,
79}
80
81impl Related<super::database::Entity> for Entity {
82    fn to() -> RelationDef {
83        Relation::Database.def()
84    }
85}
86
87impl Related<super::schema::Entity> for Entity {
88    fn to() -> RelationDef {
89        Relation::Schema.def()
90    }
91}
92
93impl ActiveModelBehavior for ActiveModel {}