
USE parts;

SELECT CONCAT('WARNING: Table ', TABLE_SCHEMA, '.', TABLE_NAME, ' already exists.') AS msg_warning 
FROM INFORMATION_SCHEMA.TABLES 
WHERE 
        TABLE_SCHEMA = 'parts' 
    AND TABLE_NAME = 'DOG_Assessment_Response'
;

CREATE TABLE IF NOT EXISTS parts.DOG_Assessment_Response (
	  id_response INT NOT NULL AUTO_INCREMENT PRIMARY KEY
	, id_assessment_command_modality_link INT NOT NULL
    , CONSTRAINT FK_DOG_Assessment_Response_id_assessment_command_modality_link
		FOREIGN KEY (id_assessment_command_modality_link)
        REFERENCES parts.DOG_Assessment_Command_Modality_Link(id_link)
	, id_response_quality_metric INT NOT NULL
    , CONSTRAINT FK_DOG_Assessment_Response_id_response_quality_metric
		FOREIGN KEY (id_response_quality_metric)
        REFERENCES parts.DOG_Response_Quality_Metric(id_metric)
	, id_obedience_level INT NOT NULL
    , CONSTRAINT FK_DOG_Assessment_Response_id_obedience_level
		FOREIGN KEY (id_obedience_level)
        REFERENCES parts.DOG_Obedience_Level(id_obedience_level)
    , value_measured DOUBLE
    , notes TEXT
    , active BIT NOT NULL DEFAULT 1
	, created_on DATETIME
    , id_user_created_by INT
    , CONSTRAINT FK_DOG_Assessment_Response_id_user_created_by
        FOREIGN KEY (id_user_created_by)
        REFERENCES parts.DOG_User(id_user)
	, id_change_set INT
	, CONSTRAINT FK_DOG_Assessment_Response_id_change_set
		FOREIGN KEY (id_change_set) 
		REFERENCES parts.DOG_Dog_Change_Set(id_change_set)
);
