feat: add permission control
This commit is contained in:
@@ -16,7 +16,6 @@ pub enum GeneralIds {
|
||||
pub enum Subscribers {
|
||||
Table,
|
||||
Id,
|
||||
Pid,
|
||||
DisplayName,
|
||||
DownloaderId,
|
||||
BangumiConf,
|
||||
@@ -58,6 +57,7 @@ pub enum Bangumi {
|
||||
pub enum SubscriptionBangumi {
|
||||
Table,
|
||||
Id,
|
||||
SubscriberId,
|
||||
SubscriptionId,
|
||||
BangumiId,
|
||||
}
|
||||
@@ -90,6 +90,7 @@ pub enum Episodes {
|
||||
pub enum SubscriptionEpisode {
|
||||
Table,
|
||||
Id,
|
||||
SubscriberId,
|
||||
SubscriptionId,
|
||||
EpisodeId,
|
||||
}
|
||||
@@ -130,7 +131,6 @@ pub enum Auth {
|
||||
Id,
|
||||
Pid,
|
||||
SubscriberId,
|
||||
AvatarUrl,
|
||||
AuthType,
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ impl MigrationTrait for Migration {
|
||||
.create_table(
|
||||
table_auto(Subscribers::Table)
|
||||
.col(pk_auto(Subscribers::Id))
|
||||
.col(string_len_uniq(Subscribers::Pid, 64))
|
||||
.col(string(Subscribers::DisplayName))
|
||||
.col(json_binary_null(Subscribers::BangumiConf))
|
||||
.to_owned(),
|
||||
@@ -42,8 +41,8 @@ impl MigrationTrait for Migration {
|
||||
.exec_stmt(
|
||||
Query::insert()
|
||||
.into_table(Subscribers::Table)
|
||||
.columns([Subscribers::Pid, Subscribers::DisplayName])
|
||||
.values_panic([SEED_SUBSCRIBER.into(), SEED_SUBSCRIBER.into()])
|
||||
.columns([Subscribers::DisplayName])
|
||||
.values_panic([SEED_SUBSCRIBER.into()])
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
@@ -159,6 +158,7 @@ impl MigrationTrait for Migration {
|
||||
.create_table(
|
||||
table_auto(SubscriptionBangumi::Table)
|
||||
.col(pk_auto(SubscriptionBangumi::Id))
|
||||
.col(integer(SubscriptionBangumi::SubscriberId))
|
||||
.col(integer(SubscriptionBangumi::SubscriptionId))
|
||||
.col(integer(SubscriptionBangumi::BangumiId))
|
||||
.foreign_key(
|
||||
@@ -193,6 +193,17 @@ impl MigrationTrait for Migration {
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.if_not_exists()
|
||||
.name("index_subscription_bangumi_subscriber_id")
|
||||
.table(SubscriptionBangumi::Table)
|
||||
.col(SubscriptionBangumi::SubscriberId)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_table(
|
||||
table_auto(Episodes::Table)
|
||||
@@ -268,6 +279,7 @@ impl MigrationTrait for Migration {
|
||||
.col(pk_auto(SubscriptionEpisode::Id))
|
||||
.col(integer(SubscriptionEpisode::SubscriptionId))
|
||||
.col(integer(SubscriptionEpisode::EpisodeId))
|
||||
.col(integer(SubscriptionEpisode::SubscriberId))
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
.name("fk_subscription_episode_subscription_id")
|
||||
@@ -300,10 +312,31 @@ impl MigrationTrait for Migration {
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.create_index(
|
||||
Index::create()
|
||||
.if_not_exists()
|
||||
.name("index_subscription_episode_subscriber_id")
|
||||
.table(SubscriptionEpisode::Table)
|
||||
.col(SubscriptionEpisode::SubscriberId)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.drop_index(
|
||||
Index::drop()
|
||||
.if_exists()
|
||||
.name("index_subscription_episode_subscriber_id")
|
||||
.table(SubscriptionBangumi::Table)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_table(Table::drop().table(SubscriptionEpisode::Table).to_owned())
|
||||
.await?;
|
||||
@@ -316,6 +349,16 @@ impl MigrationTrait for Migration {
|
||||
.drop_table(Table::drop().table(Episodes::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_index(
|
||||
Index::drop()
|
||||
.if_exists()
|
||||
.name("index_subscription_bangumi_subscriber_id")
|
||||
.table(SubscriptionBangumi::Table)
|
||||
.to_owned(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
manager
|
||||
.drop_table(Table::drop().table(SubscriptionBangumi::Table).to_owned())
|
||||
.await?;
|
||||
|
||||
@@ -2,13 +2,13 @@ use sea_orm_migration::{prelude::*, schema::*};
|
||||
|
||||
use crate::{
|
||||
migrations::defs::{CustomSchemaManagerExt, Downloaders, GeneralIds, Subscribers},
|
||||
models::{downloaders::DownloaderCategoryEnum, prelude::DownloaderCategory},
|
||||
models::downloaders::{DownloaderCategory, DownloaderCategoryEnum},
|
||||
};
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait]
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
create_postgres_enum_for_active_enum!(
|
||||
|
||||
@@ -34,7 +34,6 @@ impl MigrationTrait for Migration {
|
||||
AuthTypeEnum,
|
||||
AuthType::iden_values(),
|
||||
))
|
||||
.col(string_null(Auth::AvatarUrl))
|
||||
.col(integer(Auth::SubscriberId))
|
||||
.foreign_key(
|
||||
ForeignKey::create()
|
||||
@@ -66,6 +65,20 @@ impl MigrationTrait for Migration {
|
||||
.create_postgres_auto_update_ts_trigger_for_col(Auth::Table, GeneralIds::UpdatedAt)
|
||||
.await?;
|
||||
|
||||
let seed_subscriber_id = manager
|
||||
.get_connection()
|
||||
.query_one(
|
||||
manager.get_database_backend().build(
|
||||
Query::select()
|
||||
.column(Subscribers::Id)
|
||||
.from(Subscribers::Table)
|
||||
.limit(1),
|
||||
),
|
||||
)
|
||||
.await?
|
||||
.ok_or_else(|| DbErr::RecordNotFound(String::from("seed subscriber not found")))?
|
||||
.try_get_by_index::<i32>(0)?;
|
||||
|
||||
manager
|
||||
.exec_stmt(
|
||||
Query::insert()
|
||||
@@ -74,7 +87,7 @@ impl MigrationTrait for Migration {
|
||||
.values_panic([
|
||||
SEED_SUBSCRIBER.into(),
|
||||
SimpleExpr::from(AuthType::Basic).as_enum(AuthTypeEnum),
|
||||
1.into(),
|
||||
seed_subscriber_id.into(),
|
||||
])
|
||||
.to_owned(),
|
||||
)
|
||||
|
||||
@@ -5,6 +5,7 @@ pub use sea_orm_migration::prelude::*;
|
||||
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 {
|
||||
vec![
|
||||
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