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

CREATE TABLE IF NOT EXISTS parts.DOG_Response_Quality_Metric (
	  id_metric INT NOT NULL AUTO_INCREMENT PRIMARY KEY
	, id_unit_measurement INT NOT NULL
    , CONSTRAINT FK_DOG_Response_Quality_Metric_id_unit_measurement
		FOREIGN KEY (id_unit_measurement)
        REFERENCES parts.DOG_Unit_Measurement(id_unit_measurement)
    , code VARCHAR(100) NOT NULL
    , name VARCHAR(250) NOT NULL
    , value_min DOUBLE
    , value_max DOUBLE
    , active BIT NOT NULL DEFAULT 1
	, created_on DATETIME
    , id_user_created_by INT
    , CONSTRAINT FK_DOG_Response_Quality_Metric_id_user_created_by
        FOREIGN KEY (id_user_created_by)
        REFERENCES parts.DOG_User(id_user)
	, id_change_set INT
	, CONSTRAINT FK_DOG_Response_Quality_Metric_id_change_set
		FOREIGN KEY (id_change_set) 
		REFERENCES parts.DOG_Dog_Change_Set(id_change_set)
);
