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<String>,
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	/// The media info for this show
55	#[sea_orm(
56		belongs_to = "super::super::info::shows::Entity",
57		from = "Column::Id",
58		to = "super::super::info::shows::Column::Id",
59		on_update = "Cascade",
60		on_delete = "Cascade"
61	)]
62	MediaInfo,
63	/// The watched info for this show
64	#[sea_orm(
65		belongs_to = "super::super::watched::shows::Entity",
66		from = "Column::Id",
67		to = "super::super::watched::shows::Column::Id",
68		on_update = "Cascade",
69		on_delete = "Cascade"
70	)]
71	WatchInfo,
72}
73
74impl Related<super::collections::Entity> for Entity {
75	fn to() -> RelationDef {
76		Relation::Parent.def()
77	}
78}
79
80impl Related<super::libraries::Entity> for Entity {
81	fn to() -> RelationDef {
82		Relation::Library.def()
83	}
84}
85
86impl Related<super::super::info::shows::Entity> for Entity {
87	fn to() -> RelationDef {
88		Relation::MediaInfo.def()
89	}
90}
91
92impl Related<super::super::watched::shows::Entity> for Entity {
93	fn to() -> RelationDef {
94		Relation::WatchInfo.def()
95	}
96}