feat: Add last_logout column to users table #31

Manually merged
awiteb merged 2 commits from awiteb/user-last-login into master 2024-07-24 10:50:24 +02:00 AGit
3 changed files with 13 additions and 3 deletions
Showing only changes of commit 7dab7e29cc - Show all commits

View file

@ -16,6 +16,7 @@
//! Functions for interacting with the user table in the database. //! Functions for interacting with the user table in the database.
use chrono::Utc;
use logcall::logcall; use logcall::logcall;
use oxidetalis_core::types::PublicKey; use oxidetalis_core::types::PublicKey;
use oxidetalis_entities::prelude::*; use oxidetalis_entities::prelude::*;
@ -47,6 +48,7 @@ impl UserTableExt for DatabaseConnection {
if let Err(err) = (UserActiveModel { if let Err(err) = (UserActiveModel {
public_key: Set(*public_key), public_key: Set(*public_key),
is_admin: Set(is_admin), is_admin: Set(is_admin),
last_logout: Set(Utc::now()),
..Default::default() ..Default::default()
}) })
.save(self) .save(self)

View file

@ -21,6 +21,7 @@
//! Entity for `users` table //! Entity for `users` table
use chrono::Utc;
use oxidetalis_core::types::PublicKey; use oxidetalis_core::types::PublicKey;
use sea_orm::entity::prelude::*; use sea_orm::entity::prelude::*;
@ -32,6 +33,7 @@ pub struct Model {
#[sea_orm(primary_key)] #[sea_orm(primary_key)]
pub id: UserId, pub id: UserId,
pub public_key: PublicKey, pub public_key: PublicKey,
pub last_logout: chrono::DateTime<Utc>,
pub is_admin: bool, pub is_admin: bool,
} }

View file

@ -47,6 +47,11 @@ impl MigrationTrait for Migration {
.not_null() .not_null()
.unique_key(), .unique_key(),
) )
.col(
ColumnDef::new(Users::LastLogout)
.timestamp_with_time_zone()
.not_null(),
)
.col( .col(
ColumnDef::new(Users::IsAdmin) ColumnDef::new(Users::IsAdmin)
.boolean() .boolean()
@ -64,5 +69,6 @@ pub enum Users {
Table, Table,
Id, Id,
PublicKey, PublicKey,
LastLogout,
IsAdmin, IsAdmin,
} }