 
 
 -- Loss map data.
+-- See https://bugs.launchpad.net/openquake/+bug/805434 and
+-- https://bugs.launchpad.net/openquake/+bug/797708
 
 -- Design decision: store both probabilistic and event based loss map in the
 -- same tables (with some checks for consistency)

            OR (loss_value IS NOT NULL AND loss_mean IS NULL AND loss_std_dev IS NULL))
) TABLESPACE uiapi_ts;
SELECT AddGeometryColumn('uiapi', 'loss_map_site_data', 'site', 4326, 'POINT', 2);
-- A site appears at most once inside a loss map
ALTER TABLE uiapi.loss_map_data ALTER COLUMN site SET NOT NULL UNIQUE;


-- Loss asset data.

-- "site" table, and I merged it with the "asset" table.  But this leaves me
-- without a place to store, in the future when it will probably needed, the
-- aggregated loss value per site; the aggregated value is useful for plotting
-- purposes. Maybe a "site" table would be useful in this case?
CREATE TABLE uiapi.loss_map_data (
    id SERIAL PRIMARY KEY,
    loss_map_id INTEGER NOT NULL, -- FK to loss_map.id
    asset_ref VARCHAR NOT NULL,
    loss_mean float,
    loss_std_dev float,
    loss_value float,
