CREATE TABLE dependency (result_id BIGINT, input_id BIGINT, PRIMARY KEY(result_id, input_id)) ENGINE = INNODB;
CREATE TABLE input (id BIGINT AUTO_INCREMENT, name VARCHAR(255) NOT NULL, PRIMARY KEY(id, name)) ENGINE = INNODB;
CREATE TABLE input_val (id BIGINT AUTO_INCREMENT, value VARCHAR(255) NOT NULL, input_id BIGINT NOT NULL, INDEX input_id_idx (input_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE result (id BIGINT AUTO_INCREMENT, name VARCHAR(255) NOT NULL, PRIMARY KEY(id, name)) ENGINE = INNODB;
CREATE TABLE result_val (id BIGINT AUTO_INCREMENT, value VARCHAR(255) NOT NULL, result_id BIGINT NOT NULL, INDEX result_id_idx (result_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE value_assoc (resultval_id BIGINT, inputval_id BIGINT, PRIMARY KEY(resultval_id, inputval_id)) ENGINE = INNODB;
ALTER TABLE dependency ADD CONSTRAINT dependency_result_id_result_id FOREIGN KEY (result_id) REFERENCES result(id) ON DELETE CASCADE;
ALTER TABLE dependency ADD CONSTRAINT dependency_input_id_input_id FOREIGN KEY (input_id) REFERENCES input(id) ON DELETE CASCADE;
ALTER TABLE input_val ADD CONSTRAINT input_val_input_id_input_id FOREIGN KEY (input_id) REFERENCES input(id) ON DELETE CASCADE;
ALTER TABLE result_val ADD CONSTRAINT result_val_result_id_result_id FOREIGN KEY (result_id) REFERENCES result(id) ON DELETE CASCADE;
ALTER TABLE value_assoc ADD CONSTRAINT value_assoc_resultval_id_result_val_id FOREIGN KEY (resultval_id) REFERENCES result_val(id) ON DELETE CASCADE;
ALTER TABLE value_assoc ADD CONSTRAINT value_assoc_inputval_id_input_val_id FOREIGN KEY (inputval_id) REFERENCES input_val(id) ON DELETE CASCADE;
