CREATE TABLE feedback_requests (
	id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
	request_id INT NOT NULL,

	requester_service_number INT NOT NULL,
	request_date DATETIME NOT NULL,
	request_text TEXT,

	recipient_service_number INT NOT NULL,

	responder_service_number INT DEFAULT NULL,
	response_date DATETIME DEFAULT NULL,
	response_text TEXT,

	FOREIGN KEY idx_request (request_id) REFERENCES requests (id)/*,
	FOREIGN KEY idx_requester (requester_service_number) REFERENCES users (service_number),
	FOREIGN KEY idx_responder (responder_service_number) REFERENCES users (service_number)*/
);

ALTER TABLE requests ADD COLUMN last_forwarded_by INT DEFAULT NULL;

UPDATE requests r
SET last_forwarded_by = (SELECT last_status_changer FROM accomm_details ad WHERE ad.request_id = r.id LIMIT 1)
WHERE manager_service_number != immediate_manager;

/* ALTER TABLE requests ADD FOREIGN KEY idx_last_forwarder (last_forwarded_by)
	REFERENCES users (service_number); */
