feature/authentication service #9

Merged
GW_MC merged 19 commits from feature/authentication into master 2025-12-19 12:24:49 +08:00
6 changed files with 0 additions and 92 deletions
Showing only changes of commit b17d111c5d - Show all commits

View File

@@ -3,6 +3,5 @@
pub mod prelude;
pub mod config;
pub mod session;
pub mod user;
pub mod user_identity;

View File

@@ -1,6 +1,5 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 2.0.0-rc.18
pub use super::config::Entity as Config;
pub use super::session::Entity as Session;
pub use super::user::Entity as User;
pub use super::user_identity::Entity as UserIdentity;

View File

@@ -18,8 +18,6 @@ pub struct Model {
pub last_login_at: Option<DateTimeUtc>,
pub deleted_at: Option<DateTimeUtc>,
#[sea_orm(has_many)]
pub sessions: HasMany<super::session::Entity>,
#[sea_orm(has_many)]
pub user_identities: HasMany<super::user_identity::Entity>,
}

View File

@@ -13,7 +13,6 @@ impl MigratorTrait for Migrator {
Box::new(m20251011_000001_create_config_table::Migration),
Box::new(m20251011_000002_create_user_table::Migration),
Box::new(m20251011_000003_create_user_identity_table::Migration),
Box::new(m20251011_000004_create_session_table::Migration),
]
}
}

View File

@@ -1,4 +1,3 @@
pub mod m20251011_000001_create_config_table;
pub mod m20251011_000002_create_user_table;
pub mod m20251011_000003_create_user_identity_table;
pub mod m20251011_000004_create_session_table;

View File

@@ -1,86 +0,0 @@
use sea_orm_migration::{prelude::*, schema::*};
#[derive(DeriveMigrationName)]
pub struct Migration;
#[forbid(dead_code)]
#[derive(DeriveIden)]
pub enum Session {
Table,
Id,
UserId,
//
RefreshTokenHash,
//
ExpiresAt,
RevokedAt,
//
CreatedAt,
UpdatedAt,
}
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let _ = manager
.create_table(
Table::create()
.table(Session::Table)
.if_not_exists()
.col(pk_uuid(Session::Id))
//
.col(ColumnDef::new(Session::UserId).uuid().not_null())
.foreign_key(
ForeignKey::create()
.name("fk-session-user-id")
.from(Session::Table, Session::UserId)
.to(
super::m20251011_000002_create_user_table::User::Table,
super::m20251011_000002_create_user_table::User::Id,
)
.on_delete(ForeignKeyAction::Cascade)
.on_update(ForeignKeyAction::Cascade),
)
.col(
ColumnDef::new(Session::RefreshTokenHash)
.string()
.null()
.unique_key(),
)
.col(ColumnDef::new(Session::ExpiresAt).timestamp().not_null())
.col(ColumnDef::new(Session::RevokedAt).timestamp().null())
//
.col(
ColumnDef::new(Session::CreatedAt)
.timestamp()
.default(SimpleExpr::Keyword(Keyword::CurrentTimestamp))
.not_null(),
)
.col(
ColumnDef::new(Session::UpdatedAt)
.timestamp()
.default(SimpleExpr::Keyword(Keyword::CurrentTimestamp))
.not_null(),
)
.to_owned(),
)
.await;
manager
.create_index(
Index::create()
.name("idx-session-user-id-token")
.table(Session::Table)
.col(Session::UserId)
.col(Session::RefreshTokenHash)
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(Session::Table).to_owned())
.await
}
}