Fixed race in DB migration testing

This patch incorporates two parts:
1. Fixed length of indexed fields in models.py. This was already done in Alembic
   migration scripts, but missed the models.py
2. Fixed bug in DB migration testing where we checked current version of database
   but due a race condidition queried wrong (SQLite instead of pre-configured MySQL)
   database. Also, a small change is introduced in session.py to adopt protection
   of session facade from other projects.

Change-Id: Ieb96d53afe0d6e4b7ebc306933ed9f781d7b10b8
Merge "Fixed race in DB migration testing"