Use connection to update migration table

@yuyiguo
Code is already tested. Please, merge.