Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion acceleration/internal/store/connector_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
34 changes: 34 additions & 0 deletions acceleration/internal/store/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"math"
"os"
"path/filepath"
"strings"
"time"

"github.com/pressly/goose/v3"
Expand Down Expand Up @@ -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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Nit] R1.2 deployed has no source in the comment. Say it is the newest global migration on staging when this was written (20270202000000_log_session_and_attempt_campaign_idx.sql), so a reader knows when the constant can move. Ticket-level, not a blocker.

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 {
Expand Down
2 changes: 1 addition & 1 deletion acceleration/internal/store/router_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down