Make migration tests postgres & mysql friendly.

Add some session commits to prevent database deadlocks.
Force close all open sessions before performing tear down.
Use escaped parameter handling for raw sql statements.

Change-Id: I0ef670ddc416a02e78570ab6ebed2b4bf2a8635b
Merge "Make migration tests postgres & mysql friendly."