Updates for the "full flow"

This commit is contained in:
Connor Johnstone
2026-03-17 21:38:11 -04:00
parent e1b682b048
commit 9e1886b45a
8 changed files with 110 additions and 1 deletions

View File

@@ -37,6 +37,9 @@ pub struct Model {
pub album_id: Option<i32>,
#[sea_orm(nullable)]
pub track_id: Option<i32>,
pub name: String,
#[sea_orm(nullable)]
pub musicbrainz_id: Option<String>,
pub status: WantedStatus,
pub added_at: chrono::NaiveDateTime,
pub updated_at: chrono::NaiveDateTime,

View 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,
}

View 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,
}

View File

@@ -7,6 +7,8 @@ mod m20260317_000004_create_wanted_items;
mod m20260317_000005_create_download_queue;
mod m20260317_000006_create_search_cache;
mod m20260317_000007_unique_artist_album;
mod m20260317_000009_add_wanted_name;
mod m20260317_000010_add_wanted_mbid;
pub struct Migrator;
@@ -21,6 +23,8 @@ impl MigratorTrait for Migrator {
Box::new(m20260317_000005_create_download_queue::Migration),
Box::new(m20260317_000006_create_search_cache::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),
]
}
}

View File

@@ -68,6 +68,16 @@ pub async fn list(
.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<()> {
let item = DownloadQueue::find_by_id(id)
.one(db)

View File

@@ -93,6 +93,19 @@ pub async fn get_untagged(db: &DatabaseConnection) -> DbResult<Vec<Track>> {
.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> {
let mut active = model;
active.id = Set(id);

View File

@@ -9,6 +9,8 @@ use crate::error::{DbError, DbResult};
pub async fn add(
db: &DatabaseConnection,
item_type: ItemType,
name: &str,
musicbrainz_id: Option<&str>,
artist_id: Option<i32>,
album_id: Option<i32>,
track_id: Option<i32>,
@@ -16,6 +18,8 @@ pub async fn add(
let now = Utc::now().naive_utc();
let active = ActiveModel {
item_type: Set(item_type),
name: Set(name.to_string()),
musicbrainz_id: Set(musicbrainz_id.map(String::from)),
artist_id: Set(artist_id),
album_id: Set(album_id),
track_id: Set(track_id),