73 lines
2.2 KiB
Rust
73 lines
2.2 KiB
Rust
use sea_orm_migration::prelude::*;
|
|
|
|
use crate::m000003_create_cover_art::CoverArt;
|
|
|
|
#[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(Artist::Table)
|
|
.if_not_exists()
|
|
.col(
|
|
ColumnDef::new(Artist::Id)
|
|
.big_integer()
|
|
.not_null()
|
|
.primary_key()
|
|
.auto_increment()
|
|
.unique_key(),
|
|
)
|
|
.col(ColumnDef::new(Artist::Name).string().not_null())
|
|
.col(ColumnDef::new(Artist::CoverArtId).big_integer().null())
|
|
.col(ColumnDef::new(Artist::ArtistImageUrl).string().null())
|
|
.col(
|
|
ColumnDef::new(Artist::AlbumCount)
|
|
.integer()
|
|
.not_null()
|
|
.default(0),
|
|
)
|
|
.col(
|
|
ColumnDef::new(Artist::Starred)
|
|
.timestamp_with_time_zone()
|
|
.null(),
|
|
)
|
|
.to_owned(),
|
|
)
|
|
.await?;
|
|
|
|
manager
|
|
.create_foreign_key(
|
|
ForeignKey::create()
|
|
.from_tbl(Artist::Table)
|
|
.from_col(Artist::CoverArtId)
|
|
.to_tbl(CoverArt::Table)
|
|
.to_col(CoverArt::Id)
|
|
.on_delete(ForeignKeyAction::SetNull)
|
|
.to_owned(),
|
|
)
|
|
.await?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
manager
|
|
.drop_table(Table::drop().table(Artist::Table).to_owned())
|
|
.await
|
|
}
|
|
}
|
|
|
|
#[derive(DeriveIden)]
|
|
pub enum Artist {
|
|
Table,
|
|
Id,
|
|
Name,
|
|
CoverArtId,
|
|
ArtistImageUrl,
|
|
AlbumCount,
|
|
Starred,
|
|
}
|