From e76b2fc575fdf014d0abc249ddb9554dfa3a4689 Mon Sep 17 00:00:00 2001 From: Connor Johnstone Date: Mon, 23 Mar 2026 17:11:38 -0400 Subject: [PATCH] removed secondary artists --- ...20260323_000016_remove_orphaned_artists.rs | 25 +++++++++++++++++++ src/migration/mod.rs | 2 ++ 2 files changed, 27 insertions(+) create mode 100644 src/migration/m20260323_000016_remove_orphaned_artists.rs diff --git a/src/migration/m20260323_000016_remove_orphaned_artists.rs b/src/migration/m20260323_000016_remove_orphaned_artists.rs new file mode 100644 index 0000000..c16f4b1 --- /dev/null +++ b/src/migration/m20260323_000016_remove_orphaned_artists.rs @@ -0,0 +1,25 @@ +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> { + let conn = manager.get_connection(); + conn.execute_unprepared( + "DELETE FROM artists WHERE id NOT IN ( + SELECT DISTINCT artist_id FROM tracks WHERE artist_id IS NOT NULL + UNION SELECT DISTINCT artist_id FROM wanted_items WHERE artist_id IS NOT NULL + UNION SELECT DISTINCT artist_id FROM albums WHERE artist_id IS NOT NULL + )", + ) + .await?; + Ok(()) + } + + async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> { + // Orphaned artists cannot be restored + Ok(()) + } +} diff --git a/src/migration/mod.rs b/src/migration/mod.rs index 5ba9f6e..dcca8e5 100644 --- a/src/migration/mod.rs +++ b/src/migration/mod.rs @@ -14,6 +14,7 @@ mod m20260319_000012_add_user_id_to_wanted_items; mod m20260320_000013_add_artist_monitoring; mod m20260320_000014_create_playlists; mod m20260320_000015_add_subsonic_password; +mod m20260323_000016_remove_orphaned_artists; pub struct Migrator; @@ -35,6 +36,7 @@ impl MigratorTrait for Migrator { Box::new(m20260320_000013_add_artist_monitoring::Migration), Box::new(m20260320_000014_create_playlists::Migration), Box::new(m20260320_000015_add_subsonic_password::Migration), + Box::new(m20260323_000016_remove_orphaned_artists::Migration), ] } }