flix_db/entity/content/
episodes.rs1use flix_model::id::{LibraryId, ShowId};
4
5use seamantic::model::path::PathBytes;
6
7use flix_model::numbers::{EpisodeNumber, SeasonNumber};
8use sea_orm::{
9 ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
10 EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
11};
12
13#[derive(Debug, Clone, DeriveEntityModel)]
15#[sea_orm(table_name = "flix_episodes")]
16pub struct Model {
17 #[sea_orm(primary_key, auto_increment = false)]
19 pub show: ShowId,
20 #[sea_orm(primary_key, auto_increment = false)]
22 pub season: SeasonNumber,
23 #[sea_orm(primary_key, auto_increment = false)]
25 pub episode: EpisodeNumber,
26 pub count: u8,
28 pub slug: String,
30 pub library: LibraryId,
32 pub directory: PathBytes,
34 pub relative_media_path: String,
36 pub relative_poster_path: Option<String>,
38}
39
40impl ActiveModelBehavior for ActiveModel {}
41
42#[derive(Debug, EnumIter, DeriveRelation)]
44pub enum Relation {
45 #[sea_orm(
47 belongs_to = "super::libraries::Entity",
48 from = "Column::Library",
49 to = "super::libraries::Column::Id",
50 on_update = "Cascade",
51 on_delete = "Cascade"
52 )]
53 Library,
54 #[sea_orm(
56 belongs_to = "super::super::info::episodes::Entity",
57 from = "(Column::Show, Column::Season, Column::Episode)",
58 to = "(super::super::info::episodes::Column::Show, super::super::info::episodes::Column::Season, super::super::info::episodes::Column::Episode)",
59 on_update = "Cascade",
60 on_delete = "Cascade"
61 )]
62 MediaInfo,
63 #[sea_orm(
65 belongs_to = "super::super::watched::episodes::Entity",
66 from = "(Column::Show, Column::Season, Column::Episode)",
67 to = "(super::super::watched::episodes::Column::Show, super::super::watched::episodes::Column::Season, super::super::watched::episodes::Column::Episode)",
68 on_update = "Cascade",
69 on_delete = "Cascade"
70 )]
71 WatchInfo,
72}
73
74impl Related<super::libraries::Entity> for Entity {
75 fn to() -> RelationDef {
76 Relation::Library.def()
77 }
78}
79
80impl Related<super::super::info::episodes::Entity> for Entity {
81 fn to() -> RelationDef {
82 Relation::MediaInfo.def()
83 }
84}
85
86impl Related<super::super::watched::episodes::Entity> for Entity {
87 fn to() -> RelationDef {
88 Relation::WatchInfo.def()
89 }
90}