Fix wrong using of Metadata in 15,16 migrations

In up>down>up mode migrations are failing due to using of common MetaData.
It should be declared separatly for both of migration methods.

Fixes-Bug: #1240898
Change-Id: I8f6555ce44204e79a9c47b7caa1fe05970f4e3f0
Fix for get_resources with postgresql

Add max_ts and min_ts to GROUP BY in sub-query, since they need to be aggregated to SELECT them.

Closes-Bug: #1241526
Change-Id: Ifdd2bc661b5da31bd40d1c3fa1fc442d7417399f
Merge "Fix wrong using of Metadata in 15,16 migrations"