@@ -522,7 +522,7 @@ func (reference *ForeignKeyReferenceHandler) CheckReference(ctx *sql.Context, ro
522522 if validationErr := reference .validateColumnTypeConstraints (ctx , row , parentRow ); validationErr != nil {
523523 return validationErr
524524 }
525-
525+
526526 // We have a parent row so throw no error
527527 return nil
528528 }
@@ -550,33 +550,32 @@ func (reference *ForeignKeyReferenceHandler) CheckReference(ctx *sql.Context, ro
550550 reference .ForeignKey .ParentTable , reference .RowMapper .GetKeyString (row ))
551551}
552552
553-
554553// validateColumnTypeConstraints validates that column types meet MySQL foreign key requirements.
555554// Centralizes type validation for decimal scale matching and exact time type precision matching.
556555func (reference * ForeignKeyReferenceHandler ) validateColumnTypeConstraints (ctx * sql.Context , childRow sql.Row , parentRow sql.Row ) error {
557556 mapper := reference .RowMapper
558557 if mapper .Index == nil {
559558 return nil
560559 }
561-
560+
562561 for parentIdx , parentCol := range mapper .Index .ColumnExpressionTypes () {
563562 if parentIdx >= len (mapper .IndexPositions ) {
564563 break
565564 }
566-
565+
567566 parentType := parentCol .Type
568567 childType := mapper.SourceSch [mapper.IndexPositions [parentIdx ]].Type
569-
568+
570569 // Check for constraint violations
571570 hasViolation := false
572-
571+
573572 // Decimal scale must match
574573 if childDecimal , ok := childType .(sql.DecimalType ); ok {
575574 if parentDecimal , ok := parentType .(sql.DecimalType ); ok {
576575 hasViolation = childDecimal .Scale () != parentDecimal .Scale ()
577576 }
578577 }
579-
578+
580579 // Time types must match exactly (including precision)
581580 if ! hasViolation {
582581 isChildTime := types .IsTime (childType ) || types .IsTimespan (childType )
@@ -585,7 +584,7 @@ func (reference *ForeignKeyReferenceHandler) validateColumnTypeConstraints(ctx *
585584 hasViolation = ! childType .Equals (parentType )
586585 }
587586 }
588-
587+
589588 if hasViolation {
590589 return sql .ErrForeignKeyChildViolation .New (
591590 reference .ForeignKey .Name ,
@@ -598,7 +597,6 @@ func (reference *ForeignKeyReferenceHandler) validateColumnTypeConstraints(ctx *
598597 return nil
599598}
600599
601-
602600// CheckTable checks that every row in the table has an index entry in the referenced table.
603601func (reference * ForeignKeyReferenceHandler ) CheckTable (ctx * sql.Context , tbl sql.ForeignKeyTable ) error {
604602 partIter , err := tbl .Partitions (ctx )
@@ -656,7 +654,7 @@ func (mapper *ForeignKeyRowMapper) GetIter(ctx *sql.Context, row sql.Row, refChe
656654 }
657655
658656 targetType := mapper .SourceSch [rowPos ].Type
659-
657+
660658 // Transform the type of the value in this row to the one in the other table for the index lookup, if necessary
661659 if mapper .TargetTypeConversions != nil && mapper .TargetTypeConversions [rowPos ] != nil {
662660 var err error
0 commit comments