MCPcopy
hub / github.com/sqlc-dev/sqlc / Verify

Function Verify

internal/cmd/verify.go:51–156  ·  view source on GitHub ↗
(ctx context.Context, dir, filename string, opts *Options)

Source from the content-addressed store, hash-verified

49}
50
51func Verify(ctx context.Context, dir, filename string, opts *Options) error {
52 stderr := opts.Stderr
53 _, conf, err := readConfig(stderr, dir, filename)
54 if err != nil {
55 return err
56 }
57
58 client, err := quickdb.NewClientFromConfig(conf.Cloud)
59 if err != nil {
60 return fmt.Errorf("client init failed: %w", err)
61 }
62
63 manager := dbmanager.NewClient(conf.Servers)
64
65 // Get query sets from a previous archive by tag. If no tag is provided, get
66 // the latest query sets.
67 previous, err := client.GetQuerySets(ctx, &pb.GetQuerySetsRequest{
68 Tag: opts.Against,
69 })
70 if err != nil {
71 return err
72 }
73
74 // Create a mapping of name to query set
75 existing := map[string]config.SQL{}
76 for _, qs := range conf.SQL {
77 existing[qs.Name] = qs
78 }
79
80 var verr error
81 for _, qs := range previous.QuerySets {
82 // TODO: Create a function for this so that we can return early on errors
83
84 check := func() error {
85 if qs.Name == "" {
86 return fmt.Errorf("unnamed query set")
87 }
88
89 current, found := existing[qs.Name]
90 if !found {
91 return fmt.Errorf("unknown query set: %s", qs.Name)
92 }
93
94 // Read the schema files into memory, removing rollback statements
95 var ddl []string
96 files, err := sqlpath.Glob(current.Schema)
97 if err != nil {
98 return err
99 }
100 for _, schema := range files {
101 contents, err := os.ReadFile(schema)
102 if err != nil {
103 return fmt.Errorf("read file: %w", err)
104 }
105 ddl = append(ddl, migrations.RemoveRollbackStatements(string(contents)))
106 }
107
108 var codegen plugin.GenerateRequest

Callers 1

verify.goFile · 0.85

Calls 11

CreateDatabaseMethod · 0.95
NewClientFromConfigFunction · 0.92
NewClientFunction · 0.92
GlobFunction · 0.92
RemoveRollbackStatementsFunction · 0.92
readConfigFunction · 0.85
OpenMethod · 0.80
GetQuerySetsMethod · 0.65
CloseMethod · 0.65
PrepareContextMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected