-
Notifications
You must be signed in to change notification settings - Fork 568
/
clusterstate.go
60 lines (56 loc) · 1.79 KB
/
clusterstate.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
package v2_5_0
import (
"context"
"github.com/pachyderm/pachyderm/v2/src/pfs"
"github.com/pachyderm/pachyderm/v2/src/internal/errors"
"github.com/pachyderm/pachyderm/v2/src/internal/migrations"
"github.com/pachyderm/pachyderm/v2/src/internal/pfsdb"
)
func Migrate(state migrations.State) migrations.State {
return state.
Apply("Add projects collection", func(ctx context.Context, env migrations.Env) error {
return setupPostgresCollections(ctx, env.Tx, pfsCollections()...)
}).
Apply("Add default project", func(ctx context.Context, env migrations.Env) error {
if err := env.LockTables(ctx, "collections.projects"); err != nil {
return errors.EnsureStack(err)
}
var defaultProject = &pfs.ProjectInfo{
Project: &pfs.Project{
Name: "default", // hardcoded so that pfs.DefaultProjectName may change in the future
},
}
if err := pfsdb.Projects(nil, nil).ReadWrite(env.Tx).Create("default", defaultProject); err != nil {
return errors.Wrap(err, "could not create default project")
}
return nil
}).
Apply("Rename default project to “default”", func(ctx context.Context, env migrations.Env) error {
if err := env.LockTables(ctx,
"collections.repos",
"collections.branches",
"collections.commits",
"pfs.commit_diffs",
"pfs.commit_totals",
"storage.tracker_objects",
"collections.pipelines",
"collections.jobs",
"collections.role_bindings",
"auth.auth_tokens",
); err != nil {
return errors.EnsureStack(err)
}
if err := migratePFSDB(ctx, env.Tx); err != nil {
return err
}
if err := migratePPSDB(ctx, env.Tx); err != nil {
return err
}
if err := migrateAuth(ctx, env.Tx); err != nil {
return err
}
return nil
})
// DO NOT MODIFY THIS STATE
// IT HAS ALREADY SHIPPED IN A RELEASE
}