26 lines
827 B
Rust
26 lines
827 B
Rust
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(())
|
|
}
|
|
}
|