flix_db/entity/content/
seasons.rs

1//! Season entity
2
3use flix_model::id::{LibraryId, ShowId};
4
5use seamantic::model::path::PathBytes;
6
7use flix_model::numbers::SeasonNumber;
8use sea_orm::{
9	ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
10	EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
11};
12
13/// The database representation of a season media folder
14#[derive(Debug, Clone, DeriveEntityModel)]
15#[sea_orm(table_name = "flix_seasons")]
16pub struct Model {
17	/// The season's show's ID
18	#[sea_orm(primary_key, auto_increment = false)]
19	pub show: ShowId,
20	/// The season's number
21	#[sea_orm(primary_key, auto_increment = false)]
22	pub season: SeasonNumber,
23	/// The season's slug
24	pub slug: String,
25	/// The season's library
26	pub library: LibraryId,
27	/// The season's directory
28	pub directory: PathBytes,
29	/// The season's poster path
30	pub relative_poster_path: Option<String>,
31}
32
33impl ActiveModelBehavior for ActiveModel {}
34
35/// Relation
36#[derive(Debug, EnumIter, DeriveRelation)]
37pub enum Relation {
38	/// The library this season belongs to
39	#[sea_orm(
40		belongs_to = "super::libraries::Entity",
41		from = "Column::Library",
42		to = "super::libraries::Column::Id",
43		on_update = "Cascade",
44		on_delete = "Cascade"
45	)]
46	Library,
47	/// The media info for this show
48	#[sea_orm(
49		belongs_to = "super::super::info::seasons::Entity",
50		from = "(Column::Show, Column::Season)",
51		to = "(super::super::info::seasons::Column::Show, super::super::info::seasons::Column::Season)",
52		on_update = "Cascade",
53		on_delete = "Cascade"
54	)]
55	MediaInfo,
56	/// The watched info for this show
57	#[sea_orm(
58		belongs_to = "super::super::watched::seasons::Entity",
59		from = "(Column::Show, Column::Season)",
60		to = "(super::super::watched::seasons::Column::Show, super::super::watched::seasons::Column::Season)",
61		on_update = "Cascade",
62		on_delete = "Cascade"
63	)]
64	WatchInfo,
65}
66
67impl Related<super::libraries::Entity> for Entity {
68	fn to() -> RelationDef {
69		Relation::Library.def()
70	}
71}
72
73impl Related<super::super::info::seasons::Entity> for Entity {
74	fn to() -> RelationDef {
75		Relation::MediaInfo.def()
76	}
77}
78
79impl Related<super::super::watched::seasons::Entity> for Entity {
80	fn to() -> RelationDef {
81		Relation::WatchInfo.def()
82	}
83}