Add scan date on libraries

This commit is contained in:
2025-11-08 21:14:37 -07:00
parent c5475585d4
commit b10cef4f2d
10 changed files with 446 additions and 79 deletions
Generated
+417 -58
View File
File diff suppressed because it is too large Load Diff
+6 -6
View File
@@ -35,12 +35,12 @@ overflow-checks = true
strip = "debuginfo" strip = "debuginfo"
[workspace.dependencies] [workspace.dependencies]
flix = { path = "crates/flix", version = "=0.0.13", default-features = false } flix = { path = "crates/flix", version = "=0.0.14", default-features = false }
flix-cli = { path = "crates/cli", version = "=0.0.13", default-features = false } flix-cli = { path = "crates/cli", version = "=0.0.14", default-features = false }
flix-db = { path = "crates/db", version = "=0.0.13", default-features = false } flix-db = { path = "crates/db", version = "=0.0.14", default-features = false }
flix-fs = { path = "crates/fs", version = "=0.0.13", default-features = false } flix-fs = { path = "crates/fs", version = "=0.0.14", default-features = false }
flix-model = { path = "crates/model", version = "=0.0.13", default-features = false } flix-model = { path = "crates/model", version = "=0.0.14", default-features = false }
flix-tmdb = { path = "crates/tmdb", version = "=0.0.13", default-features = false } flix-tmdb = { path = "crates/tmdb", version = "=0.0.14", default-features = false }
seamantic = { version = "0.0.10", default-features = false } seamantic = { version = "0.0.10", default-features = false }
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "flix-cli" name = "flix-cli"
version = "0.0.13" version = "0.0.14"
categories = ["command-line-utilities"] categories = ["command-line-utilities"]
description = "CLI for interacting with a flix database" description = "CLI for interacting with a flix database"
+9 -9
View File
@@ -49,7 +49,7 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
entity::tmdb::collections::ActiveModel { entity::tmdb::collections::ActiveModel {
tmdb_id: Set(id), tmdb_id: Set(id),
flix_id: Set(flix.id), flix_id: Set(flix.id),
last_update: Set(Utc::now().date_naive()), last_update: Set(Utc::now().naive_utc().date()),
movie_count: Set(collection.movies.len().try_into().unwrap_or(0)), movie_count: Set(collection.movies.len().try_into().unwrap_or(0)),
} }
.insert(txn) .insert(txn)
@@ -99,7 +99,7 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
entity::tmdb::movies::ActiveModel { entity::tmdb::movies::ActiveModel {
tmdb_id: Set(id), tmdb_id: Set(id),
flix_id: Set(flix.id), flix_id: Set(flix.id),
last_update: Set(Utc::now().date_naive()), last_update: Set(Utc::now().naive_utc().date()),
runtime: Set(movie.runtime.into()), runtime: Set(movie.runtime.into()),
collection_id: Set(movie.collection.map(|c| c.id)), collection_id: Set(movie.collection.map(|c| c.id)),
} }
@@ -144,7 +144,7 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
.with_context(|| { .with_context(|| {
format!("seasons().get_details({}, {})", id.into_raw(), season) format!("seasons().get_details({}, {})", id.into_raw(), season)
})?; })?;
if season.air_date > Utc::now().date_naive() { if season.air_date > Utc::now().naive_utc().date() {
eprintln!( eprintln!(
"skipping season ({}, {})", "skipping season ({}, {})",
id.into_raw(), id.into_raw(),
@@ -198,7 +198,7 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
entity::tmdb::shows::ActiveModel { entity::tmdb::shows::ActiveModel {
tmdb_id: Set(id), tmdb_id: Set(id),
flix_id: Set(flix.id), flix_id: Set(flix.id),
last_update: Set(Utc::now().date_naive()), last_update: Set(Utc::now().naive_utc().date()),
number_of_seasons: Set(show.number_of_seasons), number_of_seasons: Set(show.number_of_seasons),
} }
.insert(txn) .insert(txn)
@@ -220,7 +220,7 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
tmdb_season: Set(season.season_number), tmdb_season: Set(season.season_number),
flix_show: Set(flix.id), flix_show: Set(flix.id),
flix_season: Set(season.season_number), flix_season: Set(season.season_number),
last_update: Set(Utc::now().date_naive()), last_update: Set(Utc::now().naive_utc().date()),
} }
.insert(txn) .insert(txn)
.await?; .await?;
@@ -246,7 +246,7 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
flix_show: Set(flix.id), flix_show: Set(flix.id),
flix_season: Set(season), flix_season: Set(season),
flix_episode: Set(episode.episode_number), flix_episode: Set(episode.episode_number),
last_update: Set(Utc::now().date_naive()), last_update: Set(Utc::now().naive_utc().date()),
runtime: Set(episode.runtime.into()), runtime: Set(episode.runtime.into()),
} }
.insert(txn) .insert(txn)
@@ -338,7 +338,7 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
tmdb_season: Set(season_number), tmdb_season: Set(season_number),
flix_show: Set(show.flix_id), flix_show: Set(show.flix_id),
flix_season: Set(season_number), flix_season: Set(season_number),
last_update: Set(Utc::now().date_naive()), last_update: Set(Utc::now().naive_utc().date()),
} }
.insert(txn) .insert(txn)
.await?; .await?;
@@ -362,7 +362,7 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
flix_show: Set(show.flix_id), flix_show: Set(show.flix_id),
flix_season: Set(season_number), flix_season: Set(season_number),
flix_episode: Set(episode.episode_number), flix_episode: Set(episode.episode_number),
last_update: Set(Utc::now().date_naive()), last_update: Set(Utc::now().naive_utc().date()),
runtime: Set(episode.runtime.into()), runtime: Set(episode.runtime.into()),
} }
.insert(txn) .insert(txn)
@@ -453,7 +453,7 @@ pub async fn add(client: Client, db: &DatabaseConnection, command: Command) -> R
flix_show: Set(flix_id), flix_show: Set(flix_id),
flix_season: Set(season), flix_season: Set(season),
flix_episode: Set(episode_number), flix_episode: Set(episode_number),
last_update: Set(Utc::now().date_naive()), last_update: Set(Utc::now().naive_utc().date()),
runtime: Set(episode.runtime.into()), runtime: Set(episode.runtime.into()),
} }
.insert(txn) .insert(txn)
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "flix-db" name = "flix-db"
version = "0.0.13" version = "0.0.14"
categories = [] categories = []
description = "Types for storing persistent data about media" description = "Types for storing persistent data about media"
+8
View File
@@ -6,6 +6,7 @@ pub mod libraries {
use seamantic::model::path::PathBytes; use seamantic::model::path::PathBytes;
use chrono::NaiveDateTime;
use sea_orm::entity::prelude::*; use sea_orm::entity::prelude::*;
/// The database representation of a library media folder /// The database representation of a library media folder
@@ -18,6 +19,8 @@ pub mod libraries {
pub id: LibraryId, pub id: LibraryId,
/// The library's directory /// The library's directory
pub directory: PathBytes, pub directory: PathBytes,
/// The library's last scan data
pub last_scan: Option<NaiveDateTime>,
/// Collections that are part of this library /// Collections that are part of this library
#[sea_orm(has_many, on_update = "Cascade", on_delete = "Cascade")] #[sea_orm(has_many, on_update = "Cascade", on_delete = "Cascade")]
@@ -312,6 +315,7 @@ pub mod test {
$crate::entity::content::libraries::ActiveModel { $crate::entity::content::libraries::ActiveModel {
id: Set(::flix_model::id::LibraryId::from_raw($id)), id: Set(::flix_model::id::LibraryId::from_raw($id)),
directory: Set(::std::path::PathBuf::new().into()), directory: Set(::std::path::PathBuf::new().into()),
last_scan: Set(None),
} }
.insert($db) .insert($db)
.await .await
@@ -427,6 +431,7 @@ mod tests {
use flix_model::id::{CollectionId, LibraryId, MovieId, ShowId}; use flix_model::id::{CollectionId, LibraryId, MovieId, ShowId};
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
use sea_orm::ActiveValue::{NotSet, Set}; use sea_orm::ActiveValue::{NotSet, Set};
use sea_orm::entity::prelude::*; use sea_orm::entity::prelude::*;
use sea_orm::sqlx::error::ErrorKind; use sea_orm::sqlx::error::ErrorKind;
@@ -466,6 +471,7 @@ mod tests {
assert_eq!(model.id, LibraryId::from_raw($id)); assert_eq!(model.id, LibraryId::from_raw($id));
assert_eq!(model.directory, Path::new(concat!("L Directory ", $id)).to_owned().into()); assert_eq!(model.directory, Path::new(concat!("L Directory ", $id)).to_owned().into());
assert_eq!(model.last_scan, noneable!(last_scan, NaiveDateTime::new(NaiveDate::from_yo_opt($id, 1).expect("from_yo_opt"), NaiveTime::from_hms_opt(1, 1, 1).expect("from_yo_opt")) $(, $($skip),+)?));
}; };
($db:expr, $id:literal, $error:ident $(; $($skip:ident),+)?) => { ($db:expr, $id:literal, $error:ident $(; $($skip:ident),+)?) => {
let model = assert_library!(@insert, $db, $id $(; $($skip),+)?) let model = assert_library!(@insert, $db, $id $(; $($skip),+)?)
@@ -477,6 +483,7 @@ mod tests {
super::libraries::ActiveModel { super::libraries::ActiveModel {
id: notsettable!(id, LibraryId::from_raw($id) $(, $($skip),+)?), id: notsettable!(id, LibraryId::from_raw($id) $(, $($skip),+)?),
directory: notsettable!(directory, Path::new(concat!("L Directory ", $id)).to_owned().into() $(, $($skip),+)?), directory: notsettable!(directory, Path::new(concat!("L Directory ", $id)).to_owned().into() $(, $($skip),+)?),
last_scan: notsettable!(last_scan, Some(NaiveDateTime::new(NaiveDate::from_yo_opt($id, 1).expect("from_yo_opt"), NaiveTime::from_hms_opt(1, 1, 1).expect("from_yo_opt"))) $(, $($skip),+)?),
}.insert($db).await }.insert($db).await
}; };
} }
@@ -486,6 +493,7 @@ mod tests {
assert_library!(&db, 2, Success); assert_library!(&db, 2, Success);
assert_library!(&db, 3, Success; id); assert_library!(&db, 3, Success; id);
assert_library!(&db, 4, NotNullViolation; directory); assert_library!(&db, 4, NotNullViolation; directory);
assert_library!(&db, 5, Success; last_scan);
} }
#[tokio::test] #[tokio::test]
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "flix" name = "flix"
version = "0.0.13" version = "0.0.14"
categories = [] categories = []
description = "Mechanisms for interacting with flix media" description = "Mechanisms for interacting with flix media"
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "flix-fs" name = "flix-fs"
version = "0.0.13" version = "0.0.14"
categories = [] categories = []
description = "Filesystem scanner for flix media" description = "Filesystem scanner for flix media"
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "flix-model" name = "flix-model"
version = "0.0.13" version = "0.0.14"
categories = [] categories = []
description = "Core types for flix data" description = "Core types for flix data"
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "flix-tmdb" name = "flix-tmdb"
version = "0.0.13" version = "0.0.14"
categories = [] categories = []
description = "Clients and models for fetching data from TMDB" description = "Clients and models for fetching data from TMDB"