1use crate::db::{BufferId, ChannelId};
2use sea_orm::entity::prelude::*;
3
4#[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
5#[sea_orm(table_name = "buffers")]
6pub struct Model {
7 #[sea_orm(primary_key)]
8 pub id: BufferId,
9 pub epoch: i32,
10 pub channel_id: ChannelId,
11 pub latest_operation_epoch: Option<i32>,
12 pub latest_operation_lamport_timestamp: Option<i32>,
13 pub latest_operation_replica_id: Option<i32>,
14}
15
16#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
17pub enum Relation {
18 #[sea_orm(has_many = "super::buffer_operation::Entity")]
19 Operations,
20 #[sea_orm(has_many = "super::buffer_snapshot::Entity")]
21 Snapshots,
22 #[sea_orm(
23 belongs_to = "super::channel::Entity",
24 from = "Column::ChannelId",
25 to = "super::channel::Column::Id"
26 )]
27 Channel,
28}
29
30impl Related<super::buffer_operation::Entity> for Entity {
31 fn to() -> RelationDef {
32 Relation::Operations.def()
33 }
34}
35
36impl Related<super::buffer_snapshot::Entity> for Entity {
37 fn to() -> RelationDef {
38 Relation::Snapshots.def()
39 }
40}
41
42impl Related<super::channel::Entity> for Entity {
43 fn to() -> RelationDef {
44 Relation::Channel.def()
45 }
46}
47
48impl ActiveModelBehavior for ActiveModel {}