From 8e6127c7cd1dc010c49cb0dc55311308f24bd42e Mon Sep 17 00:00:00 2001 From: Kanat Date: Tue, 24 Nov 2026 23:01:09 -0500 Subject: [PATCH] AI-3798: move the sync hash migration after the newest deployed global version Goose refuses a migration older than the newest one a database ran, and staging is at 20270202000000, so the router built from main could not start on it. The migration only adds columns if missing, so a database that ran the old number runs the new one as a no-op. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_01SWVEMnXTtPBsPNSxa4oFHi --- .../internal/store/connector_definition.go | 2 +- acceleration/internal/store/migrate_test.go | 34 +++++++++++++++++++ acceleration/internal/store/router_config.go | 2 +- ...0202000100_connector_router_sync_hash.sql} | 0 4 files changed, 36 insertions(+), 2 deletions(-) rename acceleration/migrations/global/{20270201001200_connector_router_sync_hash.sql => 20270202000100_connector_router_sync_hash.sql} (100%) diff --git a/acceleration/internal/store/connector_definition.go b/acceleration/internal/store/connector_definition.go index 014b7b2bf9..20733026a4 100644 --- a/acceleration/internal/store/connector_definition.go +++ b/acceleration/internal/store/connector_definition.go @@ -64,7 +64,7 @@ type ConnectorDefinition struct { Description string `bun:"description,notnull"` Manifest core.Manifest `bun:"manifest,type:jsonb,notnull"` // SyncHash is a fingerprint of the file the CLI last synced onto this revision - // (20270201001200_connector_router_sync_hash.sql). Empty for a built-in, and for a revision + // (20270202000100_connector_router_sync_hash.sql). Empty for a built-in, and for a revision // that was never synced or was written since by anything that is not a sync. SyncHash string `bun:"sync_hash,notnull"` CreatedAt time.Time `bun:"created_at,notnull"` diff --git a/acceleration/internal/store/migrate_test.go b/acceleration/internal/store/migrate_test.go index 8d5e4038fd..d14181fe62 100644 --- a/acceleration/internal/store/migrate_test.go +++ b/acceleration/internal/store/migrate_test.go @@ -8,6 +8,7 @@ import ( "math" "os" "path/filepath" + "strings" "time" "github.com/pressly/goose/v3" @@ -152,6 +153,39 @@ func (s *StoreSuite) TestADatabaseALaterReleaseMigratedStartsAfterTheCleanup() { s.Require().NoError(db.Migrate(s.ctx)) } +// Goose refuses a migration older than the newest one a database ran, so a migration added with +// a version below one already deployed stops every router started on that database. A database +// at the last version before the sync hash columns, that has not run their migration, takes it. +func (s *StoreSuite) TestADatabaseAtTheVersionBeforeTheSyncHashColumnsMigratesThem() { + const deployed = 20270202000000 + opened, err := Open(s.emptyDatabase("sync_hash_slot")) + s.Require().NoError(err) + defer opened.Close() + versions, err := database.NewStore(database.DialectPostgres, globalSet.table) + s.Require().NoError(err) + provider, err := goose.NewProvider("", opened.global.DB, globalSet.files, goose.WithStore(versions)) + s.Require().NoError(err) + var skipped bool + for _, source := range provider.ListSources() { + if strings.HasSuffix(source.Path, "_connector_router_sync_hash.sql") { + skipped = true + continue + } + if source.Version <= deployed { + _, err := provider.ApplyVersion(s.ctx, source.Version, true) + s.Require().NoError(err) + } + } + s.Require().True(skipped, "the sync hash migration is a file of the global set") + + s.Require().NoError(opened.Migrate(s.ctx)) + + var columns int + s.Require().NoError(opened.global.QueryRowContext(s.ctx, `SELECT count(*) FROM information_schema.columns + WHERE column_name = 'sync_hash' AND table_name IN ('connector_definitions', 'router_configs')`).Scan(&columns)) + s.Equal(2, columns) +} + // shardTo opens an empty database of the suite's own with the shared set applied and the shard // set up to version, the order Migrate runs them in. func (s *StoreSuite) shardTo(name string, version int64) *Store { diff --git a/acceleration/internal/store/router_config.go b/acceleration/internal/store/router_config.go index dad84449b4..72ec69713c 100644 --- a/acceleration/internal/store/router_config.go +++ b/acceleration/internal/store/router_config.go @@ -39,7 +39,7 @@ type RouterConfig struct { UpdatedAt time.Time `bun:"updated_at,notnull"` DeletedAt *time.Time `bun:"deleted_at"` // SyncHash is a fingerprint of the file the CLI last synced onto this config - // (20270201001200_connector_router_sync_hash.sql), as AgentConfig.SyncHash is for a + // (20270202000100_connector_router_sync_hash.sql), as AgentConfig.SyncHash is for a // directory. Empty if it was never synced, or was written since by anything that is not a // sync. SyncHash string `bun:"sync_hash,notnull"` diff --git a/acceleration/migrations/global/20270201001200_connector_router_sync_hash.sql b/acceleration/migrations/global/20270202000100_connector_router_sync_hash.sql similarity index 100% rename from acceleration/migrations/global/20270201001200_connector_router_sync_hash.sql rename to acceleration/migrations/global/20270202000100_connector_router_sync_hash.sql