DROP TABLE question_question_option;
DROP TABLE question_option;
DROP TABLE review_template_question;
DROP TABLE review_template;

CREATE TABLE IF NOT EXISTS `log` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `dateCreated` datetime NOT NULL,
  `lastModified` datetime NOT NULL,
  `deleted` bit(1) NOT NULL,
  `project_id` bigint(20) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `project_id` (`project_id`),
  KEY `deleted_index` (`deleted`),
  KEY `project_index` (`project_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
ALTER TABLE `log`
  ADD CONSTRAINT `project_index` FOREIGN KEY (`project_id`) REFERENCES `project` (`id`);

CREATE TABLE IF NOT EXISTS `log_entry` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `dateCreated` datetime NOT NULL,
  `lastModified` datetime NOT NULL,
  `deleted` bit(1) NOT NULL,
  `contents` longtext,
  `creator_id` bigint(20) NOT NULL,
  `log_id` bigint(20) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `deleted_index` (`deleted`),
  KEY `creator_index` (`creator_id`),
  KEY `log_index` (`log_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
ALTER TABLE `log_entry`
  ADD CONSTRAINT `log_index` FOREIGN KEY (`log_id`) REFERENCES `log` (`id`),
  ADD CONSTRAINT `creator_index` FOREIGN KEY (`creator_id`) REFERENCES `user` (`id`);

ALTER TABLE general_system_settings ADD COLUMN peerDownloadEnabled bit(1) NOT NULL;
ALTER TABLE project ADD COLUMN stateOfMindDate datetime;

ALTER TABLE peer_request DROP COLUMN reviewTemplate_id;
ALTER TABLE peer_request ADD COLUMN checkListTemplate_id bigint(20);
CREATE INDEX checkListTemplate_index ON peer_request(checkListTemplate_id);


ALTER TABLE answer DROP COLUMN chosenNotApplicable;
ALTER TABLE answer DROP COLUMN radioChoice_id;
ALTER TABLE answer ADD COLUMN answer varchar(255) NOT NULL;

ALTER TABLE question DROP COLUMN freeTextHeading;
ALTER TABLE question DROP COLUMN freeTextQuestion;
ALTER TABLE question DROP COLUMN notApplicableHeading;
ALTER TABLE question DROP COLUMN notApplicableOption;
ALTER TABLE question DROP COLUMN radioChoiceQuestion;
ALTER TABLE question DROP COLUMN reviewTemplate_id;

