core: DB 3.0 to 3.1 upgrade

This patch fixes the following errors
1) psql:upgrade/03_01_0410_remove_image_templates_table.sql:2: ERROR:
constraint "image_templates_images" of relation "images" does not exist
2)psql:upgrade/03_01_0950_add_permissions_on_storage_to_users.sql:122:
ERROR:  duplicate key value violates unique constraint
"idx_combined_ad_role_object"

1) was solved by adding two functions fn_db_add/drop_constraint that
checks if constraint not exists/exists before attempting to add/drop it
Then all upgrade scripts adding/dropping table constraints were modified
to use those safe functions, this will ensure that in the next round we
will not got this type of errors anymore.

2) was solved by adding a missing check for duplicate key.

All changes are safe and not change functionality.

Change-Id: I7d0a37abb58f080338b3161d0694c8ba30217d99
Signed-off-by: Eli Mesika <emesika@redhat.com>
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=892532