-- schema version 20 to 21

DROP TABLE member_history;
CREATE TABLE member_history (
    mgnr            INTEGER NOT NULL,
    date            TEXT    NOT NULL CHECK (date REGEXP '^[1-9][0-9]{3}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])$') DEFAULT CURRENT_DATE,
    type            TEXT    NOT NULL CHECK (type REGEXP '^[a-z_]+$'),

    business_shares INTEGER NOT NULL,
    comment         TEXT DEFAULT NULL,

    CONSTRAINT pk_member_history PRIMARY KEY (mgnr, date, type),
    CONSTRAINT fk_member_history_member FOREIGN KEY (mgnr) REFERENCES member (mgnr)
        ON UPDATE CASCADE
        ON DELETE CASCADE
) STRICT;
