
USE fetchmetrics;

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

CREATE TABLE IF NOT EXISTS fetchmetrics.DOG_Assessment_Command_Link (
	  id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY
    , id_temp INT
	, id_assessment INT NOT NULL
    , CONSTRAINT FK_DOG_Assessment_Command_Link_id_assessment
		FOREIGN KEY (id_assessment)
        REFERENCES fetchmetrics.DOG_Assessment(id_assessment)
	, id_command INT NOT NULL
    , CONSTRAINT FK_DOG_Assessment_Command_Link_id_command
		FOREIGN KEY (id_command)
        REFERENCES fetchmetrics.DOG_Command(id_command)
    /*
	, id_command_modality INT NOT NULL
    , CONSTRAINT FK_DOG_Assessment_Command_Link_id_command_modality
		FOREIGN KEY (id_command_modality)
        REFERENCES fetchmetrics.DOG_Command_Modality(id_command_modality)
	, id_bribe INT NOT NULL
    , CONSTRAINT FK_DOG_Assessment_Command_Link_id_bribe
		FOREIGN KEY (id_bribe)
        REFERENCES fetchmetrics.DOG_Bribe(id_bribe)
    */
	, id_reinforcement_schedule INT NOT NULL
    , CONSTRAINT FK_DOG_Assessment_Command_Link_id_reinforcement_schedule
		FOREIGN KEY (id_reinforcement_schedule)
        REFERENCES fetchmetrics.DOG_Reinforcement_Schedule(id_reinforcement_schedule)
    , distance_from_handler_metres FLOAT
	, is_in_sight_of_handler BIT
	, is_in_scent_range_of_handler BIT
	, is_in_hearing_range_of_handler BIT
	, is_on_lead BIT
	, trial_count INT
    , active BIT NOT NULL DEFAULT 1
	, created_on DATETIME
    , id_user_created_by INT
    , CONSTRAINT FK_DOG_Assessment_Command_Link_id_user_created_by
        FOREIGN KEY (id_user_created_by)
        REFERENCES fetchmetrics.DOG_User(id_user)
	, id_change_set INT
	, CONSTRAINT FK_DOG_Assessment_Command_Link_id_change_set
		FOREIGN KEY (id_change_set) 
		REFERENCES fetchmetrics.DOG_Dog_Change_Set(id_change_set)
);
