core: Fix db upgrade in PostgreSQL 8.x

PostgreSQL 8.x and 9.x have a different behaviour regarding when inline
SQL queries in PL/pgSQL code is evaluated (see
http://wiki.postgresql.org/wiki/What%27s_new_in_PostgreSQL_9.0#PL.2FpgSQL_changes_which_may_cause_regressions).

The current problem in upgrading the database in PostgreSQL 8.x is the
min_refresh_rate column added in 03_02_0440_materialized_views_extensions.sql.

The relevant parts of current flow (before the patch):
1. pre_upgrade script 30 creates the materialized_views table
2. materialized view functions are created
3. [various upgrade scripts]
4. 03_02_0440_materialized_views_extensions.sql - add a column to
   materialized_views.

In 8.x variants, stage (2) will fail since the function can not compile
due to the missing column.

This patch changes the flow as follows:
1. pre_upgrade script 30 creates the materialized_views table
2. pre_upgrade script 40 adds the missing column
3. materialized view functions are created
4. [various upgrade scripts]

Note that the original
dbscripts/upgrade/03_02_0440_materialized_views_extensions.sql is
preserved for backwards compatibility. Since it is reentrant (the column
is only created if it did not previously exist), this is the safest way
to go.

Change-Id: Ifc40a2d40c067b1ace123c565cada27ddd26cc5c
Signed-off-by: Allon Mureinik <amureini@redhat.com>