From 9d88e9ae086128b83292f4ad9868aadb0ed6b0d9 Mon Sep 17 00:00:00 2001 From: joeytrasatti-openai Date: Tue, 8 Sep 2026 21:53:29 +0000 Subject: [PATCH] Rename thread artifacts to attachments in the state database (#43927) ## What changed Add a migration that renames `thread_artifacts` to `thread_attachments` and `artifact_type` to `attachment_type`, and recreates the thread lookup index under the attachment name. ## Testing Extend the migration test to verify that existing attachment data survives the rename, section metadata is preserved, and the version 50 migrator tolerates the updated database with `ignore_missing` enabled. GitOrigin-RevId: 43955c4f69b91f92217efc1dc8e6a551d0716059 --- .../migrations/0055_thread_attachments.sql | 6 +++ codex-rs/state/src/migrations_tests.rs | 44 +++++++++++++++---- 2 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 codex-rs/state/migrations/0055_thread_attachments.sql diff --git a/codex-rs/state/migrations/0055_thread_attachments.sql b/codex-rs/state/migrations/0055_thread_attachments.sql new file mode 100644 index 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.rs index 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)>( "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]