-- schema version 9 to 10

UPDATE wine_quality_level SET min_kmw = 10.6 WHERE qualid = 'RSW';

DROP VIEW v_area_commitment_bucket;
CREATE VIEW v_area_commitment_bucket AS
SELECT year, mgnr, bucket, area, min_kg, max_kg
FROM v_area_commitment_bucket_strict
WHERE attrid IS NOT NULL
UNION ALL
SELECT b.year, b.mgnr, b.sortid,
        SUM(b.area) AS area,
        SUM(b.min_kg) AS min_kg,
        SUM(b.upper_max_kg) AS max_kg
FROM v_area_commitment_bucket_strict b
    LEFT JOIN wine_attribute a ON a.attrid = b.attrid
WHERE a.strict IS NULL OR a.strict = FALSE
GROUP BY b.year, b.mgnr, b.sortid
ORDER BY year, mgnr, bucket;
