mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Create RC database layer
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
pub struct Migration;
|
||||
|
||||
impl MigrationName for Migration {
|
||||
fn name(&self) -> &str {
|
||||
"m20250424_000001_create_user_table"
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
// Define how to apply this migration: Create the Users table.
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(crate::schema::user::Entity)
|
||||
.col(
|
||||
ColumnDef::new(crate::schema::user::Column::Id)
|
||||
.unsigned()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(crate::schema::user::Column::CreationTime).big_integer().not_null())
|
||||
.col(ColumnDef::new(crate::schema::user::Column::PublicId).string().not_null())
|
||||
.col(ColumnDef::new(crate::schema::user::Column::DisplayName).string().not_null())
|
||||
.col(ColumnDef::new(crate::schema::user::Column::Password).string().not_null())
|
||||
.col(ColumnDef::new(crate::schema::user::Column::Email).string().not_null())
|
||||
.col(ColumnDef::new(crate::schema::user::Column::SteamId).string())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
// Define how to rollback this migration: Drop the Users table.
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(crate::schema::user::Entity).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
pub struct Migration;
|
||||
|
||||
impl MigrationName for Migration {
|
||||
fn name(&self) -> &str {
|
||||
"m20250424_000002_create_user_permissions_table"
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
// Define how to apply this migration: Create the Permissions table.
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(crate::schema::permissions::Entity)
|
||||
.col(
|
||||
ColumnDef::new(crate::schema::permissions::Column::Id)
|
||||
.unsigned()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(crate::schema::permissions::Column::UserId).unsigned().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-permissions-user_id")
|
||||
.from(crate::schema::permissions::Entity, crate::schema::permissions::Column::UserId)
|
||||
.to(crate::schema::user::Entity, crate::schema::user::Column::Id),
|
||||
)
|
||||
.col(ColumnDef::new(crate::schema::permissions::Column::Moderator).boolean().not_null())
|
||||
//.col(crate::schema::permissions::Column::Moderator.def()) // I wish this worked...
|
||||
.col(ColumnDef::new(crate::schema::permissions::Column::Administrator).boolean().not_null())
|
||||
.col(ColumnDef::new(crate::schema::permissions::Column::Developer).boolean().not_null())
|
||||
.col(ColumnDef::new(crate::schema::permissions::Column::Royalty).boolean().not_null())
|
||||
.col(ColumnDef::new(crate::schema::permissions::Column::Banned).boolean().not_null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
// Define how to rollback this migration: Drop the Permissions table.
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(crate::schema::permissions::Entity).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
pub struct Migration;
|
||||
|
||||
impl MigrationName for Migration {
|
||||
fn name(&self) -> &str {
|
||||
"m20250424_000003_create_garage_table"
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
// Define how to apply this migration: Create the Garages table.
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(crate::schema::garage::Entity)
|
||||
.col(
|
||||
ColumnDef::new(crate::schema::garage::Column::Id)
|
||||
.unsigned()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::UserId).unsigned().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-garage-user_id")
|
||||
.from(crate::schema::garage::Entity, crate::schema::garage::Column::UserId)
|
||||
.to(crate::schema::user::Entity, crate::schema::user::Column::Id),
|
||||
)
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::CreationTime).big_integer().not_null())
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::Slot).unsigned().not_null())
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::Name).string().not_null())
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::CrfId).unsigned())
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::WasRated).boolean().not_null())
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::MovementCategories).string().not_null())
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::Uuid).big_integer().not_null())
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::ThumbnailVersion).unsigned().not_null())
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::TotalRobotCpu).unsigned().not_null())
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::TotalCosmeticCpu).unsigned().not_null())
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::TotalRobotRanking).unsigned().not_null())
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::BayCpu).unsigned().not_null())
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::TutorialRobot).boolean().not_null())
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::StarterRobotIndex).unsigned())
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::ControlType).tiny_unsigned().not_null())
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::VerticalStrafing).boolean().not_null())
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::SidewaysDriving).boolean().not_null())
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::TracksTurnOnSpot).boolean().not_null())
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::MasteryLevel).unsigned().not_null())
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::BaySkinId).string().not_null())
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::WeaponOrder).string().not_null())
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::RobotData).blob().not_null())
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::ColourData).blob().not_null())
|
||||
.col(ColumnDef::new(crate::schema::garage::Column::Selected).boolean().not_null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
// Define how to rollback this migration: Drop the Garages table.
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(crate::schema::garage::Entity).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
pub struct Migration;
|
||||
|
||||
impl MigrationName for Migration {
|
||||
fn name(&self) -> &str {
|
||||
"m20250424_000004_create_user_aux_table"
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
// Define how to apply this migration: Create the User auxiliary table.
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(crate::schema::user_aux::Entity)
|
||||
.col(
|
||||
ColumnDef::new(crate::schema::user_aux::Column::Id)
|
||||
.unsigned()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(crate::schema::user_aux::Column::UserId).unsigned().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-users_aux-user_id")
|
||||
.from(crate::schema::user_aux::Entity, crate::schema::user_aux::Column::UserId)
|
||||
.to(crate::schema::user::Entity, crate::schema::user::Column::Id),
|
||||
)
|
||||
.col(ColumnDef::new(crate::schema::user_aux::Column::CreationTime).big_integer().not_null())
|
||||
.col(ColumnDef::new(crate::schema::user_aux::Column::Descriptor).string().not_null())
|
||||
.col(ColumnDef::new(crate::schema::user_aux::Column::Data).string().not_null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
// Define how to rollback this migration: Drop the User auxiliary table.
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(crate::schema::user_aux::Entity).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
pub struct Migration;
|
||||
|
||||
impl MigrationName for Migration {
|
||||
fn name(&self) -> &str {
|
||||
"m20250424_000005_create_campaign_tables"
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
// Define how to apply this migration: Create the Campaigns table.
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(crate::schema::campaign::Entity)
|
||||
.col(
|
||||
ColumnDef::new(crate::schema::campaign::Column::Id)
|
||||
.unsigned()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(crate::schema::campaign::Column::UserId).unsigned().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-campaign-user_id")
|
||||
.from(crate::schema::campaign::Entity, crate::schema::campaign::Column::UserId)
|
||||
.to(crate::schema::user::Entity, crate::schema::user::Column::Id),
|
||||
)
|
||||
.col(ColumnDef::new(crate::schema::campaign::Column::CreationTime).big_integer().not_null())
|
||||
.col(ColumnDef::new(crate::schema::campaign::Column::CampaignId).string().not_null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(crate::schema::campaign_difficulty_completion::Entity)
|
||||
.col(
|
||||
ColumnDef::new(crate::schema::campaign_difficulty_completion::Column::Id)
|
||||
.unsigned()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(crate::schema::campaign_difficulty_completion::Column::CampaignId).unsigned().not_null())
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk-campaigns_completion-campaign_id")
|
||||
.from(crate::schema::campaign_difficulty_completion::Entity, crate::schema::campaign_difficulty_completion::Column::CampaignId)
|
||||
.to(crate::schema::campaign::Entity, crate::schema::campaign::Column::Id),
|
||||
)
|
||||
.col(ColumnDef::new(crate::schema::campaign_difficulty_completion::Column::CreationTime).big_integer().not_null())
|
||||
.col(ColumnDef::new(crate::schema::campaign_difficulty_completion::Column::Level).unsigned().not_null())
|
||||
.col(ColumnDef::new(crate::schema::campaign_difficulty_completion::Column::Wave).unsigned().not_null())
|
||||
.col(ColumnDef::new(crate::schema::campaign_difficulty_completion::Column::Complete).boolean().not_null())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
// Define how to rollback this migration: Drop the Campaigns table.
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(crate::schema::campaign::Entity).to_owned())
|
||||
.await?;
|
||||
manager
|
||||
.drop_table(Table::drop().table(crate::schema::campaign_difficulty_completion::Entity).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
22
rc_database/src/migration/mod.rs
Normal file
22
rc_database/src/migration/mod.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use sea_orm_migration::{MigratorTrait, MigrationTrait, prelude::async_trait};
|
||||
|
||||
mod m20250424_000001_create_user_table;
|
||||
mod m20250424_000002_create_user_permissions_table;
|
||||
mod m20250424_000003_create_garage_table;
|
||||
mod m20250424_000004_create_user_aux_table;
|
||||
mod m20250424_000005_create_campaign_tables;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigratorTrait for Migrator {
|
||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||
vec![
|
||||
Box::new(m20250424_000001_create_user_table::Migration),
|
||||
Box::new(m20250424_000002_create_user_permissions_table::Migration),
|
||||
Box::new(m20250424_000003_create_garage_table::Migration),
|
||||
Box::new(m20250424_000004_create_user_aux_table::Migration),
|
||||
Box::new(m20250424_000005_create_campaign_tables::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user