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

Function generateForeignKeyConstraints

scripts/dbgen/constraint.go:177–205  ·  view source on GitHub ↗

generateForeignKeyConstraints generates the ForeignKeyConstraint enum.

()

Source from the content-addressed store, hash-verified

175
176// generateForeignKeyConstraints generates the ForeignKeyConstraint enum.
177func generateForeignKeyConstraints() error {
178 localPath, err := localFilePath()
179 if err != nil {
180 return err
181 }
182 databasePath := filepath.Join(localPath, "..", "..", "..", "coderd", "database")
183 dumpPath := filepath.Join(databasePath, "dump.sql")
184 outputPath := filepath.Join(databasePath, "foreign_key_constraint.go")
185
186 fn := func(query string) ([]constraint, error) {
187 if strings.Contains(query, "FOREIGN KEY") {
188 name := ""
189 switch {
190 case strings.Contains(query, "ALTER TABLE") && strings.Contains(query, "ADD CONSTRAINT"):
191 name = strings.Split(query, " ")[6]
192 default:
193 return nil, xerrors.Errorf("unknown foreign key constraint format: %s", query)
194 }
195 return []constraint{
196 {
197 name: name,
198 comment: query,
199 },
200 }, nil
201 }
202 return []constraint{}, nil
203 }
204 return generateConstraints(dumpPath, outputPath, constraintTypeForeignKey, fn)
205}
206
207// generateCheckConstraints generates the CheckConstraint enum.
208func generateCheckConstraints() error {

Callers 1

runFunction · 0.85

Calls 4

localFilePathFunction · 0.85
generateConstraintsFunction · 0.85
ContainsMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected