fix: add basic auth and oidc auth
This commit is contained in:
@@ -107,6 +107,16 @@ pub enum Downloaders {
|
||||
SavePath,
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
pub enum Auth {
|
||||
Table,
|
||||
Id,
|
||||
Pid,
|
||||
SubscriberId,
|
||||
AvatarUrl,
|
||||
AuthType,
|
||||
}
|
||||
|
||||
macro_rules! create_postgres_enum_for_active_enum {
|
||||
($manager: expr, $active_enum: expr, $($enum_value:expr),+) => {
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ use super::defs::{
|
||||
Bangumi, CustomSchemaManagerExt, Episodes, GeneralIds, Subscribers, Subscriptions,
|
||||
};
|
||||
use crate::models::{
|
||||
subscribers::ROOT_SUBSCRIBER,
|
||||
subscribers::SEED_SUBSCRIBER,
|
||||
subscriptions::{self, SubscriptionCategoryEnum},
|
||||
};
|
||||
|
||||
@@ -40,7 +40,7 @@ impl MigrationTrait for Migration {
|
||||
let insert = Query::insert()
|
||||
.into_table(Subscribers::Table)
|
||||
.columns([Subscribers::Pid, Subscribers::DisplayName])
|
||||
.values_panic([ROOT_SUBSCRIBER.into(), ROOT_SUBSCRIBER.into()])
|
||||
.values_panic([SEED_SUBSCRIBER.into(), SEED_SUBSCRIBER.into()])
|
||||
.to_owned();
|
||||
manager.exec_stmt(insert).await?;
|
||||
|
||||
|
||||
83
apps/recorder/src/migrations/m20241231_000001_auth.rs
Normal file
83
apps/recorder/src/migrations/m20241231_000001_auth.rs
Normal file
@@ -0,0 +1,83 @@
|
||||
use sea_orm_migration::{prelude::*, schema::*};
|
||||
|
||||
use super::defs::Auth;
|
||||
use crate::{
|
||||
migrations::defs::{CustomSchemaManagerExt, GeneralIds, Subscribers},
|
||||
models::auth::{AuthType, AuthTypeEnum},
|
||||
};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
create_postgres_enum_for_active_enum!(
|
||||
manager,
|
||||
AuthTypeEnum,
|
||||
AuthType::Basic,
|
||||
AuthType::Oidc
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_table(
|
||||
table_auto(Auth::Table)
|
||||
.col(pk_auto(Auth::Id))
|
||||
.col(text(Auth::Pid))
|
||||
.col(enumeration(
|
||||
Auth::AuthType,
|
||||
AuthTypeEnum,
|
||||
AuthType::iden_values(),
|
||||
))
|
||||
.col(string_null(Auth::AvatarUrl))
|
||||
.col(integer(Auth::SubscriberId))
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk_auth_subscriber_id")
|
||||
.from_tbl(Auth::Table)
|
||||
.from_col(Auth::SubscriberId)
|
||||
.to_tbl(Subscribers::Table)
|
||||
.to_col(Subscribers::Id)
|
||||
.on_delete(ForeignKeyAction::Cascade)
|
||||
.on_update(ForeignKeyAction::Restrict),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.name("idx_auth_pid_auth_type")
|
||||
.unique()
|
||||
.table(Auth::Table)
|
||||
.col(Auth::Pid)
|
||||
.col(Auth::AuthType)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_postgres_auto_update_ts_trigger_for_col(Auth::Table, GeneralIds::UpdatedAt)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_postgres_auto_update_ts_trigger_for_col(Auth::Table, GeneralIds::UpdatedAt)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_table(Table::drop().table(Auth::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_postgres_enum_for_active_enum(AuthTypeEnum)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ pub mod defs;
|
||||
pub mod m20220101_000001_init;
|
||||
pub mod m20240224_082543_add_downloads;
|
||||
pub mod m20240225_060853_subscriber_add_downloader;
|
||||
pub mod m20241231_000001_auth;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
@@ -15,6 +16,7 @@ impl MigratorTrait for Migrator {
|
||||
Box::new(m20220101_000001_init::Migration),
|
||||
Box::new(m20240224_082543_add_downloads::Migration),
|
||||
Box::new(m20240225_060853_subscriber_add_downloader::Migration),
|
||||
Box::new(m20241231_000001_auth::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user