Lightweight coding agent that runs in your terminal
Rust
Rename thread artifacts to attachments in the state database (#43927)
joeytrasatti-openai9d88e9ae0861
diff --git a/codex-rs/state/migrations/0055_thread_attachments.sql b/codex-rs/state/migrations/0055_thread_attachments.sqlnew file mode 100644index 0000000000..7a31d9c7bb--- /dev/null+++ b/codex-rs/state/migrations/0055_thread_attachments.sql@@ -0,0 +1,6 @@+ALTER TABLE thread_artifacts RENAME TO thread_attachments;+ALTER TABLE thread_attachments RENAME COLUMN artifact_type TO attachment_type;++DROP INDEX idx_thread_artifacts_thread_created_id;+CREATE INDEX idx_thread_attachments_thread_created_id+ ON thread_attachments(thread_id, created_at, id);diff --git a/codex-rs/state/src/migrations_tests.rs b/codex-rs/state/src/migrations_tests.rsindex 99de1f6b00..95cd6818c2 100644--- a/codex-rs/state/src/migrations_tests.rs+++ b/codex-rs/state/src/migrations_tests.rs@@ -189,7 +189,7 @@ INSERT INTO threads (}#[tokio::test]-async fn thread_artifact_migration_preserves_existing_section_metadata() {+async fn thread_attachment_migration_preserves_existing_data() {let sqlite_home = crate::runtime::test_support::unique_temp_dir();tokio::fs::create_dir_all(&sqlite_home).await@@ -202,7 +202,7 @@ async fn thread_artifact_migration_preserves_existing_section_metadata() {.open_read_write_pool(&sqlite.state_db_path()).await.expect("sqlite database should open");- migrator_through(/*version*/ 50)+ migrator_through(/*version*/ 51).run(&pool).await.expect("released thread migrations should apply");@@ -213,10 +213,26 @@ async fn thread_artifact_migration_preserves_existing_section_metadata() {.await.expect("released section appearance should remain writable");+ let thread_id = "00000000-0000-0000-0000-000000000051";+ sqlx::query(+ "INSERT INTO threads (id, rollout_path, created_at, updated_at, source, model_provider, cwd, title, sandbox_policy, approval_mode) VALUES (?, 'rollout.jsonl', 1, 1, 'cli', 'openai', '/tmp', '', 'read-only', 'on-request')",+ )+ .bind(thread_id)+ .execute(&pool)+ .await+ .expect("existing thread should be inserted");+ sqlx::query(+ "INSERT INTO thread_artifacts (id, thread_id, artifact_type, identity_key, payload, created_at) VALUES ('attachment-1', ?, 'pull_request', 'pr-123', '{}', 1)",+ )+ .bind(thread_id)+ .execute(&pool)+ .await+ .expect("existing attachment should be inserted using the released schema");+STATE_MIGRATOR.run(&pool).await- .expect("artifact migration should apply without rewriting released migrations");+ .expect("attachment migration should apply without rewriting released migrations");let section = sqlx::query_as::<_, (String, String, Option<String>)>("SELECT id, name, appearance FROM thread_sections WHERE id = ?",)@@ -233,20 +249,30 @@ async fn thread_artifact_migration_preserves_existing_section_metadata() {));- let artifact_tables = sqlx::query_scalar::<_, String>(- "SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'thread_artifacts'",+ let attachment = sqlx::query_as::<_, (String, String, String, String, String, i64)>(+ "SELECT id, thread_id, attachment_type, identity_key, payload, created_at FROM thread_attachments",)- .fetch_all(&pool)+ .fetch_one(&pool).await- .expect("artifact table should exist");- assert_eq!(artifact_tables, vec!["thread_artifacts"]);+ .expect("existing attachment should remain available under the renamed table and column");+ assert_eq!(+ attachment,+ (+ "attachment-1".to_string(),+ thread_id.to_string(),+ "pull_request".to_string(),+ "pr-123".to_string(),+ "{}".to_string(),+ 1,+ )+ );let mut released_migrator = migrator_through(/*version*/ 50);released_migrator.ignore_missing = true;released_migrator.run(&pool).await- .expect("released binaries should tolerate the additive artifact migration");+ .expect("released binaries should tolerate the attachment rename migration");}#[tokio::test]