Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

refactor(host-core): isolate title source migration

vastsa7fb1d7a1032c
diff --git a/crates/host-core/src/db.rs b/crates/host-core/src/db.rs
index fc8c18a12..9418b08d1 100644
--- a/crates/host-core/src/db.rs
+++ b/crates/host-core/src/db.rs
@@ -22,6 +22,7 @@ mod project_groups;
mod repositories;
mod schema;
mod session_collaboration_migration;
+mod session_title_source_migration;
pub(crate) use migrations::{
archive_legacy_db, create_migration_backup, migrate_and_validate_top_level_mode,
migrate_app_settings, migrate_v10_to_v15, migrate_v11_to_v15, migrate_v12_to_v15,
@@ -38,6 +39,7 @@ pub(crate) use repositories::{
OBSOLETE_PLAN_APPROVAL_PERMISSION_MODE,
};
pub(crate) use schema::{PLAN_APPROVALS_SCHEMA, SCHEMA_LATEST, SESSION_TODO_DDL};
+pub(crate) use session_title_source_migration::migrate_v22_to_v23;
pub fn now_ms() -> i64 {
chrono::Utc::now().timestamp_millis()
diff --git a/crates/host-core/src/db/migrations.rs b/crates/host-core/src/db/migrations.rs
index 86a93ffd7..95a004fa2 100644
--- a/crates/host-core/src/db/migrations.rs
+++ b/crates/host-core/src/db/migrations.rs
@@ -984,43 +984,3 @@ pub(crate) fn migrate_v21_to_v22(conn: &Connection, path: &Path) -> Result<()> {
})?;
Ok(())
}
-
-pub(crate) fn migrate_v22_to_v23_tx(tx: &rusqlite::Transaction<'_>) -> Result<()> {
- let has_title_source: bool = tx.query_row(
- "SELECT EXISTS(SELECT 1 FROM pragma_table_info('sessions') WHERE name = 'title_source')",
- [],
- |row| row.get(0),
- )?;
- if !has_title_source {
- tx.execute_batch(
- "ALTER TABLE sessions ADD COLUMN title_source TEXT NOT NULL DEFAULT 'legacy'
- CHECK (title_source IN ('legacy', 'default', 'manual', 'generated'));",
- )?;
- // Older releases stored default and manually-entered titles in the
- // same column. Preserve the distinction where it is observable: only
- // known placeholders remain eligible for the standalone title plugin;
- // every other pre-existing title is treated as manual.
- tx.execute(
- "UPDATE sessions SET title_source = CASE
- WHEN title IN ('', 'New task', 'New chat', '新建任务', '新对话') THEN 'default'
- ELSE 'manual'
- END",
- [],
- )?;
- }
- tx.pragma_update(None, "user_version", 23i64)?;
- Ok(())
-}
-
-pub(crate) fn migrate_v22_to_v23(conn: &Connection, path: &Path) -> Result<()> {
- let backup = create_migration_backup(conn, path, 22)?;
- let tx = conn.unchecked_transaction()?;
- migrate_v22_to_v23_tx(&tx)?;
- tx.commit().with_context(|| {
- format!(
- "commit schema v22 to v23 migration; backup {} remains",
- backup.display()
- )
- })?;
- Ok(())
-}
diff --git a/crates/host-core/src/db/repositories.rs b/crates/host-core/src/db/repositories.rs
index b44ea8249..71a425fa6 100644
--- a/crates/host-core/src/db/repositories.rs
+++ b/crates/host-core/src/db/repositories.rs
@@ -198,7 +198,7 @@ impl Database {
crate::db::migrations::migrate_v21_to_v22(&conn, path)?;
}
22 => {
- crate::db::migrations::migrate_v22_to_v23(&conn, path)?;
+ migrate_v22_to_v23(&conn, path)?;
}
legacy @ 1..=6 => {
let _ = conn.execute_batch("PRAGMA wal_checkpoint(TRUNCATE);");
@@ -245,7 +245,7 @@ impl Database {
migrated_version = conn.query_row("PRAGMA user_version", [], |row| row.get(0))?;
}
if migrated_version == 22 {
- crate::db::migrations::migrate_v22_to_v23(&conn, path)?;
+ migrate_v22_to_v23(&conn, path)?;
}
let db = Self { conn, data_dir };
db.boot_maintenance()?;
diff --git a/crates/host-core/src/db/session_title_source_migration.rs b/crates/host-core/src/db/session_title_source_migration.rs
new file mode 100644
index 000000000..d301aa9a1
--- /dev/null
+++ b/crates/host-core/src/db/session_title_source_migration.rs
@@ -0,0 +1,42 @@
+use super::{create_migration_backup, Connection, Context, Path, Result};
+use rusqlite::Transaction;
+
+fn migrate_v22_to_v23_tx(tx: &Transaction<'_>) -> Result<()> {
+ let has_title_source: bool = tx.query_row(
+ "SELECT EXISTS(SELECT 1 FROM pragma_table_info('sessions') WHERE name = 'title_source')",
+ [],
+ |row| row.get(0),
+ )?;
+ if !has_title_source {
+ tx.execute_batch(
+ "ALTER TABLE sessions ADD COLUMN title_source TEXT NOT NULL DEFAULT 'legacy'
+ CHECK (title_source IN ('legacy', 'default', 'manual', 'generated'));",
+ )?;
+ // Older releases stored default and manually-entered titles in the
+ // same column. Preserve the distinction where it is observable: only
+ // known placeholders remain eligible for the standalone title plugin;
+ // every other pre-existing title is treated as manual.
+ tx.execute(
+ "UPDATE sessions SET title_source = CASE
+ WHEN title IN ('', 'New task', 'New chat', '新建任务', '新对话') THEN 'default'
+ ELSE 'manual'
+ END",
+ [],
+ )?;
+ }
+ tx.pragma_update(None, "user_version", 23i64)?;
+ Ok(())
+}
+
+pub(crate) fn migrate_v22_to_v23(conn: &Connection, path: &Path) -> Result<()> {
+ let backup = create_migration_backup(conn, path, 22)?;
+ let tx = conn.unchecked_transaction()?;
+ migrate_v22_to_v23_tx(&tx)?;
+ tx.commit().with_context(|| {
+ format!(
+ "commit schema v22 to v23 migration; backup {} remains",
+ backup.display()
+ )
+ })?;
+ Ok(())
+}