-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathmigrations.go
85 lines (78 loc) · 2.79 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
// 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 (
"github.com/cockroachdb/cockroach/pkg/clusterversion"
"github.com/cockroachdb/cockroach/pkg/migration"
)
// 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
}
// 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(
"add the system.migrations table",
toCV(clusterversion.LongRunningMigrations),
migrationsTableMigration,
),
migration.NewSystemMigration(
"use unreplicated TruncatedState and RangeAppliedState for all ranges",
toCV(clusterversion.TruncatedAndRangeAppliedStateMigration),
truncatedStateMigration,
),
migration.NewSystemMigration(
"purge all replicas using the replicated TruncatedState",
toCV(clusterversion.PostTruncatedAndRangeAppliedStateMigration),
postTruncatedStateMigration,
),
migration.NewTenantMigration(
"upgrade old foreign key representation",
toCV(clusterversion.ForeignKeyRepresentationMigration),
foreignKeyRepresentationUpgrade,
),
migration.NewTenantMigration(
"fix system.protected_ts_meta privileges",
toCV(clusterversion.ProtectedTsMetaPrivilegesMigration),
protectedTsMetaPrivilegesMigration,
),
migration.NewTenantMigration(
"add the systems.join_tokens table",
toCV(clusterversion.JoinTokensTable),
joinTokensTableMigration,
),
migration.NewTenantMigration(
"delete the deprecated namespace table descriptor at ID=2",
toCV(clusterversion.DeleteDeprecatedNamespaceTableDescriptorMigration),
deleteDeprecatedNamespaceTableDescriptorMigration),
migration.NewSystemMigration(
"move over all intents to separate lock table",
toCV(clusterversion.SeparatedIntentsMigration),
separatedIntentsMigration),
}
func init() {
for _, m := range migrations {
registry[m.ClusterVersion()] = m
}
}
func toCV(key clusterversion.Key) clusterversion.ClusterVersion {
return clusterversion.ClusterVersion{
Version: clusterversion.ByKey(key),
}
}