-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
declarative_corpus.go
62 lines (58 loc) · 1.82 KB
/
declarative_corpus.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
// Copyright 2022 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 cli
import (
"fmt"
"github.com/cockroachdb/cockroach/pkg/cli/clierrorplus"
"github.com/cockroachdb/cockroach/pkg/jobs/jobspb"
"github.com/cockroachdb/cockroach/pkg/sql/schemachanger/corpus"
"github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scop"
"github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scplan"
"github.com/spf13/cobra"
)
var declarativeValidateCorpus = &cobra.Command{
Use: "declarative-corpus-validate <filename>",
Short: "validates a corpus file for the declarative schema changer",
Long: `
Validates very single declarative schema changer state can be planned against in
a given corpus file.
`,
Args: cobra.ExactArgs(1),
RunE: clierrorplus.MaybeDecorateError(
func(cmd *cobra.Command, args []string) (resErr error) {
cr, err := corpus.NewCorpusReaderWithPath(args[0])
if err != nil {
panic(err)
}
err = cr.ReadCorpus()
if err != nil {
panic(err)
}
for idx := 0; idx < cr.GetNumEntries(); idx++ {
name, state := cr.GetCorpus(idx)
jobID := jobspb.JobID(0)
params := scplan.Params{
InRollback: state.InRollback,
ExecutionPhase: scop.LatestPhase,
SchemaChangerJobIDSupplier: func() jobspb.JobID {
jobID++
return jobID
},
}
_, err := scplan.MakePlan(cmd.Context(), *state, params)
if err != nil {
fmt.Printf("failed to validate %s with error %v\n", name, err)
} else {
fmt.Printf("validated %s\n", name)
}
}
return nil
}),
}