-- Determines the minimum duration we will have to wait between 2 refreshes , 0 means : no wait
select fn_db_add_column('materialized_views', 'min_refresh_rate_in_sec', 'int default 0');
-- Indicates if this is a product view or custom view
select fn_db_add_column('materialized_views', 'custom', 'boolean default false');
-- Indicates if this materialized_view is currently active
select fn_db_add_column('materialized_views', 'active', 'boolean default true');

Fix db upgrade in PostgreSQL 8.x
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 <abc9ddaceaf0c059a5d9bc2aed71f25cb5370dba@redhat.com>
