risingwave_meta_model/
subscription.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_common::id::TableId;
16use risingwave_pb::catalog::PbSubscription;
17use sea_orm::ActiveValue::Set;
18use sea_orm::entity::prelude::*;
19use serde::{Deserialize, Serialize};
20
21use crate::SubscriptionId;
22
23#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
24#[sea_orm(table_name = "subscription")]
25pub struct Model {
26    #[sea_orm(primary_key, auto_increment = false)]
27    pub subscription_id: SubscriptionId,
28    pub name: String,
29    pub retention_seconds: i64,
30    pub definition: String,
31    pub subscription_state: i32,
32    pub dependent_table_id: TableId,
33}
34
35#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
36pub enum Relation {
37    #[sea_orm(
38        belongs_to = "super::object::Entity",
39        from = "Column::SubscriptionId",
40        to = "super::object::Column::Oid",
41        on_update = "NoAction",
42        on_delete = "Cascade"
43    )]
44    Object,
45}
46
47impl Related<super::object::Entity> for Entity {
48    fn to() -> RelationDef {
49        Relation::Object.def()
50    }
51}
52
53impl ActiveModelBehavior for ActiveModel {}
54
55impl From<PbSubscription> for ActiveModel {
56    fn from(pb_subscription: PbSubscription) -> Self {
57        Self {
58            subscription_id: Set(pb_subscription.id),
59            name: Set(pb_subscription.name),
60            retention_seconds: Set(pb_subscription.retention_seconds as _),
61            definition: Set(pb_subscription.definition),
62            subscription_state: Set(pb_subscription.subscription_state),
63            dependent_table_id: Set(pb_subscription.dependent_table_id),
64        }
65    }
66}