Updates for the "full flow"
This commit is contained in:
@@ -37,6 +37,9 @@ pub struct Model {
|
|||||||
pub album_id: Option<i32>,
|
pub album_id: Option<i32>,
|
||||||
#[sea_orm(nullable)]
|
#[sea_orm(nullable)]
|
||||||
pub track_id: Option<i32>,
|
pub track_id: Option<i32>,
|
||||||
|
pub name: String,
|
||||||
|
#[sea_orm(nullable)]
|
||||||
|
pub musicbrainz_id: Option<String>,
|
||||||
pub status: WantedStatus,
|
pub status: WantedStatus,
|
||||||
pub added_at: chrono::NaiveDateTime,
|
pub added_at: chrono::NaiveDateTime,
|
||||||
pub updated_at: chrono::NaiveDateTime,
|
pub updated_at: chrono::NaiveDateTime,
|
||||||
|
|||||||
40
src/migration/m20260317_000009_add_wanted_name.rs
Normal file
40
src/migration/m20260317_000009_add_wanted_name.rs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
use sea_orm_migration::prelude::*;
|
||||||
|
|
||||||
|
#[derive(DeriveMigrationName)]
|
||||||
|
pub struct Migration;
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl MigrationTrait for Migration {
|
||||||
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
manager
|
||||||
|
.alter_table(
|
||||||
|
Table::alter()
|
||||||
|
.table(WantedItems::Table)
|
||||||
|
.add_column(
|
||||||
|
ColumnDef::new(WantedItems::Name)
|
||||||
|
.text()
|
||||||
|
.not_null()
|
||||||
|
.default(""),
|
||||||
|
)
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
manager
|
||||||
|
.alter_table(
|
||||||
|
Table::alter()
|
||||||
|
.table(WantedItems::Table)
|
||||||
|
.drop_column(WantedItems::Name)
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(DeriveIden)]
|
||||||
|
enum WantedItems {
|
||||||
|
Table,
|
||||||
|
Name,
|
||||||
|
}
|
||||||
35
src/migration/m20260317_000010_add_wanted_mbid.rs
Normal file
35
src/migration/m20260317_000010_add_wanted_mbid.rs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
use sea_orm_migration::prelude::*;
|
||||||
|
|
||||||
|
#[derive(DeriveMigrationName)]
|
||||||
|
pub struct Migration;
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
impl MigrationTrait for Migration {
|
||||||
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
manager
|
||||||
|
.alter_table(
|
||||||
|
Table::alter()
|
||||||
|
.table(WantedItems::Table)
|
||||||
|
.add_column(ColumnDef::new(WantedItems::MusicbrainzId).text())
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
manager
|
||||||
|
.alter_table(
|
||||||
|
Table::alter()
|
||||||
|
.table(WantedItems::Table)
|
||||||
|
.drop_column(WantedItems::MusicbrainzId)
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(DeriveIden)]
|
||||||
|
enum WantedItems {
|
||||||
|
Table,
|
||||||
|
MusicbrainzId,
|
||||||
|
}
|
||||||
@@ -7,6 +7,8 @@ mod m20260317_000004_create_wanted_items;
|
|||||||
mod m20260317_000005_create_download_queue;
|
mod m20260317_000005_create_download_queue;
|
||||||
mod m20260317_000006_create_search_cache;
|
mod m20260317_000006_create_search_cache;
|
||||||
mod m20260317_000007_unique_artist_album;
|
mod m20260317_000007_unique_artist_album;
|
||||||
|
mod m20260317_000009_add_wanted_name;
|
||||||
|
mod m20260317_000010_add_wanted_mbid;
|
||||||
|
|
||||||
pub struct Migrator;
|
pub struct Migrator;
|
||||||
|
|
||||||
@@ -21,6 +23,8 @@ impl MigratorTrait for Migrator {
|
|||||||
Box::new(m20260317_000005_create_download_queue::Migration),
|
Box::new(m20260317_000005_create_download_queue::Migration),
|
||||||
Box::new(m20260317_000006_create_search_cache::Migration),
|
Box::new(m20260317_000006_create_search_cache::Migration),
|
||||||
Box::new(m20260317_000007_unique_artist_album::Migration),
|
Box::new(m20260317_000007_unique_artist_album::Migration),
|
||||||
|
Box::new(m20260317_000009_add_wanted_name::Migration),
|
||||||
|
Box::new(m20260317_000010_add_wanted_mbid::Migration),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,16 @@ pub async fn list(
|
|||||||
.await?)
|
.await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn find_by_wanted_item_id(
|
||||||
|
db: &DatabaseConnection,
|
||||||
|
wanted_item_id: i32,
|
||||||
|
) -> DbResult<Option<DownloadQueueItem>> {
|
||||||
|
Ok(DownloadQueue::find()
|
||||||
|
.filter(download_queue::Column::WantedItemId.eq(wanted_item_id))
|
||||||
|
.one(db)
|
||||||
|
.await?)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn retry_failed(db: &DatabaseConnection, id: i32) -> DbResult<()> {
|
pub async fn retry_failed(db: &DatabaseConnection, id: i32) -> DbResult<()> {
|
||||||
let item = DownloadQueue::find_by_id(id)
|
let item = DownloadQueue::find_by_id(id)
|
||||||
.one(db)
|
.one(db)
|
||||||
|
|||||||
@@ -93,6 +93,19 @@ pub async fn get_untagged(db: &DatabaseConnection) -> DbResult<Vec<Track>> {
|
|||||||
.await?)
|
.await?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get tracks that need metadata enrichment — either no MBID at all,
|
||||||
|
/// or have an MBID but are missing album info (e.g., freshly downloaded).
|
||||||
|
pub async fn get_needing_metadata(db: &DatabaseConnection) -> DbResult<Vec<Track>> {
|
||||||
|
Ok(Tracks::find()
|
||||||
|
.filter(
|
||||||
|
Condition::any()
|
||||||
|
.add(track::Column::MusicbrainzId.is_null())
|
||||||
|
.add(track::Column::AlbumId.is_null()),
|
||||||
|
)
|
||||||
|
.all(db)
|
||||||
|
.await?)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn update_metadata(db: &DatabaseConnection, id: i32, model: ActiveModel) -> DbResult<Track> {
|
pub async fn update_metadata(db: &DatabaseConnection, id: i32, model: ActiveModel) -> DbResult<Track> {
|
||||||
let mut active = model;
|
let mut active = model;
|
||||||
active.id = Set(id);
|
active.id = Set(id);
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ use crate::error::{DbError, DbResult};
|
|||||||
pub async fn add(
|
pub async fn add(
|
||||||
db: &DatabaseConnection,
|
db: &DatabaseConnection,
|
||||||
item_type: ItemType,
|
item_type: ItemType,
|
||||||
|
name: &str,
|
||||||
|
musicbrainz_id: Option<&str>,
|
||||||
artist_id: Option<i32>,
|
artist_id: Option<i32>,
|
||||||
album_id: Option<i32>,
|
album_id: Option<i32>,
|
||||||
track_id: Option<i32>,
|
track_id: Option<i32>,
|
||||||
@@ -16,6 +18,8 @@ pub async fn add(
|
|||||||
let now = Utc::now().naive_utc();
|
let now = Utc::now().naive_utc();
|
||||||
let active = ActiveModel {
|
let active = ActiveModel {
|
||||||
item_type: Set(item_type),
|
item_type: Set(item_type),
|
||||||
|
name: Set(name.to_string()),
|
||||||
|
musicbrainz_id: Set(musicbrainz_id.map(String::from)),
|
||||||
artist_id: Set(artist_id),
|
artist_id: Set(artist_id),
|
||||||
album_id: Set(album_id),
|
album_id: Set(album_id),
|
||||||
track_id: Set(track_id),
|
track_id: Set(track_id),
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ async fn test_wanted_items_lifecycle() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Add wanted item
|
// Add wanted item
|
||||||
let item = queries::wanted::add(conn, ItemType::Artist, Some(artist.id), None, None)
|
let item = queries::wanted::add(conn, ItemType::Artist, "Radiohead", None, Some(artist.id), None, None)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(item.status, WantedStatus::Wanted);
|
assert_eq!(item.status, WantedStatus::Wanted);
|
||||||
|
|||||||
Reference in New Issue
Block a user