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)
| 29 | |
| 30 | // validateForeignKeyDefinition validates that the given foreign key definition is valid for creation |
| 31 | func 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. |
nothing calls this directly
no test coverage detected