From db2e6197bedec45aa1456980122743135ca878ac Mon Sep 17 00:00:00 2001 From: Sebastian Pravda Date: Tue, 25 Oct 2022 18:46:48 +0200 Subject: [PATCH] fix: missing files --- entity/src/session.rs | 19 ++++++++ .../src/m20221025_154422_create_session.rs | 46 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 entity/src/session.rs create mode 100644 migration/src/m20221025_154422_create_session.rs diff --git a/entity/src/session.rs b/entity/src/session.rs new file mode 100644 index 0000000..2df872b --- /dev/null +++ b/entity/src/session.rs @@ -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 {} diff --git a/migration/src/m20221025_154422_create_session.rs b/migration/src/m20221025_154422_create_session.rs new file mode 100644 index 0000000..d7931f0 --- /dev/null +++ b/migration/src/m20221025_154422_create_session.rs @@ -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 +}