Create session database table
This commit is contained in:
parent
aecaf0cca3
commit
bdfe6bc507
6 changed files with 79 additions and 1 deletions
|
@ -2,6 +2,7 @@ pub use sea_orm_migration::prelude::*;
|
|||
|
||||
mod m20230619_221344_create_user;
|
||||
mod m20230620_232650_create_keypair;
|
||||
mod m20230625_211327_create_session;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
|
@ -11,6 +12,7 @@ impl MigratorTrait for Migrator {
|
|||
vec![
|
||||
Box::new(m20230619_221344_create_user::Migration),
|
||||
Box::new(m20230620_232650_create_keypair::Migration),
|
||||
Box::new(m20230625_211327_create_session::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
51
migration/src/m20230625_211327_create_session.rs
Normal file
51
migration/src/m20230625_211327_create_session.rs
Normal file
|
@ -0,0 +1,51 @@
|
|||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[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(Session::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(Session::Id)
|
||||
.string()
|
||||
.not_null()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(Session::Token).string().not_null())
|
||||
.col(ColumnDef::new(Session::User).string().not_null())
|
||||
.col(ColumnDef::new(Session::Issued).date_time().not_null())
|
||||
.col(ColumnDef::new(Session::Expiry).date_time().not_null())
|
||||
.col(ColumnDef::new(Session::Device).string().not_null())
|
||||
.col(ColumnDef::new(Session::Ip).inet().not_null())
|
||||
.col(ColumnDef::new(Session::LastUsage).date_time())
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_table(Table::drop().table(Session::Table).to_owned())
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
/// Learn more at https://docs.rs/sea-query#iden
|
||||
#[derive(Iden)]
|
||||
enum Session {
|
||||
Table,
|
||||
Id,
|
||||
Token,
|
||||
User,
|
||||
Issued,
|
||||
Expiry,
|
||||
Device,
|
||||
Ip,
|
||||
LastUsage
|
||||
}
|
|
@ -3,4 +3,5 @@
|
|||
pub mod prelude;
|
||||
|
||||
pub mod key_pair;
|
||||
pub mod session;
|
||||
pub mod user;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
|
||||
|
||||
pub use super::key_pair::Entity as KeyPair;
|
||||
pub use super::session::Entity as Session;
|
||||
pub use super::user::Entity as User;
|
||||
|
|
23
slop-common/src/db/entities/session.rs
Normal file
23
slop-common/src/db/entities/session.rs
Normal file
|
@ -0,0 +1,23 @@
|
|||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
#[sea_orm(table_name = "session")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub id: String,
|
||||
pub token: String,
|
||||
pub user: String,
|
||||
pub issued: DateTime,
|
||||
pub expiry: DateTime,
|
||||
pub device: String,
|
||||
#[sea_orm(column_type = "custom(\"inet\")")]
|
||||
pub ip: String,
|
||||
pub last_usage: Option<DateTime>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
|
@ -1 +1 @@
|
|||
pub mod entities;
|
||||
pub mod entities;
|
||||
|
|
Loading…
Add table
Reference in a new issue