mirror of
https://github.com/n08i40k/schedule-parser-rusted.git
synced 2025-12-06 09:47:50 +03:00
feat(db): add service users table
This commit is contained in:
@@ -3,4 +3,5 @@
|
|||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
|
|
||||||
pub mod sea_orm_active_enums;
|
pub mod sea_orm_active_enums;
|
||||||
|
pub mod service_user;
|
||||||
pub mod user;
|
pub mod user;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.12
|
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.12
|
||||||
|
|
||||||
|
pub use super::service_user::Entity as ServiceUser;
|
||||||
pub use super::user::Entity as User;
|
pub use super::user::Entity as User;
|
||||||
|
|||||||
16
database/entity/src/service_user.rs
Normal file
16
database/entity/src/service_user.rs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.12
|
||||||
|
|
||||||
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||||
|
#[sea_orm(table_name = "service_user")]
|
||||||
|
pub struct Model {
|
||||||
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
|
pub id: String,
|
||||||
|
pub name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
pub enum Relation {}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
@@ -3,6 +3,7 @@ pub use sea_orm_migration::prelude::MigratorTrait;
|
|||||||
use sea_orm_migration::prelude::*;
|
use sea_orm_migration::prelude::*;
|
||||||
|
|
||||||
mod m20250904_024854_init;
|
mod m20250904_024854_init;
|
||||||
|
mod m20251027_230335_add_service_users;
|
||||||
|
|
||||||
pub struct Migrator;
|
pub struct Migrator;
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ impl MigratorTrait for Migrator {
|
|||||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||||
vec![
|
vec![
|
||||||
Box::new(m20250904_024854_init::Migration),
|
Box::new(m20250904_024854_init::Migration),
|
||||||
|
Box::new(m20251027_230335_add_service_users::Migration),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
33
database/migration/src/m20251027_230335_add_service_users.rs
Normal file
33
database/migration/src/m20251027_230335_add_service_users.rs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
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(ServiceUser::Table)
|
||||||
|
.if_not_exists()
|
||||||
|
.col(string_uniq(ServiceUser::Id).primary_key().not_null())
|
||||||
|
.col(string(ServiceUser::Name))
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||||
|
manager
|
||||||
|
.drop_table(Table::drop().table(ServiceUser::Table).to_owned())
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(DeriveIden)]
|
||||||
|
enum ServiceUser {
|
||||||
|
Table,
|
||||||
|
Id,
|
||||||
|
Name,
|
||||||
|
}
|
||||||
@@ -6,5 +6,17 @@ pub use sea_orm;
|
|||||||
pub mod entity {
|
pub mod entity {
|
||||||
pub use entity::*;
|
pub use entity::*;
|
||||||
|
|
||||||
pub use entity::user::{ActiveModel as ActiveUser, Model as User, Entity as UserEntity, Column as UserColumn};
|
pub use entity::user::{
|
||||||
|
ActiveModel as ActiveUser, //
|
||||||
|
Column as UserColumn, //
|
||||||
|
Entity as UserEntity, //
|
||||||
|
Model as User, //
|
||||||
|
};
|
||||||
|
|
||||||
|
pub use entity::service_user::{
|
||||||
|
ActiveModel as ActiveServiceUser, //
|
||||||
|
Column as ServiceUserColumn, //
|
||||||
|
Entity as ServiceUserEntity, //
|
||||||
|
Model as ServiceUser, //
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ macro_rules! define_find_by {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Query {
|
impl Query {
|
||||||
|
// User
|
||||||
|
|
||||||
define_find_by!(user, id, str, Id);
|
define_find_by!(user, id, str, Id);
|
||||||
define_find_by!(user, telegram_id, i64, TelegramId);
|
define_find_by!(user, telegram_id, i64, TelegramId);
|
||||||
define_find_by!(user, vk_id, i32, VkId);
|
define_find_by!(user, vk_id, i32, VkId);
|
||||||
@@ -60,4 +62,12 @@ impl Query {
|
|||||||
define_is_exists!(user, username, str, Username);
|
define_is_exists!(user, username, str, Username);
|
||||||
define_is_exists!(user, telegram_id, i64, TelegramId);
|
define_is_exists!(user, telegram_id, i64, TelegramId);
|
||||||
define_is_exists!(user, vk_id, i32, VkId);
|
define_is_exists!(user, vk_id, i32, VkId);
|
||||||
|
|
||||||
|
// Service user
|
||||||
|
|
||||||
|
define_find_by!(service_user, id, str, Id);
|
||||||
|
define_find_by!(service_user, name, str, Name);
|
||||||
|
|
||||||
|
define_is_exists!(service_user, id, str, Id);
|
||||||
|
define_is_exists!(service_user, name, str, Name);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user