From 78711ae4cb6fd73b4649580ec7a3a1c72a0aff2b Mon Sep 17 00:00:00 2001 From: fish <2913921008@qq.com> Date: Sun, 3 Dec 2023 12:53:20 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E5=88=9D=E6=AD=A5=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E6=95=B0=E6=8D=AE=E6=BA=90=E5=8F=AF=E8=A7=86=E5=8C=BA?= =?UTF-8?q?=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/sql/datasource_config/create.rs | 1 + .../src/sql/datasource_config/retrieve.rs | 1 + .../m20231115_135841_add_visual.rs | 28 +++++++++++++++++++ .../src/fetcher_datasource_config/mod.rs | 2 ++ .../checkers/datasource_config_data.rs | 5 +++- .../fetcher/datasource_config/checkers/mod.rs | 4 +-- .../checkers/unique_key_checker.rs | 3 ++ .../models/model_datasource_config.rs | 4 ++- script/new-sql_migrate.py | 2 +- 9 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 persistence/migrate/sql-migration/src/fetcher_datasource_config/m20231115_135841_add_visual.rs diff --git a/persistence/dao/fetcher/src/sql/datasource_config/create.rs b/persistence/dao/fetcher/src/sql/datasource_config/create.rs index b54e7ea9e..d50a84562 100644 --- a/persistence/dao/fetcher/src/sql/datasource_config/create.rs +++ b/persistence/dao/fetcher/src/sql/datasource_config/create.rs @@ -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, diff --git a/persistence/dao/fetcher/src/sql/datasource_config/retrieve.rs b/persistence/dao/fetcher/src/sql/datasource_config/retrieve.rs index 82661ae58..c74c50078 100644 --- a/persistence/dao/fetcher/src/sql/datasource_config/retrieve.rs +++ b/persistence/dao/fetcher/src/sql/datasource_config/retrieve.rs @@ -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::() .all(db) .await?; diff --git a/persistence/migrate/sql-migration/src/fetcher_datasource_config/m20231115_135841_add_visual.rs b/persistence/migrate/sql-migration/src/fetcher_datasource_config/m20231115_135841_add_visual.rs new file mode 100644 index 000000000..95e59e36d --- /dev/null +++ b/persistence/migrate/sql-migration/src/fetcher_datasource_config/m20231115_135841_add_visual.rs @@ -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(()) + } +} diff --git a/persistence/migrate/sql-migration/src/fetcher_datasource_config/mod.rs b/persistence/migrate/sql-migration/src/fetcher_datasource_config/mod.rs index aa6db629e..6b73b9800 100644 --- a/persistence/migrate/sql-migration/src/fetcher_datasource_config/mod.rs +++ b/persistence/migrate/sql-migration/src/fetcher_datasource_config/mod.rs @@ -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; diff --git a/persistence/models/sql-models/src/fetcher/datasource_config/checkers/datasource_config_data.rs b/persistence/models/sql-models/src/fetcher/datasource_config/checkers/datasource_config_data.rs index 21dad486c..191c118c5 100644 --- a/persistence/models/sql-models/src/fetcher/datasource_config/checkers/datasource_config_data.rs +++ b/persistence/models/sql-models/src/fetcher/datasource_config/checkers/datasource_config_data.rs @@ -24,7 +24,7 @@ use crate::{ }; #[check_obj( - uncheck = FetcherDatasourceConfigUncheck, + uncheck = FetcherqqDatasourceConfigUncheck, checked = PreCheckFetcherDatasourceConfig, error = CheckError )] @@ -38,6 +38,7 @@ pub struct PreCheckFetcherDatasourceConfigChecker { pub unique_key: OptionChecker>, pub config: NoCheck>, pub jump_url: OptionChecker, + pub visual: NoCheck } pub type FetcherDatasourceConfigChecker = PostChecker< @@ -60,6 +61,7 @@ impl IntoActiveModel 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); @@ -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 diff --git a/persistence/models/sql-models/src/fetcher/datasource_config/checkers/mod.rs b/persistence/models/sql-models/src/fetcher/datasource_config/checkers/mod.rs index 576067f30..44ed7138c 100644 --- a/persistence/models/sql-models/src/fetcher/datasource_config/checkers/mod.rs +++ b/persistence/models/sql-models/src/fetcher/datasource_config/checkers/mod.rs @@ -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; diff --git a/persistence/models/sql-models/src/fetcher/datasource_config/checkers/unique_key_checker.rs b/persistence/models/sql-models/src/fetcher/datasource_config/checkers/unique_key_checker.rs index f72e3b971..665724256 100644 --- a/persistence/models/sql-models/src/fetcher/datasource_config/checkers/unique_key_checker.rs +++ b/persistence/models/sql-models/src/fetcher/datasource_config/checkers/unique_key_checker.rs @@ -18,6 +18,7 @@ pub struct PreCheckFetcherDatasourceConfig { unique_key: Option, config: Map, jump_url: Option, + visual: bool } #[derive(Debug, TypedBuilder)] @@ -30,6 +31,7 @@ pub struct FetcherDatasourceConfig { pub unique_key: DatasourceUnique, pub config: Map, pub jump_url: Option, + pub visual: bool, } pub struct UniqueKeyChecker; @@ -79,6 +81,7 @@ impl Checker for UniqueKeyChecker { .nickname(uncheck.nickname) .unique_key(unique) .jump_url(uncheck.jump_url) + .visual(uncheck.visual) .build() }), ) diff --git a/persistence/models/sql-models/src/fetcher/datasource_config/models/model_datasource_config.rs b/persistence/models/sql-models/src/fetcher/datasource_config/models/model_datasource_config.rs index 7778e071d..dd0053f13 100644 --- a/persistence/models/sql-models/src/fetcher/datasource_config/models/model_datasource_config.rs +++ b/persistence/models/sql-models/src/fetcher/datasource_config/models/model_datasource_config.rs @@ -43,7 +43,7 @@ use crate::{ none( name = "DatasourceId", extra(derive(sea_orm::FromQueryResult), doc = "取得数据源对应id") - ) + ), )] pub struct Model { /// 平台type @@ -92,6 +92,8 @@ pub struct Model { /// 数据源跳转链接 #[sub_model(want("FrontendDatasource"))] pub jump_url: Option, + /// 数据源可见性 + pub visual: bool, } #[derive(Debug, Clone, Copy, EnumIter)] diff --git a/script/new-sql_migrate.py b/script/new-sql_migrate.py index 147457137..703ba87d8 100644 --- a/script/new-sql_migrate.py +++ b/script/new-sql_migrate.py @@ -17,7 +17,7 @@ } } """ -migrate_dir = "./migrate/sql-migration" +migrate_dir = "./persistence/migrate/sql-migration" # migrate dir