MCPcopy Create free account
hub / github.com/dolthub/doltgresql / validateForeignKeyDefinition

Function validateForeignKeyDefinition

server/analyzer/foreign_key.go:31–49  ·  view source on GitHub ↗

validateForeignKeyDefinition validates that the given foreign key definition is valid for creation

(ctx *sql.Context, fkDef sql.ForeignKeyConstraint, cols map[string]*sql.Column, parentCols map[string]*sql.Column)

Source from the content-addressed store, hash-verified

29
30// validateForeignKeyDefinition validates that the given foreign key definition is valid for creation
31func validateForeignKeyDefinition(ctx *sql.Context, fkDef sql.ForeignKeyConstraint, cols map[string]*sql.Column, parentCols map[string]*sql.Column) error {
32 var castsColl *casts.Collection
33 if len(fkDef.Columns) > 0 {
34 var err error
35 // TODO: which database is this supposed to use?
36 castsColl, err = core.GetCastsCollectionFromContext(ctx, "")
37 if err != nil {
38 return err
39 }
40 }
41 for i := range fkDef.Columns {
42 col := cols[strings.ToLower(fkDef.Columns[i])]
43 parentCol := parentCols[strings.ToLower(fkDef.ParentColumns[i])]
44 if !foreignKeyComparableTypes(ctx, castsColl, col.Type, parentCol.Type) {
45 return errors.Errorf("Key columns %q and %q are of incompatible types: %s and %s", col.Name, parentCol.Name, col.Type.String(), parentCol.Type.String())
46 }
47 }
48 return nil
49}
50
51// foreignKeyComparableTypes returns whether the two given types are able to be used as parent/child columns in a
52// foreign key.

Callers

nothing calls this directly

Calls 4

ErrorfMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected