feat(migrate): add room attachment, push subscription, and model_id migrations

This commit is contained in:
ZhenYi 2026-04-20 15:44:59 +08:00
parent d09af7c326
commit 98e6f77341
7 changed files with 122 additions and 0 deletions

View File

@ -82,6 +82,9 @@ impl MigratorTrait for Migrator {
Box::new(m20260415_000001_add_issue_id_to_agent_task::Migration), Box::new(m20260415_000001_add_issue_id_to_agent_task::Migration),
Box::new(m20260416_000001_add_retry_count_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(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 // Repo tables
Box::new(m20250628_000028_create_repo::Migration), Box::new(m20250628_000028_create_repo::Migration),
Box::new(m20250628_000029_create_repo_branch::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 m20260415_000001_add_issue_id_to_agent_task;
pub mod m20260416_000001_add_retry_count_to_agent_task; pub mod m20260416_000001_add_retry_count_to_agent_task;
pub mod m20260417_000001_add_stream_to_room_ai; pub mod m20260417_000001_add_stream_to_room_ai;
pub mod m20260420_000001_create_room_attachment;
pub mod m20260420_000002_add_push_subscription;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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