-- schema version 28 to 29

ALTER TABLE delivery_schedule ADD COLUMN attrid TEXT DEFAULT NULL;
ALTER TABLE delivery_schedule ADD COLUMN cultid TEXT DEFAULT NULL;
ALTER TABLE delivery_schedule ADD COLUMN cancelled INTEGER NOT NULL CHECK (cancelled IN (TRUE, FALSE)) DEFAULT FALSE;
UPDATE delivery_schedule SET cultid = 'B' WHERE UPPER(description) LIKE '%BIO%';
UPDATE delivery_schedule SET cancelled = TRUE WHERE zwstid = 'M' AND date IN ('2024-09-14', '2024-09-16');

PRAGMA writable_schema = ON;

UPDATE sqlite_schema SET sql = REPLACE(sql, '
) STRICT', ',
    CONSTRAINT fk_delivery_schedule_wine_attribute FOREIGN KEY (attrid) REFERENCES wine_attribute (attrid)
        ON UPDATE CASCADE
        ON DELETE RESTRICT,
    CONSTRAINT fk_delivery_schedule_wine_cultivation FOREIGN KEY (cultid) REFERENCES wine_cultivation (cultid)
        ON UPDATE CASCADE
        ON DELETE RESTRICT
) STRICT')
WHERE type = 'table' AND name = 'delivery_schedule';

PRAGMA schema_version = 2801;
PRAGMA writable_schema = OFF;
