Prevent creating migration with same name (Fix ##386)

While fixing this issue, I find it really hard to write unittest for it because of the situation where we have tight coupling.
This pull request fix those.

+ Prevent creating migration with same name (Fix #386)
+ Apply Dependency Inversion