From 2a40cc37c016776a9399301ab57a8fbc33264829 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Fri, 18 Sep 2026 21:22:34 +0800 Subject: [PATCH] fix(migrations): renumber the context checkpoint migration to 000105 #3406 (000104_skill_served_version) and #3407 (000104_message_context_checkpoint) each took version 104 and were merged eleven minutes apart. golang-migrate refuses to load a directory with a duplicate version ("duplicate migration file"), so every PostgreSQL deployment of main fails to migrate. Renumber the later of the two. It is safe for every deployment that could exist: one that migrated between the two merges applied the skill migration as 104 and now applies this one as 105, and after the second merge main could not load its migrations at all, so no deployment applied this file as 104. The migration is ADD COLUMN IF NOT EXISTS either way. Add a test that loads both migration directories. Pull request CI runs on the merge with main, so a second PR taking an already merged number now fails before it lands. --- .../migration_sqlite_versioned_schema_test.go | 2 +- internal/database/migration_versions_test.go | 24 +++++++++++++++++++ .../000024_message_context_checkpoint.up.sql | 2 +- ...00105_message_context_checkpoint.down.sql} | 0 ... 000105_message_context_checkpoint.up.sql} | 2 +- 5 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 internal/database/migration_versions_test.go rename migrations/versioned/{000104_message_context_checkpoint.down.sql => 000105_message_context_checkpoint.down.sql} (100%) rename migrations/versioned/{000104_message_context_checkpoint.up.sql => 000105_message_context_checkpoint.up.sql} (89%) diff --git a/internal/database/migration_sqlite_versioned_schema_test.go b/internal/database/migration_sqlite_versioned_schema_test.go index 28bff5ec..43582ebf 100644 --- a/internal/database/migration_sqlite_versioned_schema_test.go +++ b/internal/database/migration_sqlite_versioned_schema_test.go @@ -40,7 +40,7 @@ var versionedSQLiteColumns = map[string][]string{ "users": {"is_system_admin"}, // 000053 "knowledges": {"pending_subtasks_count", "profile"}, // 000056, 000101 "knowledge_bases": {"profile_config", "generated_profile"}, // 000101 - "messages": {"attachments", "usage", "sandbox_checkpoint", "context_checkpoint"}, // 000034/085/097/104 + "messages": {"attachments", "usage", "sandbox_checkpoint", "context_checkpoint"}, // 000034/085/097/105 "sessions": {"parent_session_id", "forked_from_message_id", "fork_bootstrap"}, // 000097 "tenant_invitations": {"token", "accepted_count"}, // 000054 "embed_channels": {"allow_memory"}, // 000060 diff --git a/internal/database/migration_versions_test.go b/internal/database/migration_versions_test.go new file mode 100644 index 00000000..5ac0c56d --- /dev/null +++ b/internal/database/migration_versions_test.go @@ -0,0 +1,24 @@ +package database + +import ( + "path/filepath" + "testing" + + "github.com/golang-migrate/migrate/v4/source" + _ "github.com/golang-migrate/migrate/v4/source/file" + "github.com/stretchr/testify/require" +) + +// Two pull requests that each take the next migration number both pass their +// own checks and collide once both are merged: golang-migrate refuses to load +// a directory with a duplicate version, so every deployment fails to migrate. +// 000104 did exactly that. Loading each directory catches it, since pull +// request CI runs on the merge with the current main. +func TestMigrationDirectoriesLoad(t *testing.T) { + root := sqliteRepoRoot(t) + for _, dir := range []string{"versioned", "sqlite"} { + src, err := source.Open("file://" + filepath.Join(root, "migrations", dir)) + require.NoError(t, err, "migrations/%s must load", dir) + require.NoError(t, src.Close()) + } +} diff --git a/migrations/sqlite/000024_message_context_checkpoint.up.sql b/migrations/sqlite/000024_message_context_checkpoint.up.sql index 1a133430..343dc0b2 100644 --- a/migrations/sqlite/000024_message_context_checkpoint.up.sql +++ b/migrations/sqlite/000024_message_context_checkpoint.up.sql @@ -1,3 +1,3 @@ --- Mirrors versioned migration 000104_message_context_checkpoint: the agent +-- Mirrors versioned migration 000105_message_context_checkpoint: the agent -- compaction summary persisted on the last turn it covers. ALTER TABLE messages ADD COLUMN context_checkpoint TEXT; diff --git a/migrations/versioned/000104_message_context_checkpoint.down.sql b/migrations/versioned/000105_message_context_checkpoint.down.sql similarity index 100% rename from migrations/versioned/000104_message_context_checkpoint.down.sql rename to migrations/versioned/000105_message_context_checkpoint.down.sql diff --git a/migrations/versioned/000104_message_context_checkpoint.up.sql b/migrations/versioned/000105_message_context_checkpoint.up.sql similarity index 89% rename from migrations/versioned/000104_message_context_checkpoint.up.sql rename to migrations/versioned/000105_message_context_checkpoint.up.sql index f4a1120f..da6d30a7 100644 --- a/migrations/versioned/000104_message_context_checkpoint.up.sql +++ b/migrations/versioned/000105_message_context_checkpoint.up.sql @@ -1,4 +1,4 @@ --- Migration: 000104_message_context_checkpoint +-- Migration: 000105_message_context_checkpoint -- Agent compaction summaries persisted on the assistant message of the last -- turn they cover, so the next turn's history starts from the summary instead -- of summarizing the same turns again.