MCPcopy Index your code
hub / github.com/coder/coder / generateCheckConstraints

Function generateCheckConstraints

scripts/dbgen/constraint.go:208–241  ·  view source on GitHub ↗

generateCheckConstraints generates the CheckConstraint enum.

()

Source from the content-addressed store, hash-verified

206
207// generateCheckConstraints generates the CheckConstraint enum.
208func generateCheckConstraints() error {
209 localPath, err := localFilePath()
210 if err != nil {
211 return err
212 }
213 databasePath := filepath.Join(localPath, "..", "..", "..", "coderd", "database")
214 dumpPath := filepath.Join(databasePath, "dump.sql")
215 outputPath := filepath.Join(databasePath, "check_constraint.go")
216
217 var (
218 tableRegex = regexp.MustCompile(`CREATE TABLE\s+([^\s]+)`)
219 checkRegex = regexp.MustCompile(`CONSTRAINT\s+([^\s]+)\s+CHECK`)
220 )
221 fn := func(query string) ([]constraint, error) {
222 constraints := []constraint{}
223
224 tableMatches := tableRegex.FindStringSubmatch(query)
225 if len(tableMatches) > 0 {
226 table := tableMatches[1]
227
228 // Find every CONSTRAINT xxx CHECK occurrence.
229 matches := checkRegex.FindAllStringSubmatch(query, -1)
230 for _, match := range matches {
231 constraints = append(constraints, constraint{
232 name: match[1],
233 comment: table,
234 })
235 }
236 }
237 return constraints, nil
238 }
239
240 return generateConstraints(dumpPath, outputPath, constraintTypeCheck, fn)
241}

Callers 1

runFunction · 0.85

Calls 3

localFilePathFunction · 0.85
generateConstraintsFunction · 0.85
MustCompileMethod · 0.80

Tested by

no test coverage detected