Add support for SQL migrations

This PR is for the 2.5 branch.  It has not been tested with the #26 on the 3.0 branch (and will probably affect the investigation of #27).