risingwave_meta_model/
secret.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 risingwave_pb::catalog::PbSecret;
16use sea_orm::ActiveValue::Set;
17use sea_orm::entity::prelude::*;
18use serde::{Deserialize, Serialize};
19
20use crate::SecretId;
21
22#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
23#[sea_orm(table_name = "secret")]
24pub struct Model {
25    #[sea_orm(primary_key, auto_increment = false)]
26    pub secret_id: SecretId,
27    pub name: String,
28    pub value: Vec<u8>,
29}
30
31#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
32pub enum Relation {
33    #[sea_orm(
34        belongs_to = "super::object::Entity",
35        from = "Column::SecretId",
36        to = "super::object::Column::Oid",
37        on_update = "NoAction",
38        on_delete = "Cascade"
39    )]
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<PbSecret> for ActiveModel {
52    fn from(secret: PbSecret) -> Self {
53        Self {
54            secret_id: Set(secret.id),
55            name: Set(secret.name),
56            value: Set(secret.value),
57        }
58    }
59}