Ensure sql upgrade tests can run with non-sqlite databases.

This patch fixes the issues that were preventing the running of
live sql upgrade tests (either by running test_sql_upgrade directly
or via test_sql_livetest), namely:

- Dropping the tables that were in existence before the current
  scope of migration in an order that is FK friendly
- Fixing an issue where the tables were being dropped in the
  wrong order in the downgrade of federation
- Ensuring we don't hold sessions open over upgrade/downgrade
  steps in our test methods

Limitations:

- This patch has not been tested with DB2

Closes-Bug: 1363047
Closes-Bug: 1375937
Change-Id: Ied4741a9646b57bc6f2ddcdc8a380ea55b2a9634