flix_db/entity/content/
shows.rs

1//! Show entity
2
3use flix_model::id::{CollectionId, LibraryId, ShowId};
4
5use seamantic::model::path::PathBytes;
6
7use sea_orm::{
8	ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
9	EnumIter, PrimaryKeyTrait, Related, RelationDef, RelationTrait,
10};
11
12/// The database representation of a show media folder
13#[derive(Debug, Clone, DeriveEntityModel)]
14#[sea_orm(table_name = "flix_shows")]
15pub struct Model {
16	/// The show's ID
17	#[sea_orm(primary_key, auto_increment = false)]
18	pub id: ShowId,
19	/// The show's parent
20	pub parent: Option<CollectionId>,
21	/// The show's slug
22	pub slug: String,
23	/// The show's library
24	pub library: LibraryId,
25	/// The show's directory
26	pub directory: PathBytes,
27	/// The show's poster path
28	pub relative_poster_path: Option<PathBytes>,
29}
30
31impl ActiveModelBehavior for ActiveModel {}
32
33/// Relation
34#[derive(Debug, EnumIter, DeriveRelation)]
35pub enum Relation {
36	/// The parent collection of this collection
37	#[sea_orm(
38		belongs_to = "super::collections::Entity",
39		from = "Column::Parent",
40		to = "super::collections::Column::Id",
41		on_update = "Cascade",
42		on_delete = "Cascade"
43	)]
44	Parent,
45	/// The library this show belongs to
46	#[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}
55
56impl Related<super::collections::Entity> for Entity {
57	fn to() -> RelationDef {
58		Relation::Parent.def()
59	}
60}
61
62impl Related<super::libraries::Entity> for Entity {
63	fn to() -> RelationDef {
64		Relation::Library.def()
65	}
66}