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::*;
16use serde::{Deserialize, Serialize};
17
18use crate::object::ObjectType;
19use crate::user_privilege::Action;
20use crate::{DatabaseId, DefaultPrivilegeId, SchemaId, UserId};
21
22#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
23#[sea_orm(table_name = "user_default_privilege")]
24pub struct Model {
25    #[sea_orm(primary_key)]
26    pub id: DefaultPrivilegeId,
27    pub database_id: DatabaseId,
28    pub schema_id: Option<SchemaId>,
29    pub object_type: ObjectType,
30    pub for_materialized_view: bool,
31    pub user_id: UserId,
32    pub grantee: UserId,
33    pub granted_by: UserId,
34    pub action: Action,
35    pub with_grant_option: bool,
36}
37
38#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
39pub enum Relation {
40    #[sea_orm(
41        belongs_to = "super::database::Entity",
42        from = "Column::DatabaseId",
43        to = "super::database::Column::DatabaseId",
44        on_update = "NoAction",
45        on_delete = "Cascade"
46    )]
47    Database,
48    #[sea_orm(
49        belongs_to = "super::schema::Entity",
50        from = "Column::SchemaId",
51        to = "super::schema::Column::SchemaId",
52        on_update = "NoAction",
53        on_delete = "Cascade"
54    )]
55    Schema,
56    #[sea_orm(
57        belongs_to = "super::user::Entity",
58        from = "Column::UserId",
59        to = "super::user::Column::UserId",
60        on_update = "NoAction",
61        on_delete = "Cascade"
62    )]
63    User3,
64    #[sea_orm(
65        belongs_to = "super::user::Entity",
66        from = "Column::Grantee",
67        to = "super::user::Column::UserId",
68        on_update = "NoAction",
69        on_delete = "Cascade"
70    )]
71    User2,
72    #[sea_orm(
73        belongs_to = "super::user::Entity",
74        from = "Column::GrantedBy",
75        to = "super::user::Column::UserId",
76        on_update = "NoAction",
77        on_delete = "Cascade"
78    )]
79    User1,
80}
81
82impl Related<super::database::Entity> for Entity {
83    fn to() -> RelationDef {
84        Relation::Database.def()
85    }
86}
87
88impl Related<super::schema::Entity> for Entity {
89    fn to() -> RelationDef {
90        Relation::Schema.def()
91    }
92}
93
94impl ActiveModelBehavior for ActiveModel {}