Updated name to be unique. Hopefully not a problem
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
use super::m20260317_000001_create_artists::Artists;
|
||||
use super::m20260317_000002_create_albums::Albums;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
// Drop the old non-unique index on artists.name
|
||||
manager
|
||||
.drop_index(
|
||||
Index::drop()
|
||||
.name("idx_artists_name")
|
||||
.table(Artists::Table)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Create a unique index on artists.name
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_artists_name_unique")
|
||||
.table(Artists::Table)
|
||||
.col(Artists::Name)
|
||||
.unique()
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Drop the old non-unique index on albums.name
|
||||
manager
|
||||
.drop_index(
|
||||
Index::drop()
|
||||
.name("idx_albums_name")
|
||||
.table(Albums::Table)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Create a unique composite index on albums(name, album_artist)
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_albums_name_artist_unique")
|
||||
.table(Albums::Table)
|
||||
.col(Albums::Name)
|
||||
.col(Albums::AlbumArtist)
|
||||
.unique()
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_index(
|
||||
Index::drop()
|
||||
.name("idx_albums_name_artist_unique")
|
||||
.table(Albums::Table)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_albums_name")
|
||||
.table(Albums::Table)
|
||||
.col(Albums::Name)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(
|
||||
Index::drop()
|
||||
.name("idx_artists_name_unique")
|
||||
.table(Artists::Table)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_artists_name")
|
||||
.table(Artists::Table)
|
||||
.col(Artists::Name)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ mod m20260317_000003_create_tracks;
|
||||
mod m20260317_000004_create_wanted_items;
|
||||
mod m20260317_000005_create_download_queue;
|
||||
mod m20260317_000006_create_search_cache;
|
||||
mod m20260317_000007_unique_artist_album;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
@@ -19,6 +20,7 @@ impl MigratorTrait for Migrator {
|
||||
Box::new(m20260317_000004_create_wanted_items::Migration),
|
||||
Box::new(m20260317_000005_create_download_queue::Migration),
|
||||
Box::new(m20260317_000006_create_search_cache::Migration),
|
||||
Box::new(m20260317_000007_unique_artist_album::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user