flix_db/entity/content/
movies.rs

1//! Movie entity
2
3use flix_model::id::{CollectionId, LibraryId, MovieId};
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 movie media folder
13#[derive(Debug, Clone, DeriveEntityModel)]
14#[sea_orm(table_name = "flix_movies")]
15pub struct Model {
16	/// The movie's ID
17	#[sea_orm(primary_key, auto_increment = false)]
18	pub id: MovieId,
19	/// The movie's parent
20	pub parent: Option<CollectionId>,
21	/// The movie's slug
22	pub slug: String,
23	/// The movie's library
24	pub library: LibraryId,
25	/// The movie's directory
26	pub directory: PathBytes,
27	/// The movie's media path
28	pub relative_media_path: String,
29	/// The movie'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 parent collection of this collection
39	#[sea_orm(
40		belongs_to = "super::collections::Entity",
41		from = "Column::Parent",
42		to = "super::collections::Column::Id",
43		on_update = "Cascade",
44		on_delete = "Cascade"
45	)]
46	Parent,
47	/// The library this movie belongs to
48	#[sea_orm(
49		belongs_to = "super::libraries::Entity",
50		from = "Column::Library",
51		to = "super::libraries::Column::Id",
52		on_update = "Cascade",
53		on_delete = "Cascade"
54	)]
55	Library,
56	/// The media info for this movie
57	#[sea_orm(
58		belongs_to = "super::super::info::movies::Entity",
59		from = "Column::Id",
60		to = "super::super::info::movies::Column::Id",
61		on_update = "Cascade",
62		on_delete = "Cascade"
63	)]
64	MediaInfo,
65	/// The watched info for this movie
66	#[sea_orm(
67		belongs_to = "super::super::watched::movies::Entity",
68		from = "Column::Id",
69		to = "super::super::watched::movies::Column::Id",
70		on_update = "Cascade",
71		on_delete = "Cascade"
72	)]
73	WatchInfo,
74}
75
76impl Related<super::collections::Entity> for Entity {
77	fn to() -> RelationDef {
78		Relation::Parent.def()
79	}
80}
81
82impl Related<super::libraries::Entity> for Entity {
83	fn to() -> RelationDef {
84		Relation::Library.def()
85	}
86}
87
88impl Related<super::super::info::movies::Entity> for Entity {
89	fn to() -> RelationDef {
90		Relation::MediaInfo.def()
91	}
92}
93
94impl Related<super::super::watched::movies::Entity> for Entity {
95	fn to() -> RelationDef {
96		Relation::WatchInfo.def()
97	}
98}