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: PathBytes,
29	/// The movie's poster path
30	pub relative_poster_path: Option<PathBytes>,
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}
57
58impl Related<super::collections::Entity> for Entity {
59	fn to() -> RelationDef {
60		Relation::Parent.def()
61	}
62}
63
64impl Related<super::libraries::Entity> for Entity {
65	fn to() -> RelationDef {
66		Relation::Library.def()
67	}
68}