From 8fd6dbb68b5ee610481740e8a7207e12322d3acd Mon Sep 17 00:00:00 2001 From: ZhenYi <434836402@qq.com> Date: Thu, 14 May 2026 10:02:07 +0800 Subject: [PATCH] refactor(migrate,models): apply rustfmt formatting --- libs/migrate/lib.rs | 6 +++- libs/migrate/room_compact_summary.rs | 31 +++++++++++++++++++ libs/migrate/sql/room_compact_summary.sql | 16 ++++++++++ libs/models/ai/ai_conversation.rs | 4 +-- libs/models/ai/ai_message.rs | 4 +-- libs/models/ai/ai_message_fork.rs | 4 +-- libs/models/ai/ai_shared_conversation.rs | 4 +-- libs/models/ai/ai_token_usage.rs | 4 +-- libs/models/ai/billing_error.rs | 2 +- libs/models/ai/mod.rs | 2 +- libs/models/ai/subscription.rs | 2 +- .../projects/project_context_setting.rs | 6 ++-- libs/models/rooms/mod.rs | 2 +- libs/models/rooms/room_access.rs | 2 +- libs/models/rooms/room_message.rs | 2 +- libs/models/rooms/room_user_state.rs | 2 +- libs/models/users/mod.rs | 4 +-- libs/models/users/user_billing.rs | 2 +- 18 files changed, 69 insertions(+), 30 deletions(-) create mode 100644 libs/migrate/room_compact_summary.rs create mode 100644 libs/migrate/sql/room_compact_summary.sql diff --git a/libs/migrate/lib.rs b/libs/migrate/lib.rs index df371ca..56a6008 100644 --- a/libs/migrate/lib.rs +++ b/libs/migrate/lib.rs @@ -40,8 +40,12 @@ pub struct Migrator; #[async_trait::async_trait] impl MigratorTrait for Migrator { fn migrations() -> Vec> { - vec![Box::new(init::Migration)] + vec![ + Box::new(init::Migration), + Box::new(room_compact_summary::Migration), + ] } } pub mod init; +pub mod room_compact_summary; diff --git a/libs/migrate/room_compact_summary.rs b/libs/migrate/room_compact_summary.rs new file mode 100644 index 0000000..fb51888 --- /dev/null +++ b/libs/migrate/room_compact_summary.rs @@ -0,0 +1,31 @@ +use sea_orm_migration::prelude::*; + +pub struct Migration; + +impl MigrationName for Migration { + fn name(&self) -> &str { + "room_compact_summary" + } +} + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + let sql = include_str!("sql/room_compact_summary.sql"); + super::execute_sql(manager, sql).await?; + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .get_connection() + .execute_unprepared( + r#" +DROP INDEX IF EXISTS idx_room_compact_summary_room_to_seq; +DROP TABLE IF EXISTS room_compact_summary; +"#, + ) + .await?; + Ok(()) + } +} diff --git a/libs/migrate/sql/room_compact_summary.sql b/libs/migrate/sql/room_compact_summary.sql new file mode 100644 index 0000000..51dbcad --- /dev/null +++ b/libs/migrate/sql/room_compact_summary.sql @@ -0,0 +1,16 @@ +CREATE TABLE IF NOT EXISTS room_compact_summary +( + id uuid NOT NULL + PRIMARY KEY, + room uuid NOT NULL, + from_seq bigint NOT NULL, + to_seq bigint NOT NULL, + summary text NOT NULL, + message_count integer NOT NULL, + source_message_ids jsonb DEFAULT '[]'::jsonb NOT NULL, + created_at timestamp with time zone NOT NULL, + updated_at timestamp with time zone NOT NULL +); + +CREATE INDEX IF NOT EXISTS idx_room_compact_summary_room_to_seq + ON room_compact_summary (room, to_seq DESC); diff --git a/libs/models/ai/ai_conversation.rs b/libs/models/ai/ai_conversation.rs index d5742e8..c8e35db 100644 --- a/libs/models/ai/ai_conversation.rs +++ b/libs/models/ai/ai_conversation.rs @@ -2,9 +2,7 @@ use crate::{DateTimeUtc, ProjectId, UserId}; use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; -#[derive( - Clone, Debug, PartialEq, Eq, Serialize, Deserialize, DeriveEntityModel, -)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, DeriveEntityModel)] #[sea_orm(table_name = "ai_conversation")] pub struct Model { #[sea_orm(primary_key)] diff --git a/libs/models/ai/ai_message.rs b/libs/models/ai/ai_message.rs index b02dda9..97b07a1 100644 --- a/libs/models/ai/ai_message.rs +++ b/libs/models/ai/ai_message.rs @@ -2,9 +2,7 @@ use crate::{DateTimeUtc, Uuid}; use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; -#[derive( - Clone, Debug, PartialEq, Eq, Serialize, Deserialize, DeriveEntityModel, -)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, DeriveEntityModel)] #[sea_orm(table_name = "ai_message")] pub struct Model { #[sea_orm(primary_key)] diff --git a/libs/models/ai/ai_message_fork.rs b/libs/models/ai/ai_message_fork.rs index 1f867b0..1d913e5 100644 --- a/libs/models/ai/ai_message_fork.rs +++ b/libs/models/ai/ai_message_fork.rs @@ -3,9 +3,7 @@ use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; use uuid::Uuid; -#[derive( - Clone, Debug, PartialEq, Eq, Serialize, Deserialize, DeriveEntityModel, -)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, DeriveEntityModel)] #[sea_orm(table_name = "ai_message_fork")] pub struct Model { #[sea_orm(primary_key)] diff --git a/libs/models/ai/ai_shared_conversation.rs b/libs/models/ai/ai_shared_conversation.rs index f4d0244..5ffb8b4 100644 --- a/libs/models/ai/ai_shared_conversation.rs +++ b/libs/models/ai/ai_shared_conversation.rs @@ -2,9 +2,7 @@ use crate::{DateTimeUtc, UserId}; use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; -#[derive( - Clone, Debug, PartialEq, Eq, Serialize, Deserialize, DeriveEntityModel, -)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, DeriveEntityModel)] #[sea_orm(table_name = "ai_shared_conversation")] pub struct Model { #[sea_orm(primary_key)] diff --git a/libs/models/ai/ai_token_usage.rs b/libs/models/ai/ai_token_usage.rs index a46f201..e090b7e 100644 --- a/libs/models/ai/ai_token_usage.rs +++ b/libs/models/ai/ai_token_usage.rs @@ -2,9 +2,7 @@ use crate::{DateTimeUtc, UserId}; use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; -#[derive( - Clone, Debug, PartialEq, Eq, Serialize, Deserialize, DeriveEntityModel, -)] +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, DeriveEntityModel)] #[sea_orm(table_name = "ai_token_usage")] pub struct Model { #[sea_orm(primary_key)] diff --git a/libs/models/ai/billing_error.rs b/libs/models/ai/billing_error.rs index a21342e..562d847 100644 --- a/libs/models/ai/billing_error.rs +++ b/libs/models/ai/billing_error.rs @@ -30,4 +30,4 @@ pub struct Model { #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation {} -impl ActiveModelBehavior for ActiveModel {} \ No newline at end of file +impl ActiveModelBehavior for ActiveModel {} diff --git a/libs/models/ai/mod.rs b/libs/models/ai/mod.rs index de0b4c9..ce56af2 100644 --- a/libs/models/ai/mod.rs +++ b/libs/models/ai/mod.rs @@ -50,8 +50,8 @@ pub mod ai_message; pub mod ai_message_fork; pub mod ai_session; pub mod ai_shared_conversation; +pub mod ai_token_usage; pub mod ai_tool_auth; pub mod ai_tool_call; -pub mod ai_token_usage; pub mod billing_error; pub mod subscription; diff --git a/libs/models/ai/subscription.rs b/libs/models/ai/subscription.rs index abf1897..b2ff856 100644 --- a/libs/models/ai/subscription.rs +++ b/libs/models/ai/subscription.rs @@ -60,4 +60,4 @@ pub struct Model { #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation {} -impl ActiveModelBehavior for ActiveModel {} \ No newline at end of file +impl ActiveModelBehavior for ActiveModel {} diff --git a/libs/models/projects/project_context_setting.rs b/libs/models/projects/project_context_setting.rs index 19fcfd6..e3cd348 100644 --- a/libs/models/projects/project_context_setting.rs +++ b/libs/models/projects/project_context_setting.rs @@ -4,9 +4,7 @@ use serde::{Deserialize, Serialize}; /// Project-level context management settings. /// Controls compaction (sliding window) and RAG behavior. -#[derive( - Clone, Debug, PartialEq, Serialize, Deserialize, DeriveEntityModel, -)] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, DeriveEntityModel)] #[sea_orm(table_name = "project_context_setting")] pub struct Model { #[sea_orm(primary_key)] @@ -35,4 +33,4 @@ pub struct Model { #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] pub enum Relation {} -impl ActiveModelBehavior for ActiveModel {} \ No newline at end of file +impl ActiveModelBehavior for ActiveModel {} diff --git a/libs/models/rooms/mod.rs b/libs/models/rooms/mod.rs index d9e256d..af5689d 100644 --- a/libs/models/rooms/mod.rs +++ b/libs/models/rooms/mod.rs @@ -106,4 +106,4 @@ pub mod room_message_reaction; pub mod room_notifications; pub mod room_pin; pub mod room_thread; -pub mod room_user_state; \ No newline at end of file +pub mod room_user_state; diff --git a/libs/models/rooms/room_access.rs b/libs/models/rooms/room_access.rs index 15e1869..6f16482 100644 --- a/libs/models/rooms/room_access.rs +++ b/libs/models/rooms/room_access.rs @@ -31,4 +31,4 @@ impl Related for Entity { } } -impl ActiveModelBehavior for ActiveModel {} \ No newline at end of file +impl ActiveModelBehavior for ActiveModel {} diff --git a/libs/models/rooms/room_message.rs b/libs/models/rooms/room_message.rs index 852bf2e..9c9dc81 100644 --- a/libs/models/rooms/room_message.rs +++ b/libs/models/rooms/room_message.rs @@ -57,4 +57,4 @@ impl Related for Entity { } } -impl ActiveModelBehavior for ActiveModel {} \ No newline at end of file +impl ActiveModelBehavior for ActiveModel {} diff --git a/libs/models/rooms/room_user_state.rs b/libs/models/rooms/room_user_state.rs index a1420cf..a5abb4d 100644 --- a/libs/models/rooms/room_user_state.rs +++ b/libs/models/rooms/room_user_state.rs @@ -37,4 +37,4 @@ impl Related for Entity { } } -impl ActiveModelBehavior for ActiveModel {} \ No newline at end of file +impl ActiveModelBehavior for ActiveModel {} diff --git a/libs/models/users/mod.rs b/libs/models/users/mod.rs index ee57e5a..8582df6 100644 --- a/libs/models/users/mod.rs +++ b/libs/models/users/mod.rs @@ -1,6 +1,7 @@ pub use user::Entity as User; pub use user_2fa::Entity as User2fa; pub use user_activity_log::Entity as UserActivityLog; +pub use user_billing::Entity as UserBilling; pub use user_email::Entity as UserEmail; pub use user_email_change::Entity as UserEmailChange; pub use user_notification::Entity as UserNotification; @@ -10,11 +11,11 @@ pub use user_preferences::Entity as UserPreferences; pub use user_relation::Entity as UserRelation; pub use user_ssh_key::Entity as UserSshKey; pub use user_token::Entity as UserToken; -pub use user_billing::Entity as UserBilling; pub mod user; pub mod user_2fa; pub mod user_activity_log; +pub mod user_billing; pub mod user_email; pub mod user_email_change; pub mod user_notification; @@ -24,4 +25,3 @@ pub mod user_preferences; pub mod user_relation; pub mod user_ssh_key; pub mod user_token; -pub mod user_billing; diff --git a/libs/models/users/user_billing.rs b/libs/models/users/user_billing.rs index 44aadd2..a268147 100644 --- a/libs/models/users/user_billing.rs +++ b/libs/models/users/user_billing.rs @@ -43,4 +43,4 @@ impl Related for Entity { } } -impl ActiveModelBehavior for ActiveModel {} \ No newline at end of file +impl ActiveModelBehavior for ActiveModel {}