flix_db/entity/content/
episodes.rs

1//! Episode entity
2
3use 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/// The database representation of a episode media folder
14#[derive(Debug, Clone, DeriveEntityModel)]
15#[sea_orm(table_name = "flix_episodes")]
16pub struct Model {
17	/// The episode's show's ID
18	#[sea_orm(primary_key, auto_increment = false)]
19	pub show: ShowId,
20	/// The episode's season's number
21	#[sea_orm(primary_key, auto_increment = false)]
22	pub season: SeasonNumber,
23	/// The episode's number
24	#[sea_orm(primary_key, auto_increment = false)]
25	pub episode: EpisodeNumber,
26	/// The episode's slug
27	pub slug: String,
28	/// The episode's library
29	pub library: LibraryId,
30	/// The episode's directory
31	pub directory: PathBytes,
32	/// The episode's media path
33	pub relative_media_path: PathBytes,
34	/// The episode's poster path
35	pub relative_poster_path: Option<PathBytes>,
36}
37
38impl ActiveModelBehavior for ActiveModel {}
39
40/// Relation
41#[derive(Debug, EnumIter, DeriveRelation)]
42pub enum Relation {
43	/// The library this episode belongs to
44	#[sea_orm(
45		belongs_to = "super::libraries::Entity",
46		from = "Column::Library",
47		to = "super::libraries::Column::Id",
48		on_update = "Cascade",
49		on_delete = "Cascade"
50	)]
51	Library,
52}
53
54impl Related<super::libraries::Entity> for Entity {
55	fn to() -> RelationDef {
56		Relation::Library.def()
57	}
58}