199 lines
7.1 KiB
Rust
199 lines
7.1 KiB
Rust
use sea_orm_migration::{prelude::*, schema::*};
|
|
use crate::extension::postgres::Type;
|
|
|
|
#[derive(DeriveMigrationName)]
|
|
pub struct Migration;
|
|
|
|
#[async_trait::async_trait]
|
|
impl MigrationTrait for Migration {
|
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
manager
|
|
.create_type(
|
|
Type::create()
|
|
.as_enum(Alias::new("mode"))
|
|
.values([Alias::new("std"),Alias::new("taiko"),Alias::new("ctb"),Alias::new("mania")])
|
|
.to_owned(),
|
|
)
|
|
.await?;
|
|
manager
|
|
.create_type(
|
|
Type::create()
|
|
.as_enum(Alias::new("category"))
|
|
.values([Alias::new("qua"),Alias::new("ro16"),Alias::new("qf"),Alias::new("sf"),Alias::new("f"),Alias::new("gf")])
|
|
.to_owned(),
|
|
)
|
|
.await?;
|
|
manager
|
|
.create_table(
|
|
Table::create()
|
|
.table(MapSelections::Table)
|
|
.if_not_exists()
|
|
.col(
|
|
ColumnDef::new(MapSelections::Id)
|
|
.integer()
|
|
.not_null()
|
|
.auto_increment()
|
|
.primary_key(),
|
|
)
|
|
.col(
|
|
ColumnDef::new(MapSelections::BeatmapId)
|
|
.integer()
|
|
.not_null(),
|
|
)
|
|
.col(
|
|
ColumnDef::new(MapSelections::BeatmapSetId)
|
|
.integer()
|
|
.not_null(),
|
|
)
|
|
.col(ColumnDef::new(MapSelections::Title).string().null())
|
|
.col(ColumnDef::new(MapSelections::TitleUnicode).string().null())
|
|
.col(ColumnDef::new(MapSelections::Artist).string().null())
|
|
.col(ColumnDef::new(MapSelections::ArtistUnicode).string().null())
|
|
.col(ColumnDef::new(MapSelections::Version).string().null())
|
|
.col(ColumnDef::new(MapSelections::Creator).string().null())
|
|
.col(ColumnDef::new(MapSelections::StarRating).decimal().null())
|
|
.col(ColumnDef::new(MapSelections::Bpm).decimal().null())
|
|
.col(ColumnDef::new(MapSelections::TotalLength).integer().null())
|
|
.col(ColumnDef::new(MapSelections::MaxCombo).integer().null())
|
|
.col(ColumnDef::new(MapSelections::Ar).decimal().null())
|
|
.col(ColumnDef::new(MapSelections::Cs).decimal().null())
|
|
.col(ColumnDef::new(MapSelections::Od).decimal().null())
|
|
.col(ColumnDef::new(MapSelections::Hp).decimal().null())
|
|
.col(
|
|
ColumnDef::new(MapSelections::Mode)
|
|
.custom(Alias::new("mode"))
|
|
.not_null()
|
|
.default("std"),
|
|
)
|
|
.col(ColumnDef::new(MapSelections::Mods).json().null())
|
|
.col(
|
|
ColumnDef::new(MapSelections::SelectedModName)
|
|
.string()
|
|
.null(),
|
|
)
|
|
.col(
|
|
ColumnDef::new(MapSelections::SelectedModPosition)
|
|
.integer()
|
|
.null(),
|
|
)
|
|
.col(ColumnDef::new(MapSelections::Comment).string().null())
|
|
.col(ColumnDef::new(MapSelections::SelectedBy).integer().null())
|
|
.foreign_key(
|
|
ForeignKey::create()
|
|
.from(MapSelections::Table, MapSelections::SelectedBy)
|
|
.to(User::Table, User::Id),
|
|
)
|
|
.col(
|
|
ColumnDef::new(MapSelections::SelectedAt)
|
|
.timestamp()
|
|
.not_null(),
|
|
)
|
|
.col(
|
|
ColumnDef::new(MapSelections::Season)
|
|
.integer()
|
|
.not_null()
|
|
.default(1),
|
|
)
|
|
.col(
|
|
ColumnDef::new(MapSelections::Category)
|
|
.custom(Alias::new("category"))
|
|
.not_null()
|
|
.default("qua"),
|
|
)
|
|
.col(ColumnDef::new(MapSelections::CoverUrl).string().null())
|
|
.col(
|
|
ColumnDef::new(MapSelections::IsApproved)
|
|
.boolean()
|
|
.null()
|
|
.default(false),
|
|
)
|
|
.col(
|
|
ColumnDef::new(MapSelections::IsNeedTest)
|
|
.boolean()
|
|
.null()
|
|
.default(false),
|
|
)
|
|
.col(
|
|
ColumnDef::new(MapSelections::IsOrigin)
|
|
.boolean()
|
|
.null()
|
|
.default(false),
|
|
)
|
|
.col(
|
|
ColumnDef::new(MapSelections::IsCustome)
|
|
.boolean()
|
|
.null()
|
|
.default(false),
|
|
)
|
|
.col(
|
|
ColumnDef::new(MapSelections::CreatedAt)
|
|
.timestamp()
|
|
.not_null()
|
|
.default(Expr::current_timestamp()),
|
|
)
|
|
.col(
|
|
ColumnDef::new(MapSelections::UpdatedAt)
|
|
.timestamp()
|
|
.not_null()
|
|
.default(Expr::current_timestamp()),
|
|
)
|
|
.to_owned(),
|
|
)
|
|
.await?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
manager.drop_type(Type::drop().name(Alias::new("mode")).to_owned()).await?;
|
|
manager.drop_type(Type::drop().name(Alias::new("category")).to_owned()).await?;
|
|
manager
|
|
.drop_table(Table::drop().table(MapSelections::Table).to_owned())
|
|
.await
|
|
}
|
|
}
|
|
|
|
#[derive(DeriveIden)]
|
|
enum MapSelections {
|
|
Table,
|
|
Id,
|
|
BeatmapId,
|
|
BeatmapSetId,
|
|
Title,
|
|
TitleUnicode,
|
|
Artist,
|
|
ArtistUnicode,
|
|
Version,
|
|
Creator,
|
|
StarRating,
|
|
Bpm,
|
|
TotalLength,
|
|
MaxCombo,
|
|
Ar,
|
|
Cs,
|
|
Od,
|
|
Hp,
|
|
Mode,
|
|
Mods,
|
|
SelectedModName,
|
|
SelectedModPosition,
|
|
Comment,
|
|
SelectedBy,
|
|
SelectedAt,
|
|
Season,
|
|
Category,
|
|
CoverUrl,
|
|
IsApproved,
|
|
IsNeedTest,
|
|
IsOrigin,
|
|
IsCustome,
|
|
CreatedAt,
|
|
UpdatedAt,
|
|
}
|
|
|
|
#[derive(DeriveIden)]
|
|
enum User {
|
|
Table,
|
|
Id,
|
|
}
|