risingwave_meta_model/
subscription.rs1use risingwave_common::id::{JobId, 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: Option<i64>,
30 pub definition: String,
31 pub subscription_state: i32,
32 pub dependent_table_id: TableId,
33 pub cross_db_downstream_job_id: Option<JobId>,
34}
35
36#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
37pub enum Relation {
38 #[sea_orm(
39 belongs_to = "super::object::Entity",
40 from = "Column::SubscriptionId",
41 to = "super::object::Column::Oid",
42 on_update = "NoAction",
43 on_delete = "Cascade"
44 )]
45 Object,
46 #[sea_orm(
47 belongs_to = "super::object::Entity",
48 from = "Column::DependentTableId",
49 to = "super::object::Column::Oid",
50 on_update = "NoAction",
51 on_delete = "Cascade"
52 )]
53 DependentObject,
54}
55
56impl Related<super::object::Entity> for Entity {
57 fn to() -> RelationDef {
58 Relation::Object.def()
59 }
60}
61
62impl ActiveModelBehavior for ActiveModel {}
63
64impl From<PbSubscription> for ActiveModel {
65 fn from(pb_subscription: PbSubscription) -> Self {
66 Self {
67 subscription_id: Set(pb_subscription.id),
68 name: Set(pb_subscription.name),
69 retention_seconds: Set(pb_subscription.retention_seconds.map(|v| v as _)),
70 definition: Set(pb_subscription.definition),
71 subscription_state: Set(pb_subscription.subscription_state),
72 dependent_table_id: Set(pb_subscription.dependent_table_id),
73 cross_db_downstream_job_id: Set(pb_subscription.cross_db_downstream_job_id),
74 }
75 }
76}