
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_Dog_Command_Link'
;

CREATE TABLE IF NOT EXISTS parts.DOG_Dog_Command_Link (
	  id_link INT NOT NULL AUTO_INCREMENT PRIMARY KEY
	, id_dog INT NOT NULL
    , CONSTRAINT FK_DOG_Dog_Command_Link_id_dog
		FOREIGN KEY (id_dog)
        REFERENCES parts.DOG_Dog(id_dog)
	, id_command INT NOT NULL
    , CONSTRAINT FK_DOG_Dog_Command_Link_id_command
		FOREIGN KEY (id_command)
        REFERENCES parts.DOG_Command(id_command)
	, id_understanding_level INT NOT NULL
    , CONSTRAINT FK_DOG_Dog_Command_Link_id_understanding_level
		FOREIGN KEY (id_understanding_level)
        REFERENCES parts.DOG_Understanding_Level(id_understanding_level)
	, id_obedience_level INT NOT NULL
    , CONSTRAINT FK_DOG_Dog_Command_Link_id_obedience_level
		FOREIGN KEY (id_obedience_level)
        REFERENCES parts.DOG_Obedience_Level(id_obedience_level)
    , hand_signal_description TEXT
	, notes TEXT
--  , has_button BIT NOT NULL DEFAULT 0
    , active BIT NOT NULL DEFAULT 1
	, created_on DATETIME
    , id_user_created_by INT
    , CONSTRAINT FK_DOG_Dog_Command_Link_id_user_created_by
        FOREIGN KEY (id_user_created_by)
        REFERENCES parts.DOG_User(id_user)
	, id_change_set INT
	, CONSTRAINT FK_DOG_Dog_Command_Link_id_change_set
		FOREIGN KEY (id_change_set) 
		REFERENCES parts.DOG_Dog_Change_Set(id_change_set)
);
