145 lines
4.8 KiB
Rust
145 lines
4.8 KiB
Rust
use sea_orm_migration::prelude::*;
|
|
|
|
use crate::{
|
|
m000003_create_cover_art::CoverArt, m000004_create_artist::Artist, m000006_create_album::Album,
|
|
};
|
|
|
|
#[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(Track::Table)
|
|
.if_not_exists()
|
|
.col(
|
|
ColumnDef::new(Track::Id)
|
|
.big_integer()
|
|
.not_null()
|
|
.auto_increment()
|
|
.primary_key()
|
|
.unique_key(),
|
|
)
|
|
.col(ColumnDef::new(Track::Title).string().not_null())
|
|
.col(ColumnDef::new(Track::AlbumId).big_integer().null())
|
|
.col(ColumnDef::new(Track::ArtistId).big_integer().null())
|
|
.col(
|
|
ColumnDef::new(Track::IsDir)
|
|
.boolean()
|
|
.not_null()
|
|
.default(false),
|
|
)
|
|
.col(ColumnDef::new(Track::CoverArtId).big_integer().null())
|
|
.col(
|
|
ColumnDef::new(Track::Created)
|
|
.timestamp_with_time_zone()
|
|
.not_null(),
|
|
)
|
|
.col(
|
|
ColumnDef::new(Track::Starred)
|
|
.timestamp_with_time_zone()
|
|
.null(),
|
|
)
|
|
.col(ColumnDef::new(Track::Duration).big_integer().not_null())
|
|
.col(ColumnDef::new(Track::BitRate).big_integer().null())
|
|
.col(ColumnDef::new(Track::TrackNumber).integer().null())
|
|
.col(ColumnDef::new(Track::Size).big_integer().not_null())
|
|
.col(
|
|
ColumnDef::new(Track::PlayCount)
|
|
.big_integer()
|
|
.not_null()
|
|
.default(0),
|
|
)
|
|
.col(
|
|
ColumnDef::new(Track::DiscNumber)
|
|
.integer()
|
|
.not_null()
|
|
.default(1),
|
|
)
|
|
.col(ColumnDef::new(Track::Suffix).string().not_null())
|
|
.col(ColumnDef::new(Track::ContentType).string().not_null())
|
|
.col(
|
|
ColumnDef::new(Track::IsVideo)
|
|
.boolean()
|
|
.not_null()
|
|
.default(false),
|
|
)
|
|
.col(ColumnDef::new(Track::Path).string().not_null())
|
|
.to_owned(),
|
|
)
|
|
.await?;
|
|
|
|
manager
|
|
.create_foreign_key(
|
|
ForeignKey::create()
|
|
.from_tbl(Track::Table)
|
|
.from_col(Track::AlbumId)
|
|
.to_tbl(Album::Table)
|
|
.to_col(Album::Id)
|
|
.on_delete(ForeignKeyAction::Cascade)
|
|
.on_update(ForeignKeyAction::Cascade)
|
|
.to_owned(),
|
|
)
|
|
.await?;
|
|
|
|
manager
|
|
.create_foreign_key(
|
|
ForeignKey::create()
|
|
.from_tbl(Track::Table)
|
|
.from_col(Track::ArtistId)
|
|
.to_tbl(Artist::Table)
|
|
.to_col(Artist::Id)
|
|
.on_delete(ForeignKeyAction::Cascade)
|
|
.on_update(ForeignKeyAction::Cascade)
|
|
.to_owned(),
|
|
)
|
|
.await?;
|
|
|
|
manager
|
|
.create_foreign_key(
|
|
ForeignKey::create()
|
|
.from_tbl(Track::Table)
|
|
.from_col(Track::CoverArtId)
|
|
.to_tbl(CoverArt::Table)
|
|
.to_col(CoverArt::Id)
|
|
.on_delete(ForeignKeyAction::Cascade)
|
|
.on_update(ForeignKeyAction::Cascade)
|
|
.to_owned(),
|
|
)
|
|
.await?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
manager
|
|
.drop_table(Table::drop().table(Track::Table).to_owned())
|
|
.await
|
|
}
|
|
}
|
|
|
|
#[derive(DeriveIden)]
|
|
pub enum Track {
|
|
Table,
|
|
Id,
|
|
Title,
|
|
AlbumId,
|
|
ArtistId,
|
|
IsDir,
|
|
TrackNumber,
|
|
CoverArtId,
|
|
Created,
|
|
Starred,
|
|
PlayCount,
|
|
DiscNumber,
|
|
Duration,
|
|
BitRate,
|
|
Size,
|
|
Suffix,
|
|
ContentType,
|
|
IsVideo,
|
|
Path,
|
|
}
|