Skip to content

Commit d3422bd

Browse files
committed
Give more info about foreign keys
This helps when the table itself doesn't have foreign keys defined but if there are other tables with foreign keys pointing to the table on which gh-ost runs. This gives INFO messages for each FK. Note that it now informs the user about `payment` being involved. ``` $ ./gh-ost -database sakila -table rental -alter 'ADD COLUMN ghost_test_001 tinyint DEFAULT NULL' -port 19590 -user msandbox -password msandbox -verbose 2016-08-03 10:18:45 INFO starting gh-ost 1.0.8 2016-08-03 10:18:45 INFO Migrating `sakila`.`rental` 2016-08-03 10:18:45 INFO connection validated on 127.0.0.1:19590 2016-08-03 10:18:45 INFO User has ALL privileges 2016-08-03 10:18:45 INFO binary logs validated on 127.0.0.1:19590 2016-08-03 10:18:45 INFO Restarting replication on 127.0.0.1:19590 to make sure binlog settings apply to replication thread 2016-08-03 10:18:46 INFO Table found. Engine=InnoDB 2016-08-03 10:18:47 INFO Found foreign key on `sakila`.`payment` related to `sakila`.`rental` 2016-08-03 10:18:47 INFO Found foreign key on `sakila`.`rental` related to `sakila`.`rental` 2016-08-03 10:18:47 INFO Found foreign key on `sakila`.`rental` related to `sakila`.`rental` 2016-08-03 10:18:47 INFO Found foreign key on `sakila`.`rental` related to `sakila`.`rental` 2016-08-03 10:18:47 ERROR Found 4 foreign keys related to `sakila`.`rental`. Foreign keys are not supported. Bailing out 2016-08-03 10:18:47 FATAL 2016-08-03 10:18:47 ERROR Found 4 foreign keys related to `sakila`.`rental`. Foreign keys are not supported. Bailing out ``` Related Issue: #129
1 parent 1c1869d commit d3422bd

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

go/logic/inspect.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func (this *Inspector) validateTable() error {
312312
// validateTableForeignKeys makes sure no foreign keys exist on the migrated table
313313
func (this *Inspector) validateTableForeignKeys() error {
314314
query := `
315-
SELECT COUNT(*) AS num_foreign_keys
315+
SELECT TABLE_SCHEMA, TABLE_NAME
316316
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
317317
WHERE
318318
REFERENCED_TABLE_NAME IS NOT NULL
@@ -322,8 +322,10 @@ func (this *Inspector) validateTableForeignKeys() error {
322322
`
323323
numForeignKeys := 0
324324
err := sqlutils.QueryRowsMap(this.db, query, func(rowMap sqlutils.RowMap) error {
325-
numForeignKeys = rowMap.GetInt("num_foreign_keys")
326-
325+
fkSchema := rowMap.GetString("TABLE_SCHEMA")
326+
fkTable := rowMap.GetString("TABLE_NAME")
327+
log.Infof("Found foreign key on %s.%s related to %s.%s", sql.EscapeName(fkSchema), sql.EscapeName(fkTable), sql.EscapeName(this.migrationContext.DatabaseName), sql.EscapeName(this.migrationContext.OriginalTableName))
328+
numForeignKeys++
327329
return nil
328330
},
329331
this.migrationContext.DatabaseName,
@@ -335,7 +337,7 @@ func (this *Inspector) validateTableForeignKeys() error {
335337
return err
336338
}
337339
if numForeignKeys > 0 {
338-
return log.Errorf("Found %d foreign keys on %s.%s. Foreign keys are not supported. Bailing out", numForeignKeys, sql.EscapeName(this.migrationContext.DatabaseName), sql.EscapeName(this.migrationContext.OriginalTableName))
340+
return log.Errorf("Found %d foreign keys related to %s.%s. Foreign keys are not supported. Bailing out", numForeignKeys, sql.EscapeName(this.migrationContext.DatabaseName), sql.EscapeName(this.migrationContext.OriginalTableName))
339341
}
340342
log.Debugf("Validated no foreign keys exist on table")
341343
return nil

0 commit comments

Comments
 (0)