MCPcopy Create free account
hub / github.com/dataddo/pgq / ValidateFields

Function ValidateFields

validator.go:55–88  ·  view source on GitHub ↗

ValidateFields checks if required fields exist

(ctx context.Context, db *sqlx.DB, queueName string)

Source from the content-addressed store, hash-verified

53
54// ValidateFields checks if required fields exist
55func ValidateFields(ctx context.Context, db *sqlx.DB, queueName string) error {
56 // --- (1) ----
57 // Recover the columns that the queue has
58 columns, err := getColumnData(ctx, db, queueName)
59 if err != nil {
60 return err
61 }
62
63 // --- (2) ----
64 // Run through each one of the recovered columns and validate if all the mandatory ones are included
65 var missingColumns []string
66 for _, mandatoryField := range mandatoryFields {
67 if _, ok := columns[mandatoryField]; !ok {
68 missingColumns = append(missingColumns, mandatoryField)
69 }
70 delete(columns, mandatoryField)
71 }
72
73 // If all the mandatory fields have been found then we don't need to return an error. However,
74 // if there is at least one mandatory field missing in the schema then this queue is invalid.
75 // TODO: Add some more logic to maybe indicate which field is the one that need to be included
76 if len(missingColumns) > 1 {
77 return errors.Errorf("some PGQ columns are missing: %v", missingColumns)
78 }
79
80 // TODO log extra columns in queue table or ignore them?
81 // extraColumns := make([]string, 0, len(columns))
82 // for k := range columns {
83 // extraColumns = append(extraColumns, k)
84 // }
85 // _ = extraColumns
86
87 return nil
88}
89
90// ValidateIndexes checks if required indexes exist
91func ValidateIndexes(ctx context.Context, db *sqlx.DB, queueName string) error {

Calls 1

getColumnDataFunction · 0.85