sql: split function and trigger defs into two files

This is required to properly load the database functions and triggers
during the upgrade operation.

The upgrade-4-5.plsql script needs to run a function that is in
functions.plsql but since functions.plsql also contains trigger
definition it needs to be loaded after the upgrade-X-Y files (which
usually contain table changes). So we have a cyclic dependency and the
easiest solution to solving it is to split the functions into their own
file which is loaded before the upgrade scripts and trigger script.

Part of #528.
test
test