From 98e6f773411db6cabf41459ac52458630c82adc6 Mon Sep 17 00:00:00 2001 From: ZhenYi <434836402@qq.com> Date: Mon, 20 Apr 2026 15:44:59 +0800 Subject: [PATCH] feat(migrate): add room attachment, push subscription, and model_id migrations --- libs/migrate/lib.rs | 5 +++ ...m20260420_000001_create_room_attachment.rs | 30 ++++++++++++++++ .../m20260420_000002_add_push_subscription.rs | 35 +++++++++++++++++++ ...420_000003_add_model_id_to_room_message.rs | 30 ++++++++++++++++ ...20260420_000001_create_room_attachment.sql | 15 ++++++++ ...m20260420_000002_add_push_subscription.sql | 5 +++ ...20_000003_add_model_id_to_room_message.sql | 2 ++ 7 files changed, 122 insertions(+) create mode 100644 libs/migrate/m20260420_000001_create_room_attachment.rs create mode 100644 libs/migrate/m20260420_000002_add_push_subscription.rs create mode 100644 libs/migrate/m20260420_000003_add_model_id_to_room_message.rs create mode 100644 libs/migrate/sql/m20260420_000001_create_room_attachment.sql create mode 100644 libs/migrate/sql/m20260420_000002_add_push_subscription.sql create mode 100644 libs/migrate/sql/m20260420_000003_add_model_id_to_room_message.sql diff --git a/libs/migrate/lib.rs b/libs/migrate/lib.rs index 31faad5..eb32acd 100644 --- a/libs/migrate/lib.rs +++ b/libs/migrate/lib.rs @@ -82,6 +82,9 @@ impl MigratorTrait for Migrator { Box::new(m20260415_000001_add_issue_id_to_agent_task::Migration), Box::new(m20260416_000001_add_retry_count_to_agent_task::Migration), Box::new(m20260417_000001_add_stream_to_room_ai::Migration), + Box::new(m20260420_000001_create_room_attachment::Migration), + Box::new(m20260420_000002_add_push_subscription::Migration), + Box::new(m20260420_000003_add_model_id_to_room_message::Migration), // Repo tables Box::new(m20250628_000028_create_repo::Migration), Box::new(m20250628_000029_create_repo_branch::Migration), @@ -254,3 +257,5 @@ pub mod m20260414_000001_create_agent_task; pub mod m20260415_000001_add_issue_id_to_agent_task; pub mod m20260416_000001_add_retry_count_to_agent_task; pub mod m20260417_000001_add_stream_to_room_ai; +pub mod m20260420_000001_create_room_attachment; +pub mod m20260420_000002_add_push_subscription; diff --git a/libs/migrate/m20260420_000001_create_room_attachment.rs b/libs/migrate/m20260420_000001_create_room_attachment.rs new file mode 100644 index 0000000..849edc8 --- /dev/null +++ b/libs/migrate/m20260420_000001_create_room_attachment.rs @@ -0,0 +1,30 @@ +//! SeaORM migration: create room_attachment table + +use sea_orm_migration::prelude::*; + +pub struct Migration; + +impl MigrationName for Migration { + fn name(&self) -> &str { + "m20260420_000001_create_room_attachment" + } +} + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + let sql = include_str!("sql/m20260420_000001_create_room_attachment.sql"); + super::execute_sql(manager, sql).await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .get_connection() + .execute_raw(sea_orm::Statement::from_string( + sea_orm::DbBackend::Postgres, + "DROP TABLE IF EXISTS room_attachment;".to_string(), + )) + .await?; + Ok(()) + } +} diff --git a/libs/migrate/m20260420_000002_add_push_subscription.rs b/libs/migrate/m20260420_000002_add_push_subscription.rs new file mode 100644 index 0000000..7d9c05b --- /dev/null +++ b/libs/migrate/m20260420_000002_add_push_subscription.rs @@ -0,0 +1,35 @@ +//! SeaORM migration: add push subscription fields to user_notification + +use sea_orm_migration::prelude::*; + +pub struct Migration; + +impl MigrationName for Migration { + fn name(&self) -> &str { + "m20260420_000002_add_push_subscription" + } +} + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + let sql = include_str!("sql/m20260420_000002_add_push_subscription.sql"); + super::execute_sql(manager, sql).await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .get_connection() + .execute_raw(sea_orm::Statement::from_string( + sea_orm::DbBackend::Postgres, + r#" + ALTER TABLE user_notification + DROP COLUMN IF EXISTS push_subscription_endpoint, + DROP COLUMN IF EXISTS push_subscription_keys_p256dh, + DROP COLUMN IF EXISTS push_subscription_keys_auth; + "#.to_string(), + )) + .await?; + Ok(()) + } +} diff --git a/libs/migrate/m20260420_000003_add_model_id_to_room_message.rs b/libs/migrate/m20260420_000003_add_model_id_to_room_message.rs new file mode 100644 index 0000000..ba57388 --- /dev/null +++ b/libs/migrate/m20260420_000003_add_model_id_to_room_message.rs @@ -0,0 +1,30 @@ +//! SeaORM migration: add model_id column to room_message + +use sea_orm_migration::prelude::*; + +pub struct Migration; + +impl MigrationName for Migration { + fn name(&self) -> &str { + "m20260420_000003_add_model_id_to_room_message" + } +} + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + let sql = include_str!("sql/m20260420_000003_add_model_id_to_room_message.sql"); + super::execute_sql(manager, sql).await + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .get_connection() + .execute_raw( + sea_orm::DbBackend::Postgres, + "ALTER TABLE room_message DROP COLUMN IF EXISTS model_id;", + ) + .await?; + Ok(()) + } +} diff --git a/libs/migrate/sql/m20260420_000001_create_room_attachment.sql b/libs/migrate/sql/m20260420_000001_create_room_attachment.sql new file mode 100644 index 0000000..aa2abea --- /dev/null +++ b/libs/migrate/sql/m20260420_000001_create_room_attachment.sql @@ -0,0 +1,15 @@ +CREATE TABLE IF NOT EXISTS room_attachment ( + id UUID PRIMARY KEY, + room UUID NOT NULL, + message UUID NOT NULL, + uploader UUID NOT NULL, + file_name VARCHAR(255) NOT NULL, + file_size BIGINT NOT NULL, + content_type VARCHAR(100) NOT NULL, + s3_key VARCHAR(500) NOT NULL, + created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() +); + +CREATE INDEX idx_room_attachment_room ON room_attachment (room); +CREATE INDEX idx_room_attachment_message ON room_attachment (message); +CREATE INDEX idx_room_attachment_uploader ON room_attachment (uploader); diff --git a/libs/migrate/sql/m20260420_000002_add_push_subscription.sql b/libs/migrate/sql/m20260420_000002_add_push_subscription.sql new file mode 100644 index 0000000..97818b9 --- /dev/null +++ b/libs/migrate/sql/m20260420_000002_add_push_subscription.sql @@ -0,0 +1,5 @@ +-- Add push subscription fields to user_notification +ALTER TABLE user_notification + ADD COLUMN push_subscription_endpoint TEXT, + ADD COLUMN push_subscription_keys_p256dh TEXT, + ADD COLUMN push_subscription_keys_auth TEXT; diff --git a/libs/migrate/sql/m20260420_000003_add_model_id_to_room_message.sql b/libs/migrate/sql/m20260420_000003_add_model_id_to_room_message.sql new file mode 100644 index 0000000..73d921f --- /dev/null +++ b/libs/migrate/sql/m20260420_000003_add_model_id_to_room_message.sql @@ -0,0 +1,2 @@ +ALTER TABLE room_message ADD COLUMN IF NOT EXISTS model_id UUID; +CREATE INDEX IF NOT EXISTS idx_room_message_model_id ON room_message (model_id) WHERE model_id IS NOT NULL;