mirror of
https://github.com/n08i40k/schedule-parser-rusted.git
synced 2025-12-06 17:57:47 +03:00
feat(database)!: switch from diesel to sea-orm
This commit is contained in:
16
database/migration/src/lib.rs
Normal file
16
database/migration/src/lib.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
pub use sea_orm_migration::prelude::MigratorTrait;
|
||||
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
mod m20250904_024854_init;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigratorTrait for Migrator {
|
||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||
vec![
|
||||
Box::new(m20250904_024854_init::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
70
database/migration/src/m20250904_024854_init.rs
Normal file
70
database/migration/src/m20250904_024854_init.rs
Normal file
@@ -0,0 +1,70 @@
|
||||
use sea_orm_migration::prelude::extension::postgres::Type;
|
||||
use sea_orm_migration::sea_orm::{EnumIter, Iterable};
|
||||
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_type(
|
||||
Type::create()
|
||||
.as_enum(UserRole)
|
||||
.values(UserRoleVariants::iter())
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(User::Table)
|
||||
.if_not_exists()
|
||||
.col(string_uniq(User::Id).primary_key().not_null())
|
||||
.col(string_uniq(User::Username).not_null())
|
||||
.col(string_null(User::Password))
|
||||
.col(integer_null(User::VkId))
|
||||
.col(string_null(User::Group))
|
||||
.col(enumeration(User::Role, UserRole, UserRoleVariants::iter()))
|
||||
.col(string_null(User::AndroidVersion))
|
||||
.col(big_integer_null(User::TelegramId).unique_key())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(User::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_type(Type::drop().name(UserRole).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
struct UserRole;
|
||||
|
||||
#[derive(DeriveIden, EnumIter)]
|
||||
enum UserRoleVariants {
|
||||
Student,
|
||||
Teacher,
|
||||
Admin,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum User {
|
||||
Table,
|
||||
Id,
|
||||
Username,
|
||||
Password,
|
||||
VkId,
|
||||
Group,
|
||||
Role,
|
||||
AndroidVersion,
|
||||
TelegramId,
|
||||
}
|
||||
6
database/migration/src/main.rs
Normal file
6
database/migration/src/main.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[async_std::main]
|
||||
async fn main() {
|
||||
cli::run_cli(migration::Migrator).await;
|
||||
}
|
||||
Reference in New Issue
Block a user