
CREATE TABLE WEB_HOOK_EVENT(
    USER_NAME VARCHAR(100) NOT NULL,
    REPOSITORY_NAME VARCHAR(100) NOT NULL,
    URL VARCHAR(200) NOT NULL,
    EVENT VARCHAR(30) NOT NULL
);

ALTER TABLE WEB_HOOK_EVENT ADD CONSTRAINT IDX_WEB_HOOK_EVENT_PK PRIMARY KEY (USER_NAME, REPOSITORY_NAME, URL, EVENT);
ALTER TABLE WEB_HOOK_EVENT ADD CONSTRAINT IDX_WEB_HOOK_EVENT_FK0 FOREIGN KEY (USER_NAME, REPOSITORY_NAME, URL) REFERENCES WEB_HOOK (USER_NAME, REPOSITORY_NAME, URL)
  ON DELETE CASCADE ON UPDATE CASCADE;

CREATE TEMPORARY TABLE TMP_EVENTS (EVENT VARCHAR(30));

INSERT INTO TMP_EVENTS VALUES ('push'),('issue_comment'),('issues'),('pull_request');

INSERT INTO WEB_HOOK_EVENT (USER_NAME, REPOSITORY_NAME, URL, EVENT)
  SELECT USER_NAME, REPOSITORY_NAME, URL, EVENT
    FROM WEB_HOOK, TMP_EVENTS;

DROP TABLE TMP_EVENTS;
