soundcloud/lhm — pull request #77 by pomier (2014-10-24 13:10:05+00:00)
Title: Add support for multiple outbound foreign keys constraints

This adds support for tables with multiples outbound foreign keys constraints. This is a modification of pull request #36 who allowed only one foreign key constraint.

The original problem in issue #34 was that lhm tries to create a table with foreign keys constraint having the same name than the original table, producing an error. #36 tried to fix it by modifying the last number at the end of the name. `table_ibfk_1` would then become `table_ibfk_2`.
The problem was that the new constraints names were the same when the table had more than one outbound foreign keys, producing the same error than before. Another problem with that solution is that the names produced are not consistent when you undo or redo a migration. The original names are lost forever, so undo a migration won't give you the same structure than before. The new name depends on the original name, so redo a migration may not give the same structure either.

My solution appends a suffix "_lhmn" to the constraint name. If the suffix is already there, we remove it in the new name. If you apply two `change_table`, the constraint names will then be exactly as before. This allows migrations undo and redo to work as they should. Besides, the uniqueness of constraints names is no longer a problem, making lhm support as many outbound foreign key constraints as necessary.