refactor(migrate,models): apply rustfmt formatting

This commit is contained in:
ZhenYi 2026-05-14 10:02:07 +08:00
parent 4c4c33f970
commit 8fd6dbb68b
18 changed files with 69 additions and 30 deletions

View File

@ -40,8 +40,12 @@ pub struct Migrator;
#[async_trait::async_trait]
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![Box::new(init::Migration)]
vec![
Box::new(init::Migration),
Box::new(room_compact_summary::Migration),
]
}
}
pub mod init;
pub mod room_compact_summary;

View File

@ -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(())
}
}

View File

@ -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);

View File

@ -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)]

View File

@ -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)]

View File

@ -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)]

View File

@ -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)]

View File

@ -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)]

View File

@ -30,4 +30,4 @@ pub struct Model {
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}
impl ActiveModelBehavior for ActiveModel {}

View File

@ -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;

View File

@ -60,4 +60,4 @@ pub struct Model {
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}
impl ActiveModelBehavior for ActiveModel {}

View File

@ -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 {}
impl ActiveModelBehavior for ActiveModel {}

View File

@ -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;
pub mod room_user_state;

View File

@ -31,4 +31,4 @@ impl Related<super::room::Entity> for Entity {
}
}
impl ActiveModelBehavior for ActiveModel {}
impl ActiveModelBehavior for ActiveModel {}

View File

@ -57,4 +57,4 @@ impl Related<super::room_thread::Entity> for Entity {
}
}
impl ActiveModelBehavior for ActiveModel {}
impl ActiveModelBehavior for ActiveModel {}

View File

@ -37,4 +37,4 @@ impl Related<super::room::Entity> for Entity {
}
}
impl ActiveModelBehavior for ActiveModel {}
impl ActiveModelBehavior for ActiveModel {}

View File

@ -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;

View File

@ -43,4 +43,4 @@ impl Related<crate::users::user::Entity> for Entity {
}
}
impl ActiveModelBehavior for ActiveModel {}
impl ActiveModelBehavior for ActiveModel {}