From 4dd9e0be64b944df1932b0b8c725641da1690bde Mon Sep 17 00:00:00 2001 From: Kanat Date: Tue, 24 Nov 2026 23:15:25 -0500 Subject: [PATCH 1/2] [AI-3663] Re-slot the sync_hash migration after staging's goose version #2302 merged 20270201001200 after staging's global goose version was already 20270202000000, and goose is built without WithAllowMissing, so a build from main refused to start there. Rename it to 20270202000100; both ALTERs are ADD COLUMN IF NOT EXISTS, so a database that ran it under the old version re-runs it as a no-op. Co-Authored-By: Claude Sonnet 5.5 --- .../internal/store/connector_definition.go | 2 +- acceleration/internal/store/migrate_test.go | 30 +++++++++++++++++++ acceleration/internal/store/router_config.go | 2 +- ...0202000100_connector_router_sync_hash.sql} | 0 4 files changed, 32 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..df362f5df3 100644 --- a/acceleration/internal/store/migrate_test.go +++ b/acceleration/internal/store/migrate_test.go @@ -136,6 +136,36 @@ func (s *StoreSuite) TestARolledBackVersionWithNoFileIsNotRefused() { s.Require().NoError(db.Migrate(s.ctx)) } +// Staging's global version was 20270202000000 before the sync_hash columns merged, and a build refuses to start +// on a database with a migration older than its newest applied one. So the migration sorts after that version, +// and a database that ran it under its first version, 20270201001200, applies it again as a no-op. +func (s *StoreSuite) TestTheSyncHashMigrationSortsAfterAGlobalVersionStagingHad() { + db, err := Open(s.emptyDatabase("sync_hash_slot")) + s.Require().NoError(err) + defer db.Close() + hasColumns := func() (hasColumn bool) { + s.Require().NoError(db.global.QueryRowContext(s.ctx, `SELECT count(*) = 2 FROM information_schema.columns + WHERE column_name = 'sync_hash' AND table_name IN ('connector_definitions', 'router_configs')`).Scan(&hasColumn)) + return hasColumn + } + + s.upTo(db, globalSet, 20270202000000) + s.False(hasColumns(), "a database at 20270202000000 has not run the sync_hash migration") + for _, table := range []string{"connector_definitions", "router_configs"} { + _, err = db.global.ExecContext(s.ctx, "ALTER TABLE ? ADD COLUMN sync_hash TEXT NOT NULL DEFAULT ''", bun.Ident(table)) + s.Require().NoError(err) + } + _, err = db.global.ExecContext(s.ctx, "INSERT INTO ? (version_id, is_applied) VALUES (20270201001200, true)", bun.Ident(globalSet.table)) + s.Require().NoError(err) + + s.Require().NoError(db.Migrate(s.ctx)) + s.True(hasColumns()) + var recorded bool + s.Require().NoError(db.global.QueryRowContext(s.ctx, "SELECT EXISTS (SELECT 1 FROM ? WHERE version_id = 20270202000100 AND is_applied)", + bun.Ident(globalSet.table)).Scan(&recorded)) + s.True(recorded, "the migration is recorded under its new version") +} + // A database a later release migrated holds versions this one has no file for, after the // squashed history and before any of it is recorded once the cleanup has run: rolling back to // this release starts on it. 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 From 9f064dc34a532e6911e00d12ea48859e80a4e72b Mon Sep 17 00:00:00 2001 From: Kanat Date: Tue, 24 Nov 2026 23:29:09 -0500 Subject: [PATCH 2/2] AI-3663: assert the sync_hash migration adds the columns on a database at 20270202000000 Co-Authored-By: Claude Sonnet 5.5 --- acceleration/internal/store/migrate_test.go | 48 ++++++++++++++------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/acceleration/internal/store/migrate_test.go b/acceleration/internal/store/migrate_test.go index df362f5df3..2b4872f8a5 100644 --- a/acceleration/internal/store/migrate_test.go +++ b/acceleration/internal/store/migrate_test.go @@ -140,30 +140,48 @@ func (s *StoreSuite) TestARolledBackVersionWithNoFileIsNotRefused() { // on a database with a migration older than its newest applied one. So the migration sorts after that version, // and a database that ran it under its first version, 20270201001200, applies it again as a no-op. func (s *StoreSuite) TestTheSyncHashMigrationSortsAfterAGlobalVersionStagingHad() { - db, err := Open(s.emptyDatabase("sync_hash_slot")) - s.Require().NoError(err) + db := s.syncHashDatabase("sync_hash_slot") defer db.Close() - hasColumns := func() (hasColumn bool) { - s.Require().NoError(db.global.QueryRowContext(s.ctx, `SELECT count(*) = 2 FROM information_schema.columns - WHERE column_name = 'sync_hash' AND table_name IN ('connector_definitions', 'router_configs')`).Scan(&hasColumn)) - return hasColumn - } - - s.upTo(db, globalSet, 20270202000000) - s.False(hasColumns(), "a database at 20270202000000 has not run the sync_hash migration") for _, table := range []string{"connector_definitions", "router_configs"} { - _, err = db.global.ExecContext(s.ctx, "ALTER TABLE ? ADD COLUMN sync_hash TEXT NOT NULL DEFAULT ''", bun.Ident(table)) + _, err := db.global.ExecContext(s.ctx, "ALTER TABLE ? ADD COLUMN sync_hash TEXT NOT NULL DEFAULT ''", bun.Ident(table)) s.Require().NoError(err) } - _, err = db.global.ExecContext(s.ctx, "INSERT INTO ? (version_id, is_applied) VALUES (20270201001200, true)", bun.Ident(globalSet.table)) + _, err := db.global.ExecContext(s.ctx, "INSERT INTO ? (version_id, is_applied) VALUES (20270201001200, true)", bun.Ident(globalSet.table)) s.Require().NoError(err) s.Require().NoError(db.Migrate(s.ctx)) - s.True(hasColumns()) - var recorded bool + s.True(s.syncHashRecorded(db), "the migration is recorded under its new version") +} + +// Staging's own path: at 20270202000000 with neither column and no row of the first version, Migrate adds both. +func (s *StoreSuite) TestTheSyncHashMigrationAddsTheColumnsToAGlobalDatabaseAt20270202000000() { + db := s.syncHashDatabase("sync_hash_add") + defer db.Close() + + s.Require().NoError(db.Migrate(s.ctx)) + s.True(s.syncHashColumns(db), "Migrate adds sync_hash to connector_definitions and router_configs") + s.True(s.syncHashRecorded(db), "the migration is recorded under its new version") +} + +// syncHashDatabase opens an empty database with the global set applied up to 20270202000000. +func (s *StoreSuite) syncHashDatabase(name string) *Store { + db, err := Open(s.emptyDatabase(name)) + s.Require().NoError(err) + s.upTo(db, globalSet, 20270202000000) + s.False(s.syncHashColumns(db), "a database at 20270202000000 has not run the sync_hash migration") + return db +} + +func (s *StoreSuite) syncHashColumns(db *Store) (hasColumns bool) { + s.Require().NoError(db.global.QueryRowContext(s.ctx, `SELECT count(*) = 2 FROM information_schema.columns + WHERE column_name = 'sync_hash' AND table_name IN ('connector_definitions', 'router_configs')`).Scan(&hasColumns)) + return hasColumns +} + +func (s *StoreSuite) syncHashRecorded(db *Store) (recorded bool) { s.Require().NoError(db.global.QueryRowContext(s.ctx, "SELECT EXISTS (SELECT 1 FROM ? WHERE version_id = 20270202000100 AND is_applied)", bun.Ident(globalSet.table)).Scan(&recorded)) - s.True(recorded, "the migration is recorded under its new version") + return recorded } // A database a later release migrated holds versions this one has no file for, after the