2023-10-09 18:49:57 +00:00
|
|
|
use sea_orm_migration::prelude::*;
|
|
|
|
|
|
|
|
|
|
use crate::{
|
2023-10-10 18:25:02 +00:00
|
|
|
m000002_create_music_folder::MusicFolder, m000003_create_cover_art::CoverArt,
|
|
|
|
|
m000004_create_artist::Artist,
|
2023-10-09 18:49:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#[derive(DeriveMigrationName)]
|
|
|
|
|
pub struct Migration;
|
|
|
|
|
|
|
|
|
|
#[async_trait::async_trait]
|
|
|
|
|
impl MigrationTrait for Migration {
|
|
|
|
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
|
|
|
manager
|
|
|
|
|
.create_table(
|
|
|
|
|
Table::create()
|
|
|
|
|
.table(Album::Table)
|
|
|
|
|
.if_not_exists()
|
|
|
|
|
.col(
|
|
|
|
|
ColumnDef::new(Album::Id)
|
|
|
|
|
.big_integer()
|
|
|
|
|
.not_null()
|
|
|
|
|
.auto_increment()
|
|
|
|
|
.primary_key(),
|
|
|
|
|
)
|
|
|
|
|
.col(ColumnDef::new(Album::Name).string().not_null())
|
|
|
|
|
.col(ColumnDef::new(Album::ArtistId).big_integer().null())
|
2023-10-09 19:24:32 +00:00
|
|
|
.col(ColumnDef::new(Album::CoverArtId).big_integer().null())
|
2023-10-09 18:49:57 +00:00
|
|
|
.col(ColumnDef::new(Album::SongCount).integer().not_null())
|
|
|
|
|
.col(ColumnDef::new(Album::Duration).big_integer().not_null())
|
|
|
|
|
.col(
|
|
|
|
|
ColumnDef::new(Album::PlayCount)
|
|
|
|
|
.big_integer()
|
|
|
|
|
.not_null()
|
|
|
|
|
.default(0),
|
|
|
|
|
)
|
|
|
|
|
.col(
|
|
|
|
|
ColumnDef::new(Album::Created)
|
|
|
|
|
.timestamp_with_time_zone()
|
|
|
|
|
.not_null(),
|
|
|
|
|
)
|
|
|
|
|
.col(
|
|
|
|
|
ColumnDef::new(Album::Starred)
|
|
|
|
|
.timestamp_with_time_zone()
|
|
|
|
|
.null(),
|
|
|
|
|
)
|
|
|
|
|
.col(ColumnDef::new(Album::Year).integer().null())
|
2023-10-10 18:25:02 +00:00
|
|
|
.col(
|
|
|
|
|
ColumnDef::new(Album::GenreIds)
|
|
|
|
|
.array(ColumnType::BigInteger)
|
|
|
|
|
.null(),
|
|
|
|
|
)
|
|
|
|
|
.col(
|
|
|
|
|
ColumnDef::new(Album::Played)
|
|
|
|
|
.timestamp_with_time_zone()
|
|
|
|
|
.not_null(),
|
|
|
|
|
)
|
|
|
|
|
.col(ColumnDef::new(Album::UserRating).tiny_integer().null())
|
|
|
|
|
.col(
|
|
|
|
|
ColumnDef::new(Album::ArtistIds)
|
|
|
|
|
.array(ColumnType::BigInteger)
|
|
|
|
|
.null(),
|
|
|
|
|
)
|
|
|
|
|
.col(
|
|
|
|
|
ColumnDef::new(Album::OriginalReleaseDate)
|
|
|
|
|
.timestamp_with_time_zone()
|
|
|
|
|
.null(),
|
|
|
|
|
)
|
|
|
|
|
.col(
|
|
|
|
|
ColumnDef::new(Album::MusicFolderId)
|
|
|
|
|
.big_integer()
|
|
|
|
|
.not_null(),
|
|
|
|
|
)
|
2023-10-09 18:49:57 +00:00
|
|
|
.to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
manager
|
|
|
|
|
.create_foreign_key(
|
|
|
|
|
ForeignKey::create()
|
|
|
|
|
.from_tbl(Album::Table)
|
|
|
|
|
.from_col(Album::MusicFolderId)
|
|
|
|
|
.to_tbl(MusicFolder::Table)
|
|
|
|
|
.to_col(MusicFolder::Id)
|
|
|
|
|
.on_delete(ForeignKeyAction::Cascade)
|
|
|
|
|
.to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
|
|
manager
|
|
|
|
|
.create_foreign_key(
|
|
|
|
|
ForeignKey::create()
|
|
|
|
|
.from_tbl(Album::Table)
|
|
|
|
|
.from_col(Album::ArtistId)
|
|
|
|
|
.to_tbl(Artist::Table)
|
|
|
|
|
.to_col(Artist::Id)
|
|
|
|
|
.on_delete(ForeignKeyAction::SetNull)
|
|
|
|
|
.to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.await?;
|
|
|
|
|
|
2023-10-09 19:24:32 +00:00
|
|
|
manager
|
|
|
|
|
.create_foreign_key(
|
|
|
|
|
ForeignKey::create()
|
|
|
|
|
.from_tbl(Album::Table)
|
|
|
|
|
.from_col(Album::CoverArtId)
|
|
|
|
|
.to_tbl(CoverArt::Table)
|
|
|
|
|
.to_col(CoverArt::Id)
|
|
|
|
|
.on_delete(ForeignKeyAction::SetNull)
|
|
|
|
|
.to_owned(),
|
|
|
|
|
)
|
|
|
|
|
.await?;
|
|
|
|
|
|
2023-10-09 18:49:57 +00:00
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
|
|
|
manager
|
|
|
|
|
.drop_table(Table::drop().table(Album::Table).to_owned())
|
|
|
|
|
.await
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(DeriveIden)]
|
|
|
|
|
pub enum Album {
|
|
|
|
|
Table,
|
|
|
|
|
Id,
|
|
|
|
|
Name,
|
|
|
|
|
ArtistId,
|
2023-10-09 19:24:32 +00:00
|
|
|
CoverArtId,
|
2023-10-09 18:49:57 +00:00
|
|
|
SongCount,
|
|
|
|
|
Duration,
|
|
|
|
|
PlayCount,
|
|
|
|
|
Created,
|
|
|
|
|
Starred,
|
|
|
|
|
Year,
|
2023-10-10 18:25:02 +00:00
|
|
|
GenreIds,
|
|
|
|
|
Played,
|
|
|
|
|
UserRating,
|
|
|
|
|
ArtistIds,
|
|
|
|
|
OriginalReleaseDate,
|
2023-10-09 18:49:57 +00:00
|
|
|
MusicFolderId,
|
|
|
|
|
}
|