risingwave_meta_model/
subscription.rs1use 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}