Skip to content

Commit

Permalink
migration/migrations: prevent duplicate registration
Browse files Browse the repository at this point in the history
Prior to this change, subsequent registrations overwrote earlier registrations.

Release note: None
  • Loading branch information
ajwerner committed Oct 12, 2021
1 parent 960cdaa commit 7da7d09
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions pkg/migration/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"github.com/cockroachdb/cockroach/pkg/clusterversion"
"github.com/cockroachdb/cockroach/pkg/migration"
"github.com/cockroachdb/errors"
)

// GetMigration returns the migration corresponding to this version if
Expand Down Expand Up @@ -72,12 +73,6 @@ var migrations = []migration.Migration{
NoPrecondition,
fixDescriptorMigration,
),
migration.NewTenantMigration(
"add the system.statement_statistics and system.transaction_statistics tables",
toCV(clusterversion.SQLStatsTables),
NoPrecondition,
sqlStatsTablesMigration,
),
migration.NewTenantMigration(
"add the system.database_role_settings table",
toCV(clusterversion.DatabaseRoleSettings),
Expand Down Expand Up @@ -139,10 +134,19 @@ var migrations = []migration.Migration{
NoPrecondition,
tenantUsageSingleConsumptionColumn,
),
migration.NewTenantMigration(
"add the system.statement_statistics and system.transaction_statistics tables",
toCV(clusterversion.SQLStatsTables),
NoPrecondition,
sqlStatsTablesMigration,
),
}

func init() {
for _, m := range migrations {
if _, exists := registry[m.ClusterVersion()]; exists {
panic(errors.AssertionFailedf("duplicate migration registration for %v", m.ClusterVersion()))
}
registry[m.ClusterVersion()] = m
}
}
Expand Down

0 comments on commit 7da7d09

Please sign in to comment.