2024-03-23 05:01:45 +01:00
|
|
|
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(Credentials::Table)
|
|
|
|
.col(
|
|
|
|
ColumnDef::new(Credentials::Id)
|
|
|
|
.string()
|
|
|
|
.not_null()
|
|
|
|
.primary_key()
|
|
|
|
)
|
2024-03-24 04:03:22 +01:00
|
|
|
.col(ColumnDef::new(Credentials::Email).string().not_null())
|
|
|
|
.col(ColumnDef::new(Credentials::Password).string().not_null())
|
|
|
|
.to_owned()
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
manager
|
|
|
|
.create_table(
|
|
|
|
Table::create()
|
|
|
|
.table(Sessions::Table)
|
|
|
|
.col(
|
|
|
|
ColumnDef::new(Sessions::Id)
|
2024-03-25 01:58:06 +01:00
|
|
|
.string()
|
2024-03-24 04:03:22 +01:00
|
|
|
.not_null()
|
|
|
|
.primary_key()
|
|
|
|
)
|
|
|
|
.col(ColumnDef::new(Sessions::Actor).string().not_null())
|
|
|
|
.col(ColumnDef::new(Sessions::Expires).date_time().not_null())
|
2024-03-23 05:01:45 +01:00
|
|
|
.to_owned()
|
|
|
|
)
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
|
|
manager
|
|
|
|
.drop_table(Table::drop().table(Credentials::Table).to_owned())
|
|
|
|
.await?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(DeriveIden)]
|
|
|
|
enum Credentials {
|
|
|
|
Table,
|
|
|
|
Id,
|
|
|
|
Email,
|
|
|
|
Password,
|
|
|
|
}
|
2024-03-24 04:03:22 +01:00
|
|
|
|
|
|
|
#[derive(DeriveIden)]
|
|
|
|
enum Sessions {
|
|
|
|
Table,
|
2024-03-25 01:58:06 +01:00
|
|
|
Id, // TODO here ID is the session "secret" but in Credentials it's the actor ID (String) ??? weird!!
|
2024-03-24 04:03:22 +01:00
|
|
|
Actor,
|
|
|
|
Expires,
|
|
|
|
}
|