use property_settings_db_v2;

create table properties
(
    entity_type         VARCHAR(200)    NOT NULL,
    entity_value        VARCHAR(200)    NOT NULL,
    property_type       VARCHAR(200)    NOT NULL,
    property_value      BLOB            NOT NULL,
    is_active           BOOLEAN         NOT NULL DEFAULT 1,

    PRIMARY KEY (entity_type, entity_value, property_type)
) ENGINE=INNODB DEFAULT CHARSET=utf8;

ALTER TABLE properties ADD COLUMN creation_date DATETIME;
ALTER TABLE properties ADD COLUMN last_update DATETIME;
ALTER TABLE properties ADD COLUMN last_updated_by VARCHAR(150);
delimiter //
CREATE TRIGGER properties_insert_trigger BEFORE INSERT ON properties
FOR EACH ROW BEGIN
    SET NEW.creation_date=NOW();
    SET NEW.last_updated_by=USER();
    SET NEW.last_update=NOW();
END;//
CREATE TRIGGER properties_update_trigger BEFORE UPDATE ON properties
FOR EACH ROW
BEGIN
    SET NEW.last_updated_by=USER();
    SET NEW.last_update = NOW();
END;//
delimiter ;
