Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ 初步实现数据源可视区分 #172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ impl DatasourceOperate<'_, NoConnect> {
datasource.avatar = config.avatar.to_string(),
datasouce.config = ?config.config,
datasouce.jump_url = ?config.jump_url,
datasouce.visual = ?config.visual,
);
match Self::find_delete_model_by_datasource_and_unique_key(
db,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ where
.column(Column::Datasource)
.column(Column::DbUniqueKey)
.filter(Column::DeleteAt.eq(get_zero_data_time()))
.filter(Column::Visual.eq(true))
.into_model::<FrontendDatasource>()
.all(db)
.await?;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

use sea_orm_migration::prelude::*;

use super::FetcherDatasourceConfig;

pub struct Migration;
impl MigrationName for Migration {
fn name(&self) -> &str { "m20231115_135841_fetcher_datasource_config_add_visual" }
}
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let mut al = sea_query::Table::alter();
al.table(FetcherDatasourceConfig::Table).add_column(
ColumnDef::new(FetcherDatasourceConfig::Visual).boolean().not_null().default(true),
);
manager.alter_table(al).await?;
Ok(())
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let mut al = sea_query::Table::alter();
al.table(FetcherDatasourceConfig::Table)
.drop_column(FetcherDatasourceConfig::Visual);
manager.alter_table(al).await?;
Ok(())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ enum FetcherDatasourceConfig {
DbUniqueKey,
DeleteAt,
JumpUrl,
Visual,
}
pub mod m20221231_200206_alter_nickname;
pub mod m20230217_135012_add_sort_detele;
pub mod m20230528_110010_add_jump_url;
pub mod m20231115_135841_add_visual;
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{
};

#[check_obj(
uncheck = FetcherDatasourceConfigUncheck,
uncheck = FetcherqqDatasourceConfigUncheck,
checked = PreCheckFetcherDatasourceConfig,
error = CheckError
)]
Expand All @@ -38,6 +38,7 @@ pub struct PreCheckFetcherDatasourceConfigChecker {
pub unique_key: OptionChecker<NoCheck<String>>,
pub config: NoCheck<Map<String, Value>>,
pub jump_url: OptionChecker<UrlChecker>,
pub visual: NoCheck<bool>
}

pub type FetcherDatasourceConfigChecker = PostChecker<
Expand All @@ -60,6 +61,7 @@ impl IntoActiveModel<ActiveModel> for FetcherDatasourceConfig {
.expect_or_log("config为非法json格式")),
db_unique_key: Set(self.unique_key),
jump_url: Set(self.jump_url.map(|url| url.to_string())),
visual: Set(self.visual),
..Default::default()
};
active.id.set_optional(self.id);
Expand Down Expand Up @@ -91,6 +93,7 @@ impl Model {
db_unique_key: Set(self.db_unique_key),
delete_at: Set(self.delete_at),
jump_url: Set(new_model.jump_url.map(|url| url.to_string())),
visual: Set(self.visual),
};
active.soft_recover();
active
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::convert::Infallible;

pub use datasource_config_data::{
FetcherDatasourceConfigChecker, FetcherDatasourceConfigUncheck,
};
pub use datasource_config_data::FetcherqqDatasourceConfigUncheck;
use status_err::{ErrPrefix, StatusErr};
use thiserror::Error;
pub use unique_key::DatasourceUnique;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub struct PreCheckFetcherDatasourceConfig {
unique_key: Option<String>,
config: Map<String, Value>,
jump_url: Option<Url>,
visual: bool
}

#[derive(Debug, TypedBuilder)]
Expand All @@ -30,6 +31,7 @@ pub struct FetcherDatasourceConfig {
pub unique_key: DatasourceUnique,
pub config: Map<String, Value>,
pub jump_url: Option<Url>,
pub visual: bool,
}

pub struct UniqueKeyChecker;
Expand Down Expand Up @@ -79,6 +81,7 @@ impl Checker for UniqueKeyChecker {
.nickname(uncheck.nickname)
.unique_key(unique)
.jump_url(uncheck.jump_url)
.visual(uncheck.visual)
.build()
}),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use crate::{
none(
name = "DatasourceId",
extra(derive(sea_orm::FromQueryResult), doc = "取得数据源对应id")
)
),
)]
pub struct Model {
/// 平台type
Expand Down Expand Up @@ -92,6 +92,8 @@ pub struct Model {
/// 数据源跳转链接
#[sub_model(want("FrontendDatasource"))]
pub jump_url: Option<String>,
/// 数据源可见性
pub visual: bool,
}

#[derive(Debug, Clone, Copy, EnumIter)]
Expand Down
2 changes: 1 addition & 1 deletion script/new-sql_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
}
"""
migrate_dir = "./migrate/sql-migration"
migrate_dir = "./persistence/migrate/sql-migration"

# migrate dir

Expand Down
Loading