
CREATE TRIGGER t_member_i_ctime
    AFTER INSERT ON member FOR EACH ROW
    WHEN NEW.ctime != UNIXEPOCH()
BEGIN
    UPDATE member SET ctime = UNIXEPOCH() WHERE mgnr = NEW.mgnr;
END;

CREATE TRIGGER t_member_u_ctime
    BEFORE UPDATE ON member FOR EACH ROW
    WHEN OLD.ctime != NEW.ctime
BEGIN
    SELECT RAISE(ABORT, 'It is not allowed to change ctime');
END;

CREATE TRIGGER t_member_i_mtime
    AFTER INSERT ON member FOR EACH ROW
    WHEN NEW.mtime != UNIXEPOCH()
BEGIN
    UPDATE member SET mtime = UNIXEPOCH() WHERE mgnr = NEW.mgnr;
END;

CREATE TRIGGER t_member_u_mtime
    AFTER UPDATE ON member FOR EACH ROW
    WHEN NEW.mtime != UNIXEPOCH()
BEGIN
    UPDATE member SET mtime = UNIXEPOCH() WHERE mgnr = NEW.mgnr;
END;

----------------------------------------------------------------

CREATE TRIGGER t_member_billing_address_i_mtime_member
    AFTER INSERT ON member_billing_address FOR EACH ROW
BEGIN
    UPDATE member SET mtime = UNIXEPOCH() WHERE mgnr = NEW.mgnr;
END;

CREATE TRIGGER t_member_billing_address_u_mtime_member
    AFTER UPDATE ON member_billing_address FOR EACH ROW
BEGIN
    UPDATE member SET mtime = UNIXEPOCH() WHERE mgnr = OLD.mgnr OR mgnr = NEW.mgnr;
END;

CREATE TRIGGER t_member_billing_address_d_mtime_member
    AFTER DELETE ON member_billing_address FOR EACH ROW
BEGIN
    UPDATE member SET mtime = UNIXEPOCH() WHERE mgnr = OLD.mgnr;
END;

----------------------------------------------------------------

CREATE TRIGGER t_member_telephone_number_i_mtime_member
    AFTER INSERT ON member_telephone_number FOR EACH ROW
BEGIN
    UPDATE member SET mtime = UNIXEPOCH() WHERE mgnr = NEW.mgnr;
END;

CREATE TRIGGER t_member_telephone_number_u_mtime_member
    AFTER UPDATE ON member_telephone_number FOR EACH ROW
BEGIN
    UPDATE member SET mtime = UNIXEPOCH() WHERE mgnr = OLD.mgnr OR mgnr = NEW.mgnr;
END;

CREATE TRIGGER t_member_telephone_number_d_mtime_member
    AFTER DELETE ON member_telephone_number FOR EACH ROW
BEGIN
    UPDATE member SET mtime = UNIXEPOCH() WHERE mgnr = OLD.mgnr;
END;

----------------------------------------------------------------

CREATE TRIGGER t_area_commitment_i_ctime
    AFTER INSERT ON area_commitment FOR EACH ROW
    WHEN NEW.ctime != UNIXEPOCH()
BEGIN
    UPDATE area_commitment SET ctime = UNIXEPOCH() WHERE fbnr = NEW.fbnr;
END;

CREATE TRIGGER t_area_commitment_u_ctime
    BEFORE UPDATE ON area_commitment FOR EACH ROW
    WHEN OLD.ctime != NEW.ctime
BEGIN
    SELECT RAISE(ABORT, 'It is not allowed to change ctime');
END;

CREATE TRIGGER t_area_commitment_i_mtime
    AFTER INSERT ON area_commitment FOR EACH ROW
    WHEN NEW.mtime != UNIXEPOCH()
BEGIN
    UPDATE area_commitment SET mtime = UNIXEPOCH() WHERE fbnr = NEW.fbnr;
END;

CREATE TRIGGER t_area_commitment_u_mtime
    AFTER UPDATE ON area_commitment FOR EACH ROW
    WHEN NEW.mtime != UNIXEPOCH()
BEGIN
    UPDATE area_commitment SET mtime = UNIXEPOCH() WHERE fbnr = NEW.fbnr;
END;

----------------------------------------------------------------

CREATE TRIGGER t_delivery_i_ctime
    AFTER INSERT ON delivery FOR EACH ROW
    WHEN NEW.ctime != UNIXEPOCH()
BEGIN
    UPDATE delivery SET ctime = UNIXEPOCH() WHERE (year, did) = (NEW.year, NEW.did);
END;

CREATE TRIGGER t_delivery_u_ctime
    AFTER UPDATE ON delivery FOR EACH ROW
    WHEN OLD.ctime != NEW.ctime
BEGIN
    SELECT RAISE(ABORT, 'It is not allowed to change ctime');
END;

CREATE TRIGGER t_delivery_i_mtime
    AFTER INSERT ON delivery FOR EACH ROW
    WHEN NEW.mtime != UNIXEPOCH()
BEGIN
    UPDATE delivery SET mtime = UNIXEPOCH() WHERE (year, did) = (NEW.year, NEW.did);
END;

CREATE TRIGGER t_delivery_u_mtime
    AFTER UPDATE ON delivery FOR EACH ROW
    WHEN NEW.mtime != UNIXEPOCH()
BEGIN
    UPDATE delivery SET mtime = UNIXEPOCH() WHERE (year, did) = (NEW.year, NEW.did);
END;

----------------------------------------------------------------

CREATE TRIGGER t_delivery_part_i_ctime
    AFTER INSERT ON delivery_part FOR EACH ROW
    WHEN NEW.ctime != UNIXEPOCH()
BEGIN
    UPDATE delivery_part SET ctime = UNIXEPOCH() WHERE (year, did, dpnr) = (NEW.year, NEW.did, NEW.dpnr);
END;

CREATE TRIGGER t_delivery_part_u_ctime
    AFTER UPDATE ON delivery_part FOR EACH ROW
    WHEN OLD.ctime != NEW.ctime
BEGIN
    SELECT RAISE(ABORT, 'It is not allowed to change ctime');
END;

CREATE TRIGGER t_delivery_part_i_mtime
    AFTER INSERT ON delivery_part FOR EACH ROW
    WHEN NEW.mtime != UNIXEPOCH()
BEGIN
    UPDATE delivery_part SET mtime = UNIXEPOCH() WHERE (year, did, dpnr) = (NEW.year, NEW.did, NEW.dpnr);
END;

CREATE TRIGGER t_delivery_part_u_mtime
    AFTER UPDATE ON delivery_part FOR EACH ROW
    WHEN NEW.mtime != UNIXEPOCH()
BEGIN
    UPDATE delivery_part SET mtime = UNIXEPOCH() WHERE (year, did, dpnr) = (NEW.year, NEW.did, NEW.dpnr);
END;

CREATE TRIGGER t_delivery_part_i_mtime_delivery
    AFTER INSERT ON delivery_part FOR EACH ROW
BEGIN
    UPDATE delivery SET mtime = UNIXEPOCH() WHERE (year, did) = (NEW.year, NEW.did);
END;

CREATE TRIGGER t_delivery_part_u_mtime_delivery
    AFTER UPDATE ON delivery_part FOR EACH ROW
BEGIN
    UPDATE delivery SET mtime = UNIXEPOCH() WHERE (year, did) = (NEW.year, NEW.did) OR (year, did) = (OLD.year, OLD.did);
END;

CREATE TRIGGER t_delivery_part_d_mtime_delivery
    AFTER DELETE ON delivery_part FOR EACH ROW
BEGIN
    UPDATE delivery SET mtime = UNIXEPOCH() WHERE (year, did) = (OLD.year, OLD.did);
END;

----------------------------------------------------------------

CREATE TRIGGER t_delivery_part_attribute_i_mtime_delivery_part
    AFTER INSERT ON delivery_part_attribute FOR EACH ROW
BEGIN
    UPDATE delivery_part SET mtime = UNIXEPOCH() WHERE (year, did, dpnr) = (NEW.year, NEW.did, NEW.dpnr);
END;

CREATE TRIGGER t_delivery_part_attribute_u_mtime_delivery_part
    AFTER UPDATE ON delivery_part_attribute FOR EACH ROW
BEGIN
    UPDATE delivery_part SET mtime = UNIXEPOCH() WHERE (year, did, dpnr) = (NEW.year, NEW.did, NEW.dpnr) OR (year, did, dpnr) = (OLD.year, OLD.did, OLD.dpnr);
END;

CREATE TRIGGER t_delivery_part_attribute_d_mtime_delivery_part
    AFTER DELETE ON delivery_part_attribute FOR EACH ROW
BEGIN
    UPDATE delivery_part SET mtime = UNIXEPOCH() WHERE (year, did, dpnr) = (OLD.year, OLD.did, OLD.dpnr);
END;

----------------------------------------------------------------

CREATE TRIGGER t_delivery_part_modifier_i_mtime_delivery_part
    AFTER INSERT ON delivery_part_modifier FOR EACH ROW
BEGIN
    UPDATE delivery_part SET mtime = UNIXEPOCH() WHERE (year, did, dpnr) = (NEW.year, NEW.did, NEW.dpnr);
END;

CREATE TRIGGER t_delivery_part_modifier_u_mtime_delivery_part
    AFTER UPDATE ON delivery_part_modifier FOR EACH ROW
BEGIN
    UPDATE delivery_part SET mtime = UNIXEPOCH() WHERE (year, did, dpnr) = (NEW.year, NEW.did, NEW.dpnr) OR (year, did, dpnr) = (OLD.year, OLD.did, OLD.dpnr);
END;

CREATE TRIGGER t_delivery_part_modifier_d_mtime_delivery_part
    AFTER DELETE ON delivery_part_modifier FOR EACH ROW
BEGIN
    UPDATE delivery_part SET mtime = UNIXEPOCH() WHERE (year, did, dpnr) = (OLD.year, OLD.did, OLD.dpnr);
END;

----------------------------------------------------------------

CREATE TRIGGER t_payment_variant_i_ctime
    AFTER INSERT ON payment_variant FOR EACH ROW
    WHEN NEW.ctime != UNIXEPOCH()
BEGIN
    UPDATE payment_variant SET ctime = UNIXEPOCH() WHERE (year, avnr) = (NEW.year, NEW.avnr);
END;

CREATE TRIGGER t_payment_variant_u_ctime
    BEFORE UPDATE ON payment_variant FOR EACH ROW
    WHEN OLD.ctime != NEW.ctime
BEGIN
    SELECT RAISE(ABORT, 'It is not allowed to change ctime');
END;

CREATE TRIGGER t_payment_variant_i_mtime
    AFTER INSERT ON payment_variant FOR EACH ROW
    WHEN NEW.mtime != UNIXEPOCH()
BEGIN
    UPDATE payment_variant SET mtime = UNIXEPOCH() WHERE (year, avnr) = (NEW.year, NEW.avnr);
END;

CREATE TRIGGER t_payment_variant_u_mtime
    AFTER UPDATE ON payment_variant FOR EACH ROW
    WHEN NEW.mtime != UNIXEPOCH()
BEGIN
    UPDATE payment_variant SET mtime = UNIXEPOCH() WHERE (year, avnr) = (NEW.year, NEW.avnr);
END;

----------------------------------------------------------------

CREATE TRIGGER t_payment_delivery_part_i_mtime_payment_variant
    AFTER INSERT ON payment_delivery_part FOR EACH ROW
BEGIN
    UPDATE payment_variant SET mtime = UNIXEPOCH() WHERE (year, avnr) = (NEW.year, NEW.avnr);
END;

CREATE TRIGGER t_payment_delivery_part_u_mtime_payment_variant
    AFTER UPDATE ON payment_delivery_part FOR EACH ROW
BEGIN
    UPDATE payment_variant SET mtime = UNIXEPOCH() WHERE (year, avnr) = (OLD.year, OLD.avnr) OR (year, avnr) = (NEW.year, NEW.avnr);
END;

CREATE TRIGGER t_payment_delivery_part_d_mtime_payment_variant
    AFTER DELETE ON payment_delivery_part FOR EACH ROW
BEGIN
    UPDATE payment_variant SET mtime = UNIXEPOCH() WHERE (year, avnr) = (OLD.year, OLD.avnr);
END;

----------------------------------------------------------------

CREATE TRIGGER t_payment_member_i_mtime_payment_variant
    AFTER INSERT ON payment_member FOR EACH ROW
BEGIN
    UPDATE payment_variant SET mtime = UNIXEPOCH() WHERE (year, avnr) = (NEW.year, NEW.avnr);
END;

CREATE TRIGGER t_payment_member_u_mtime_payment_variant
    AFTER UPDATE ON payment_member FOR EACH ROW
BEGIN
    UPDATE payment_variant SET mtime = UNIXEPOCH() WHERE (year, avnr) = (OLD.year, OLD.avnr) OR (year, avnr) = (NEW.year, NEW.avnr);
END;

CREATE TRIGGER t_payment_member_d_mtime_payment_variant
    AFTER DELETE ON payment_member FOR EACH ROW
BEGIN
    UPDATE payment_variant SET mtime = UNIXEPOCH() WHERE (year, avnr) = (OLD.year, OLD.avnr);
END;