add migration

This commit is contained in:
2026-02-12 14:06:19 +08:00
parent 4309810fc3
commit 879cba6a9f
9 changed files with 708 additions and 81 deletions

View File

@@ -1,12 +1,28 @@
pub use sea_orm_migration::prelude::*;
mod m20260211_140546_user;
mod m20260211_140547_map_selections;
mod m20260211_140548_match_rooms;
mod m20260211_140549_match_schedules;
mod m20260211_140550_player_matchups;
mod m20260211_140551_messages;
mod m20260211_140552_map_comments;
mod m20260211_140553_tournament_settings;
pub struct Migrator;
#[async_trait::async_trait]
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![Box::new(m20260211_140546_user::Migration)]
vec![
Box::new(m20260211_140546_user::Migration),
Box::new(m20260211_140547_map_selections::Migration),
Box::new(m20260211_140548_match_rooms::Migration),
Box::new(m20260211_140549_match_schedules::Migration),
Box::new(m20260211_140550_player_matchups::Migration),
Box::new(m20260211_140551_messages::Migration),
Box::new(m20260211_140552_map_comments::Migration),
Box::new(m20260211_140553_tournament_settings::Migration),
]
}
}

View File

@@ -18,52 +18,34 @@ impl MigrationTrait for Migration {
.auto_increment()
.primary_key(),
)
.col(
ColumnDef::new(User::OsuId)
.integer()
.not_null()
.unique_key(),
)
.col(ColumnDef::new(User::OsuId).string().not_null().unique_key())
.col(
ColumnDef::new(User::Username)
.string()
.not_null()
.unique_key(),
)
.col(
ColumnDef::new(User::RegisteredAt)
.timestamp()
.not_null()
.default(Expr::current_timestamp()),
)
.col(ColumnDef::new(User::AvatarUrl).string().null())
.col(ColumnDef::new(User::CoverUrl).string().null())
.col(
ColumnDef::new(User::UserState)
.enumeration("userstate", vec!["active", "banned", "deleted"])
.not_null()
.default(UserState::Active),
)
.col(ColumnDef::new(User::Pp).float().not_null().default(0.0))
.col(ColumnDef::new(User::CountryCode).string())
.col(ColumnDef::new(User::Pp).float().null())
.col(ColumnDef::new(User::GlobalRank).integer().null())
.col(ColumnDef::new(User::Country).string().null())
.col(ColumnDef::new(User::CountryRank).integer().null())
.col(ColumnDef::new(User::Level).integer().not_null().default(1))
.col(ColumnDef::new(User::Approved).integer().null())
.col(
ColumnDef::new(User::RegisteredSeasonal)
.integer()
ColumnDef::new(User::UserGroup)
.enumeration("usergroup", vec!["player", "admin"])
.not_null()
.default(1),
)
// gu服绑定
.col(
ColumnDef::new(User::GuServerId)
.integer()
.null()
.unique_key(),
.default("player"),
)
.col(ColumnDef::new(User::Season).integer().null())
.col(ColumnDef::new(User::GuServerUserId).integer().null())
.col(ColumnDef::new(User::GuServerUsername).string().null())
// 用户组
.col(
ColumnDef::new(User::UserGroupType)
.enumeration("usergrouptype", vec!["player", "admin"])
.not_null()
.default(UserGroupType::Player),
)
.col(
ColumnDef::new(User::CreatedAt)
.timestamp()
@@ -96,54 +78,17 @@ enum User {
Id,
OsuId,
Username,
RegisteredAt,
AvatarUrl,
CoverUrl,
UserState,
CountryCode,
CountryRank,
RegisteredSeasonal,
GuServerId,
GuServerUsername,
UserGroupType,
CreatedAt,
UpdatedAt,
Level,
Pp,
GlobalRank,
}
#[derive(DeriveIden)]
enum UserState {
Table,
Active,
Banned,
Deleted,
}
#[derive(DeriveIden)]
enum UserGroupType {
Table,
Player,
Admin,
}
impl Into<Expr> for UserState {
fn into(self) -> Expr {
match self {
UserState::Active => Expr::val("active"),
UserState::Banned => Expr::val("banned"),
UserState::Deleted => Expr::val("deleted"),
UserState::Table => Expr::val("userstate"),
}
}
}
impl Into<Expr> for UserGroupType {
fn into(self) -> Expr {
match self {
UserGroupType::Player => Expr::val("player"),
UserGroupType::Admin => Expr::val("admin"),
UserGroupType::Table => Expr::val("usergrouptype"),
}
}
Country,
CountryRank,
Approved,
UserGroup,
Season,
GuServerUserId,
GuServerUsername,
CreatedAt,
UpdatedAt,
}

View File

@@ -0,0 +1,139 @@
use sea_orm_migration::{prelude::*, schema::*};
#[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(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().not_null())
.col(ColumnDef::new(MapSelections::TitleUnicode).string().null())
.col(ColumnDef::new(MapSelections::Artist).string().not_null())
.col(ColumnDef::new(MapSelections::ArtistUnicode).string().null())
.col(ColumnDef::new(MapSelections::Version).string().not_null())
.col(ColumnDef::new(MapSelections::Creator).string().not_null())
.col(
ColumnDef::new(MapSelections::StarRating)
.decimal()
.not_null(),
)
.col(ColumnDef::new(MapSelections::Bpm).decimal().not_null())
.col(
ColumnDef::new(MapSelections::TotalLength)
.integer()
.not_null(),
)
.col(ColumnDef::new(MapSelections::MaxCombo).integer().not_null())
.col(ColumnDef::new(MapSelections::Ar).decimal().not_null())
.col(ColumnDef::new(MapSelections::Cs).decimal().not_null())
.col(ColumnDef::new(MapSelections::Od).decimal().not_null())
.col(ColumnDef::new(MapSelections::Hp).decimal().not_null())
.col(
ColumnDef::new(MapSelections::SelectedMods)
.string()
.not_null(),
)
.col(
ColumnDef::new(MapSelections::ModPosition)
.integer()
.not_null(),
)
.col(ColumnDef::new(MapSelections::Comment).text().null())
.col(
ColumnDef::new(MapSelections::SelectedBy)
.string()
.not_null(),
)
.col(
ColumnDef::new(MapSelections::SelectedAt)
.timestamp()
.not_null(),
)
.col(ColumnDef::new(MapSelections::Season).string().not_null())
.col(ColumnDef::new(MapSelections::Category).string().not_null())
.col(ColumnDef::new(MapSelections::Url).text().not_null())
.col(ColumnDef::new(MapSelections::CoverUrl).text().null())
.col(ColumnDef::new(MapSelections::Approved).integer().null())
.col(ColumnDef::new(MapSelections::Padding).integer().null())
.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_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,
SelectedMods,
ModPosition,
Comment,
SelectedBy,
SelectedAt,
Season,
Category,
Url,
CoverUrl,
Approved,
Padding,
CreatedAt,
UpdatedAt,
}

View File

@@ -0,0 +1,93 @@
use sea_orm_migration::{prelude::*, schema::*};
#[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(MatchRooms::Table)
.if_not_exists()
.col(
ColumnDef::new(MatchRooms::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(
ColumnDef::new(MatchRooms::RoomName)
.string()
.not_null(),
)
.col(
ColumnDef::new(MatchRooms::RoundNumber)
.integer()
.not_null(),
)
.col(
ColumnDef::new(MatchRooms::MatchDate)
.date()
.not_null(),
)
.col(
ColumnDef::new(MatchRooms::MatchTime)
.time()
.not_null(),
)
.col(
ColumnDef::new(MatchRooms::MatchNumber)
.integer()
.not_null(),
)
.col(ColumnDef::new(MatchRooms::MaxParticipants).integer().null())
.col(ColumnDef::new(MatchRooms::Status).enumeration("status", vec!["available", "scheduled", "completed"]).null())
.col(
ColumnDef::new(MatchRooms::CreatedBy)
.string()
.not_null(),
)
.col(
ColumnDef::new(MatchRooms::CreatedAt)
.timestamp()
.not_null()
.default(Expr::current_timestamp()),
)
.col(
ColumnDef::new(MatchRooms::UpdatedAt)
.timestamp()
.not_null()
.default(Expr::current_timestamp()),
)
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(MatchRooms::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
enum MatchRooms {
Table,
Id,
RoomName,
RoundNumber,
MatchDate,
MatchTime,
MatchNumber,
MaxParticipants,
Status,
CreatedBy,
CreatedAt,
UpdatedAt,
}

View File

@@ -0,0 +1,110 @@
use sea_orm_migration::{prelude::*, schema::*};
#[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(MatchSchedules::Table)
.if_not_exists()
.col(
ColumnDef::new(MatchSchedules::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(MatchSchedules::RoomId).integer().not_null())
.col(
ColumnDef::new(MatchSchedules::Player1OsuId)
.string()
.not_null(),
)
.col(
ColumnDef::new(MatchSchedules::Player1Username)
.string()
.not_null(),
)
.col(
ColumnDef::new(MatchSchedules::Player2OsuId)
.string()
.not_null(),
)
.col(
ColumnDef::new(MatchSchedules::Player2Username)
.string()
.not_null(),
)
.col(ColumnDef::new(MatchSchedules::RedScore).integer().null())
.col(ColumnDef::new(MatchSchedules::BlueScore).integer().null())
.col(
ColumnDef::new(MatchSchedules::Status)
.enumeration("status", vec!["available", "scheduled", "completed"])
.null(),
)
.col(ColumnDef::new(MatchSchedules::ReplayLink).text().null())
.col(ColumnDef::new(MatchSchedules::MatchLink).text().null())
.col(
ColumnDef::new(MatchSchedules::CreatedBy)
.string()
.not_null(),
)
.col(
ColumnDef::new(MatchSchedules::CreatedAt)
.timestamp()
.not_null()
.default(Expr::current_timestamp()),
)
.col(
ColumnDef::new(MatchSchedules::UpdatedAt)
.timestamp()
.not_null()
.default(Expr::current_timestamp()),
)
.foreign_key(
ForeignKey::create()
.from(MatchSchedules::Table, MatchSchedules::RoomId)
.to(MatchRooms::Table, MatchRooms::Id),
)
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(MatchSchedules::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
enum MatchSchedules {
Table,
Id,
RoomId,
Player1OsuId,
Player1Username,
Player2OsuId,
Player2Username,
RedScore,
BlueScore,
Status,
ReplayLink,
MatchLink,
CreatedBy,
CreatedAt,
UpdatedAt,
}
#[derive(DeriveIden)]
enum MatchRooms {
Table,
Id,
}

View File

@@ -0,0 +1,89 @@
use sea_orm_migration::{prelude::*, schema::*};
#[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(PlayerMatchups::Table)
.if_not_exists()
.col(
ColumnDef::new(PlayerMatchups::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(
ColumnDef::new(PlayerMatchups::Player1OsuId)
.string()
.not_null(),
)
.col(
ColumnDef::new(PlayerMatchups::Player1Username)
.string()
.not_null(),
)
.col(
ColumnDef::new(PlayerMatchups::Player2OsuId)
.string()
.not_null(),
)
.col(
ColumnDef::new(PlayerMatchups::Player2Username)
.string()
.not_null(),
)
.col(
ColumnDef::new(PlayerMatchups::Status)
.enumeration("status", vec!["available", "scheduled", "completed"])
.null(),
)
.col(
ColumnDef::new(PlayerMatchups::CreatedBy)
.string()
.not_null(),
)
.col(
ColumnDef::new(PlayerMatchups::CreatedAt)
.timestamp()
.not_null()
.default(Expr::current_timestamp()),
)
.col(
ColumnDef::new(PlayerMatchups::UpdatedAt)
.timestamp()
.not_null()
.default(Expr::current_timestamp()),
)
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(PlayerMatchups::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
enum PlayerMatchups {
Table,
Id,
Player1OsuId,
Player1Username,
Player2OsuId,
Player2Username,
Status,
CreatedBy,
CreatedAt,
UpdatedAt,
}

View File

@@ -0,0 +1,90 @@
use sea_orm_migration::{prelude::*, schema::*};
#[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(Messages::Table)
.if_not_exists()
.col(
ColumnDef::new(Messages::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(Messages::SenderOsuId).string().not_null())
.col(ColumnDef::new(Messages::SenderUsername).string().not_null())
.col(ColumnDef::new(Messages::ReceiverOsuId).string().not_null())
.col(
ColumnDef::new(Messages::ReceiverUsername)
.string()
.not_null(),
)
.col(
ColumnDef::new(Messages::Type)
.enumeration(
"type",
vec!["match_invitation", "match_response", "system"],
)
.null(),
)
.col(ColumnDef::new(Messages::Title).string().not_null())
.col(ColumnDef::new(Messages::Content).text().not_null())
.col(ColumnDef::new(Messages::RelatedMatchupId).integer().null())
.col(
ColumnDef::new(Messages::Status)
.enumeration("status", vec!["available", "scheduled", "completed"])
.null(),
)
.col(ColumnDef::new(Messages::ResponseAction).string().null())
.col(ColumnDef::new(Messages::ResponseTime).timestamp().null())
.col(
ColumnDef::new(Messages::CreatedAt)
.timestamp()
.not_null()
.default(Expr::current_timestamp()),
)
.col(
ColumnDef::new(Messages::UpdatedAt)
.timestamp()
.not_null()
.default(Expr::current_timestamp()),
)
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(Messages::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
enum Messages {
Table,
Id,
SenderOsuId,
SenderUsername,
ReceiverOsuId,
ReceiverUsername,
Type,
Title,
Content,
RelatedMatchupId,
Status,
ResponseAction,
ResponseTime,
CreatedAt,
UpdatedAt,
}

View File

@@ -0,0 +1,76 @@
use sea_orm_migration::{prelude::*, schema::*};
#[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(MapComments::Table)
.if_not_exists()
.col(
ColumnDef::new(MapComments::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(
ColumnDef::new(MapComments::MapSelectionId)
.integer()
.not_null(),
)
.col(ColumnDef::new(MapComments::OsuId).string().not_null())
.col(ColumnDef::new(MapComments::Username).string().not_null())
.col(ColumnDef::new(MapComments::Comment).text().null())
.col(
ColumnDef::new(MapComments::CreatedAt)
.timestamp()
.not_null()
.default(Expr::current_timestamp()),
)
.col(
ColumnDef::new(MapComments::UpdatedAt)
.timestamp()
.not_null()
.default(Expr::current_timestamp()),
)
.foreign_key(
ForeignKey::create()
.from(MapComments::Table, MapComments::MapSelectionId)
.to(MapSelections::Table, MapSelections::Id),
)
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(MapComments::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
enum MapComments {
Table,
Id,
MapSelectionId,
OsuId,
Username,
Comment,
CreatedAt,
UpdatedAt,
}
#[derive(DeriveIden)]
enum MapSelections {
Table,
Id,
}

View File

@@ -0,0 +1,69 @@
use sea_orm_migration::{prelude::*, schema::*};
#[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(TournamentSettings::Table)
.if_not_exists()
.col(
ColumnDef::new(TournamentSettings::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(
ColumnDef::new(TournamentSettings::TournamentName)
.string()
.not_null(),
)
.col(ColumnDef::new(TournamentSettings::MaxPpForRegistration).float().null())
.col(ColumnDef::new(TournamentSettings::MinPpForRegistration).float().null())
.col(ColumnDef::new(TournamentSettings::CurrentSeason).string().null())
.col(ColumnDef::new(TournamentSettings::CurrentSeasonStage).string().null())
.col(ColumnDef::new(TournamentSettings::MappoolVisible).integer().null())
.col(
ColumnDef::new(TournamentSettings::CreatedAt)
.timestamp()
.not_null()
.default(Expr::current_timestamp()),
)
.col(
ColumnDef::new(TournamentSettings::UpdatedAt)
.timestamp()
.not_null()
.default(Expr::current_timestamp()),
)
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(TournamentSettings::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
enum TournamentSettings {
Table,
Id,
TournamentName,
MaxPpForRegistration,
MinPpForRegistration,
CurrentSeason,
CurrentSeasonStage,
MappoolVisible,
CreatedAt,
UpdatedAt,
}