mirror of
https://github.com/openai/codex.git
synced 2026-11-25 07:23:22 +00:00
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
This commit is contained in:
1 parent
82d4a98912
commit
9d88e9ae08
2 files changed
+41
-9
No files matched your search
@@ -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]
|
||||
|
||||
Reference in new issue
Block a user