Skip to content

Commit 1887dd1

Browse files
committed
[ga-format-pr] Run ./format_repo.sh to fix formatting
1 parent 76decf9 commit 1887dd1

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

sql/plan/alter_foreign_key.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ func foreignKeyComparableTypes(ctx *sql.Context, type1 sql.Type, type2 sql.Type)
655655
if (types.IsTime(type1) || types.IsTimespan(type1)) && (types.IsTime(type2) || types.IsTimespan(type2)) {
656656
// MySQL allows time-related types to reference each other in foreign keys:
657657
// - DATETIME can reference DATETIME with different precision
658-
// - TIMESTAMP can reference TIMESTAMP with different precision
658+
// - TIMESTAMP can reference TIMESTAMP with different precision
659659
// - DATETIME can reference TIMESTAMP and vice versa
660660
// - TIME can reference TIME with different precision
661661
return true

sql/plan/foreign_key_editor.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
556555
func (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.
603601
func (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

Comments
 (0)