-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
migrations.go
98 lines (89 loc) · 3.21 KB
/
migrations.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright 2020 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.
// Package migrations contains the implementation of migrations. It is imported
// by the server library.
//
// This package registers the migrations with the migration package.
package migrations
import (
"context"
"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
// one exists.
func GetMigration(key clusterversion.ClusterVersion) (migration.Migration, bool) {
m, ok := registry[key]
return m, ok
}
// NoPrecondition is a PreconditionFunc that doesn't check anything.
func NoPrecondition(context.Context, clusterversion.ClusterVersion, migration.TenantDeps) error {
return nil
}
// registry defines the global mapping between a cluster version and the
// associated migration. The migration is only executed after a cluster-wide
// bump of the corresponding version gate.
var registry = make(map[clusterversion.ClusterVersion]migration.Migration)
var migrations = []migration.Migration{
migration.NewTenantMigration(
"ensure that draining names are no longer in use",
toCV(clusterversion.DrainingNamesMigration),
NoPrecondition,
ensureNoDrainingNames,
),
migration.NewTenantMigration(
"add column avgSize to table system.table_statistics",
toCV(clusterversion.AlterSystemTableStatisticsAddAvgSizeCol),
NoPrecondition,
alterSystemTableStatisticsAddAvgSize,
),
migration.NewTenantMigration(
"update system.statement_diagnostics_requests table to support conditional stmt diagnostics",
toCV(clusterversion.AlterSystemStmtDiagReqs),
NoPrecondition,
alterSystemStmtDiagReqs,
),
migration.NewTenantMigration(
"seed system.span_configurations with configs for existing for existing tenants",
toCV(clusterversion.SeedTenantSpanConfigs),
NoPrecondition,
seedTenantSpanConfigsMigration,
),
migration.NewTenantMigration("insert missing system.namespace entries for public schemas",
toCV(clusterversion.InsertPublicSchemaNamespaceEntryOnRestore),
NoPrecondition,
insertMissingPublicSchemaNamespaceEntry,
),
migration.NewTenantMigration(
"add column target to system.protected_ts_records",
toCV(clusterversion.AlterSystemProtectedTimestampAddColumn),
NoPrecondition,
alterTableProtectedTimestampRecords,
),
migration.NewTenantMigration("update synthetic public schemas to be backed by a descriptor",
toCV(clusterversion.PublicSchemasWithDescriptors),
NoPrecondition,
publicSchemaMigration,
),
}
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
}
}
func toCV(key clusterversion.Key) clusterversion.ClusterVersion {
return clusterversion.ClusterVersion{
Version: clusterversion.ByKey(key),
}
}