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

CREATE TABLE IF NOT EXISTS fetchmetrics.DOG_Image (
	  id_image INT NOT NULL AUTO_INCREMENT PRIMARY KEY
    , id_file_type INT NOT NULL
    , CONSTRAINT FK_DOG_Image_id_file_type
        FOREIGN KEY (id_file_type)
        REFERENCES fetchmetrics.CORE_File_Type(id_file_type)
    , id_dog INT
    , CONSTRAINT FK_DOG_Image_id_dog
        FOREIGN KEY (id_dog)
        REFERENCES fetchmetrics.DOG_Dog(id_dog)
    , path VARCHAR(1024) NOT NULL
    , name VARCHAR(1024) NOT NULL
    , display_order INT
    , active BIT NOT NULL DEFAULT 1
	, created_on DATETIME
    , id_user_created_by INT
    , CONSTRAINT FK_DOG_Image_id_user_created_by
        FOREIGN KEY (id_user_created_by)
        REFERENCES fetchmetrics.DOG_User(id_user)
	, id_change_set INT
	, CONSTRAINT FK_DOG_Image_id_change_set
		FOREIGN KEY (id_change_set) 
		REFERENCES fetchmetrics.DOG_Dog_Change_Set(id_change_set)
);
