Merge pull request #10 from EETagent/session_entity

Session entity
This commit is contained in:
Sebastian Pravda 2022-10-25 18:56:20 +02:00 committed by GitHub
commit ef594e8227
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 69 additions and 0 deletions

View file

@ -3,3 +3,4 @@ pub mod prelude;
pub mod admin;
pub mod candidate;
pub mod parent;
pub mod session;

View file

@ -3,3 +3,4 @@
pub use super::admin::Entity as Admin;
pub use super::candidate::Entity as Candidate;
pub use super::parent::Entity as Parent;
pub use super::session::Entity as Session;

19
entity/src/session.rs Normal file
View file

@ -0,0 +1,19 @@
//! SeaORM Entity. Generated by sea-orm-codegen 0.9.3
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "session")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub hashed_token: String,
pub user_id: i32,
pub created_at: DateTime,
pub updated_at: DateTime,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}

View file

@ -4,6 +4,7 @@ mod m20221024_111310_create_admin;
mod m20221024_121621_create_candidate;
mod m20221024_124701_create_parent;
mod m20221024_134454_fill_admin;
mod m20221025_154422_create_session;
pub struct Migrator;
@ -15,6 +16,7 @@ impl MigratorTrait for Migrator {
Box::new(m20221024_121621_create_candidate::Migration),
Box::new(m20221024_124701_create_parent::Migration),
Box::new(m20221024_134454_fill_admin::Migration::default()),
Box::new(m20221025_154422_create_session::Migration),
]
}
}

View file

@ -0,0 +1,46 @@
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)
.uuid()
.not_null()
.unique_key()
.primary_key(),
)
.col(ColumnDef::new(Session::HashedToken).string().not_null())
.col(ColumnDef::new(Session::UserId).integer().not_null())
.col(ColumnDef::new(Session::CreatedAt).date_time().not_null())
.col(ColumnDef::new(Session::UpdatedAt).date_time().not_null())
.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,
HashedToken,
UserId,
CreatedAt,
UpdatedAt
}