sql migration error in 020_add_metadata_tables

- add check to verify resource_metadata is not empty
- fix check to verify insert statement is set

Change-Id: I6b7c1d4a8ebf35af2547d97baa39831597012468
Closes-Bug: #1257779
Don't need session.flush in context managed by session

Within the scope of a single method, keeping all the reads and writes within
the context managed by a single session. In this way, the session's __exit__
handler will take care of calling flush() and commit() for you.
If using this approach, you should not explicitly call flush() or commit().
See http://stackoverflow.com/questions/4201455/sqlalchemy-whats-the-
difference-between-flush-and-commit

Closes-Bug: #1258044
Change-Id: I53f7a054ffd4a4d72ae20d5efc91bc24c1f7516e
Merge "sql migration error in 020_add_metadata_tables"