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

CREATE TABLE IF NOT EXISTS fetchmetrics.DOG_Assessment_Group (
	  id_group INT NOT NULL AUTO_INCREMENT PRIMARY KEY
    , id_temp INT
	, id_assessment_type INT NOT NULL
    , CONSTRAINT FK_DOG_Assessment_id_assessment_type
		FOREIGN KEY (id_assessment_type)
        REFERENCES fetchmetrics.DOG_Assessment_Type(id_type)
	, id_weather INT NOT NULL
    , CONSTRAINT FK_DOG_Assessment_id_weather
		FOREIGN KEY (id_weather)
        REFERENCES fetchmetrics.DOG_Weather(id_weather)
	, id_lighting_level INT NOT NULL
    , CONSTRAINT FK_DOG_Assessment_id_lighting_level
		FOREIGN KEY (id_lighting_level)
        REFERENCES fetchmetrics.DOG_Lighting_Level(id_lighting_level)
	, id_location INT NOT NULL
    , CONSTRAINT FK_DOG_Assessment_id_location
		FOREIGN KEY (id_location)
        REFERENCES fetchmetrics.DOG_Location(id_location)
	, id_user_handler INT NOT NULL
    , CONSTRAINT FK_DOG_Assessment_id_user_handler
		FOREIGN KEY (id_user_handler)
        REFERENCES fetchmetrics.DOG_User(id_user)
	, name VARCHAR(1000) NOT NULL
	, notes TEXT
    , difficulty_level DOUBLE
    , start_on DATETIME
    , end_on DATETIME
    , temperature_celcius DECIMAL(5, 2)
    , difficulty_level DOUBLE
    , active BIT NOT NULL DEFAULT 1
	, created_on DATETIME
    , id_user_created_by INT
    , CONSTRAINT FK_DOG_Assessment_Group_id_user_created_by
        FOREIGN KEY (id_user_created_by)
        REFERENCES fetchmetrics.DOG_User(id_user)
	, id_change_set INT
	, CONSTRAINT FK_DOG_Assessment_Group_id_change_set
		FOREIGN KEY (id_change_set) 
		REFERENCES fetchmetrics.DOG_Dog_Change_Set(id_change_set)
);
