feat(migrate): add content_tsv backfill migration for full-text search

Populate content_tsv column on existing messages for PostgreSQL FTS support.
This commit is contained in:
ZhenYi 2026-04-28 13:12:38 +08:00
parent 3643991955
commit 5a90a475a4
3 changed files with 22 additions and 0 deletions

View File

@ -3,6 +3,7 @@ pub use sea_orm_migration::prelude::*;
mod m20260420_000003_add_model_id_to_room_message; mod m20260420_000003_add_model_id_to_room_message;
pub mod m20260421_000001_add_agent_type_to_room_ai; pub mod m20260421_000001_add_agent_type_to_room_ai;
pub mod m20260426_000001_add_thinking_content_to_room_message; pub mod m20260426_000001_add_thinking_content_to_room_message;
pub mod m20260428_000001_backfill_content_tsv;
pub async fn execute_sql(manager: &SchemaManager<'_>, sql: &str) -> Result<(), DbErr> { pub async fn execute_sql(manager: &SchemaManager<'_>, sql: &str) -> Result<(), DbErr> {
for stmt in split_sql_statements(sql) { for stmt in split_sql_statements(sql) {
@ -91,6 +92,7 @@ impl MigratorTrait for Migrator {
Box::new(m20260420_000003_add_model_id_to_room_message::Migration), Box::new(m20260420_000003_add_model_id_to_room_message::Migration),
Box::new(m20260421_000001_add_agent_type_to_room_ai::Migration), Box::new(m20260421_000001_add_agent_type_to_room_ai::Migration),
Box::new(m20260426_000001_add_thinking_content_to_room_message::Migration), Box::new(m20260426_000001_add_thinking_content_to_room_message::Migration),
Box::new(m20260428_000001_backfill_content_tsv::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),

View File

@ -0,0 +1,17 @@
use sea_orm_migration::prelude::*;
#[derive(DeriveMigrationName)]
pub struct Migration;
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let sql = include_str!("sql/m20260428_000001_backfill_content_tsv.sql");
super::execute_sql(manager, sql).await
}
async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
// No-op: backfill is idempotent and non-reversible
Ok(())
}
}

View File

@ -0,0 +1,3 @@
-- Backfill content_tsv for existing messages where it's NULL
-- New messages are already handled by application code (connection.rs bulk insert)
UPDATE room_message SET content_tsv = to_tsvector('simple', content) WHERE content_tsv IS NULL;