Skip to content
Open
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
3 changes: 2 additions & 1 deletion management/internals/server/boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"crypto/tls"
"net/http"
"net/netip"
"os"
"slices"
"time"

Expand Down Expand Up @@ -74,7 +75,7 @@ func (s *BaseServer) CacheStore() cachestore.StoreInterface {

func (s *BaseServer) Store() store.Store {
return Create(s, func() store.Store {
store, err := store.NewStore(context.Background(), s.Config.StoreConfig.Engine, s.Config.Datadir, s.Metrics(), false)
store, err := store.NewStore(context.Background(), s.Config.StoreConfig.Engine, s.Config.Datadir, s.Metrics(), os.Getenv("NETBIRD_SKIP_MIGRATIONS") == "true")
if err != nil {
Comment on lines +78 to 79
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

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

The PR description says the change is limited to gating AutoMigrate at two production call sites, but this PR also includes unrelated behavioral changes in other areas (e.g., request buffering, telemetry middleware, and multiple store query changes). Please either scope the PR down to just the migration gating or update the PR description to cover these additional changes and their rationale, since they materially affect runtime behavior.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The other files noted (telemetry middleware, account_request_buffer.go, management/server/store/sql_store.go) aren't actually in this PR. They were appearing in the diff because the branch was behind upstream main at review time, so changes from upstream #5879 (context cancel monitoring) showed as additions. Current head 00f3b929 is rebased onto current main; the diff is now scoped to the two migration-gating files as described in the PR body.

log.Fatalf("failed to create store: %v", err)
}
Expand Down
23 changes: 17 additions & 6 deletions management/server/activity/store/sql_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,24 @@ func NewSqlStore(ctx context.Context, dataDir string, encryptionKey string) (*St
return nil, fmt.Errorf("initialize database: %w", err)
}

if err = migrate(ctx, fieldEncrypt, db); err != nil {
return nil, fmt.Errorf("events database migration: %w", err)
}
// Only honor NETBIRD_SKIP_MIGRATIONS for the Postgres activity store, which
// is the one that participates in multi-master logical replication.
// A per-node SQLite activity store still needs its schema created on fresh
// nodes, so the skip must not apply there.
skipMigrations := os.Getenv("NETBIRD_SKIP_MIGRATIONS") == "true" &&
os.Getenv(storeEngineEnv) == string(types.PostgresStoreEngine)

if !skipMigrations {
if err = migrate(ctx, fieldEncrypt, db); err != nil {
return nil, fmt.Errorf("events database migration: %w", err)
}

err = db.AutoMigrate(&activity.Event{}, &activity.DeletedUser{})
if err != nil {
return nil, fmt.Errorf("events auto migrate: %w", err)
err = db.AutoMigrate(&activity.Event{}, &activity.DeletedUser{})
if err != nil {
return nil, fmt.Errorf("events auto migrate: %w", err)
}
} else {
log.WithContext(ctx).Info("NETBIRD_SKIP_MIGRATIONS=true and activity store engine is Postgres; skipping events database migration and AutoMigrate/schema updates")
}

return &Store{
Expand Down