CRM-15765 upgrade and sql changes

Upgrade handling and SQL changes for https://issues.civicrm.org/jira/browse/CRM-15765