CREATE TABLE about (id BIGINT AUTO_INCREMENT, multimedia_id BIGINT, rank BIGINT DEFAULT 0, INDEX multimedia_id_idx (multimedia_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE administrator (id BIGINT AUTO_INCREMENT, name VARCHAR(255) NOT NULL, surname VARCHAR(255), email VARCHAR(150) NOT NULL UNIQUE, password VARCHAR(128) NOT NULL, algorithm VARCHAR(128) DEFAULT 'sha1' NOT NULL, salt VARCHAR(128), token VARCHAR(255) NOT NULL UNIQUE, is_active TINYINT(1) DEFAULT '0', last_login DATETIME, credentials VARCHAR(100), is_tutor TINYINT(1) DEFAULT '0', avatar_min VARCHAR(255), avatar_med VARCHAR(255), avatar_max VARCHAR(255), biography TEXT, url_web VARCHAR(255), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE administrator_session (id BIGINT AUTO_INCREMENT, administrator_id BIGINT, ip VARCHAR(50), user_agent TEXT, accept_language VARCHAR(255) NOT NULL, date_logout DATETIME, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX administrator_id_idx (administrator_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE answer (id BIGINT AUTO_INCREMENT, game_id BIGINT, question_id BIGINT, question_option_id BIGINT, points FLOAT(18, 2) DEFAULT 0, is_completed TINYINT(1) DEFAULT '0', is_correct TINYINT(1) DEFAULT '0', date_started DATETIME, date_completed DATETIME, duration BIGINT DEFAULT 0, culture VARCHAR(10), calculated_type VARCHAR(20), INDEX game_id_idx (game_id), INDEX question_id_idx (question_id), INDEX question_option_id_idx (question_option_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE category_translation (id BIGINT, name VARCHAR(255), description TEXT, lang CHAR(2), PRIMARY KEY(id, lang)) ENGINE = INNODB;
CREATE TABLE category (id BIGINT AUTO_INCREMENT, piece_id BIGINT, multimedia_id BIGINT, num_questions BIGINT DEFAULT 1, INDEX piece_id_idx (piece_id), INDEX multimedia_id_idx (multimedia_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE challenge (id BIGINT AUTO_INCREMENT, player1_id BIGINT, player2_id BIGINT, date_started DATETIME, date_finished DATETIME, winner_id BIGINT, status VARCHAR(50), points_player1 BIGINT, points_player2 BIGINT, INDEX player1_id_idx (player1_id), INDEX player2_id_idx (player2_id), INDEX winner_id_idx (winner_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE challenge_answer (id BIGINT AUTO_INCREMENT, challenge_id BIGINT, answer_id BIGINT, miliseconds BIGINT, INDEX challenge_id_idx (challenge_id), INDEX answer_id_idx (answer_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE configuration_translation (id BIGINT, plain_text TEXT, long_text_wiki TEXT, long_text_html TEXT, file_name VARCHAR(100), file_mime_type VARCHAR(20), file_size BIGINT, lang CHAR(2), PRIMARY KEY(id, lang)) ENGINE = INNODB;
CREATE TABLE configuration (id BIGINT AUTO_INCREMENT, type VARCHAR(20), is_visible TINYINT(1) DEFAULT '1' NOT NULL, name VARCHAR(255), description TEXT, slug VARCHAR(100), category VARCHAR(100), number FLOAT(18, 2) DEFAULT 0 NOT NULL, number_min FLOAT(18, 2) DEFAULT 0 NOT NULL, number_max FLOAT(18, 2) DEFAULT 0 NOT NULL, date_from DATETIME, date_to DATETIME, is_checked TINYINT(1) DEFAULT '0' NOT NULL, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE custom1_translation (id BIGINT, name VARCHAR(255), description TEXT, lang CHAR(2), PRIMARY KEY(id, lang)) ENGINE = INNODB;
CREATE TABLE custom1 (id BIGINT AUTO_INCREMENT, rank BIGINT, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE custom2_translation (id BIGINT, name VARCHAR(255), description TEXT, lang CHAR(2), PRIMARY KEY(id, lang)) ENGINE = INNODB;
CREATE TABLE custom2 (id BIGINT AUTO_INCREMENT, rank BIGINT, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE custom3_translation (id BIGINT, name VARCHAR(255), description TEXT, lang CHAR(2), PRIMARY KEY(id, lang)) ENGINE = INNODB;
CREATE TABLE custom3 (id BIGINT AUTO_INCREMENT, rank BIGINT, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE documentation (id BIGINT AUTO_INCREMENT, multimedia_id BIGINT, rank BIGINT DEFAULT 0, INDEX multimedia_id_idx (multimedia_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE event (id BIGINT AUTO_INCREMENT, name VARCHAR(255), description TEXT, remote_id VARCHAR(20), is_active TINYINT(1) DEFAULT '1', PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE feedback_translation (id BIGINT, texto TEXT, lang CHAR(2), PRIMARY KEY(id, lang)) ENGINE = INNODB;
CREATE TABLE feedback (id BIGINT AUTO_INCREMENT, predeterminado TINYINT(1) DEFAULT '0', type VARCHAR(150), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE forum_message_translation (id BIGINT, message TEXT, lang CHAR(2), PRIMARY KEY(id, lang)) ENGINE = INNODB;
CREATE TABLE forum_message (id BIGINT AUTO_INCREMENT, title_id BIGINT, player_id BIGINT, active TINYINT(1) DEFAULT '0', date DATETIME, INDEX title_id_idx (title_id), INDEX player_id_idx (player_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE forum_title_translation (id BIGINT, title TEXT, lang CHAR(2), PRIMARY KEY(id, lang)) ENGINE = INNODB;
CREATE TABLE forum_title (id BIGINT AUTO_INCREMENT, active TINYINT(1) DEFAULT '0', PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE game (id BIGINT AUTO_INCREMENT, player_id BIGINT, profile_player_id BIGINT, zone_id BIGINT, event_id BIGINT, custom1_id BIGINT, custom2_id BIGINT, custom3_id BIGINT, num_answers_ok BIGINT DEFAULT 0, num_answers_error BIGINT DEFAULT 0, points DOUBLE(18, 2) DEFAULT 0, is_completed TINYINT(1) DEFAULT '0', date_started DATETIME, date_completed DATETIME, rank_player BIGINT, rank_general BIGINT, rank_zone BIGINT, rank_event BIGINT, rank_custom1 BIGINT, rank_custom2 BIGINT, rank_custom3 BIGINT, initial_level BIGINT, level_id BIGINT, INDEX player_id_idx (player_id), INDEX profile_player_id_idx (profile_player_id), INDEX zone_id_idx (zone_id), INDEX event_id_idx (event_id), INDEX custom1_id_idx (custom1_id), INDEX custom2_id_idx (custom2_id), INDEX custom3_id_idx (custom3_id), INDEX level_id_idx (level_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE game_configuration (id BIGINT AUTO_INCREMENT, game_id BIGINT, configuration_id BIGINT, culture VARCHAR(10), num_file_downloads BIGINT DEFAULT 0, num_video0 BIGINT DEFAULT 0, num_video25 BIGINT DEFAULT 0, num_video50 BIGINT DEFAULT 0, num_video75 BIGINT DEFAULT 0, num_video100 BIGINT DEFAULT 0, date_file_first DATETIME, date_file_last DATETIME, date_video_first DATETIME, date_video_last DATETIME, INDEX game_id_idx (game_id), INDEX configuration_id_idx (configuration_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE game_multimedia (id BIGINT AUTO_INCREMENT, game_id BIGINT, multimedia_id BIGINT, culture VARCHAR(10), num_file_downloads BIGINT DEFAULT 0, num_video0 BIGINT DEFAULT 0, num_video25 BIGINT DEFAULT 0, num_video50 BIGINT DEFAULT 0, num_video75 BIGINT DEFAULT 0, num_video100 BIGINT DEFAULT 0, date_file_first DATETIME, date_file_last DATETIME, date_video_first DATETIME, date_video_last DATETIME, INDEX game_id_idx (game_id), INDEX multimedia_id_idx (multimedia_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE glosary_translation (id BIGINT, name VARCHAR(255), description TEXT, example TEXT, lang CHAR(2), PRIMARY KEY(id, lang)) ENGINE = INNODB;
CREATE TABLE glosary (id BIGINT AUTO_INCREMENT, active TINYINT(1) DEFAULT '1', letter VARCHAR(1), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE instructions (id BIGINT AUTO_INCREMENT, multimedia_id BIGINT, rank BIGINT DEFAULT 0, INDEX multimedia_id_idx (multimedia_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE level_translation (id BIGINT, name TEXT, lang CHAR(2), PRIMARY KEY(id, lang)) ENGINE = INNODB;
CREATE TABLE level (id BIGINT AUTO_INCREMENT, level BIGINT, points BIGINT, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE multimedia_translation (id BIGINT, url TEXT, lang CHAR(2), PRIMARY KEY(id, lang)) ENGINE = INNODB;
CREATE TABLE multimedia (id BIGINT AUTO_INCREMENT, type VARCHAR(50), rank BIGINT, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE piece_translation (id BIGINT, name VARCHAR(255), description TEXT, lang CHAR(2), PRIMARY KEY(id, lang)) ENGINE = INNODB;
CREATE TABLE piece (id BIGINT AUTO_INCREMENT, rank BIGINT, color VARCHAR(10), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE piece_level (id BIGINT AUTO_INCREMENT, piece_id BIGINT, level_id BIGINT, INDEX piece_id_idx (piece_id), INDEX level_id_idx (level_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE player (id BIGINT AUTO_INCREMENT, zone_id BIGINT, event_id BIGINT, administrator_id BIGINT, custom1_id BIGINT, custom2_id BIGINT, custom3_id BIGINT, name VARCHAR(255) NOT NULL, surname VARCHAR(255), remote_id VARCHAR(50) UNIQUE, email VARCHAR(150) UNIQUE, is_active TINYINT(1) DEFAULT '1', is_sign_up TINYINT(1) DEFAULT '0', first_login DATETIME, last_login DATETIME, has_completed TINYINT(1) DEFAULT '0', date_has_completed DATETIME, culture VARCHAR(5) DEFAULT 'es', created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX zone_id_idx (zone_id), INDEX event_id_idx (event_id), INDEX administrator_id_idx (administrator_id), INDEX custom1_id_idx (custom1_id), INDEX custom2_id_idx (custom2_id), INDEX custom3_id_idx (custom3_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE profile_translation (id BIGINT, name VARCHAR(255), description TEXT, lang CHAR(2), PRIMARY KEY(id, lang)) ENGINE = INNODB;
CREATE TABLE profile (id BIGINT AUTO_INCREMENT, rank BIGINT, activated TINYINT(1) DEFAULT '0', PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE profile_category (id BIGINT AUTO_INCREMENT, profile_id BIGINT, category_id BIGINT, INDEX profile_id_idx (profile_id), INDEX category_id_idx (category_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE profile_piece (id BIGINT AUTO_INCREMENT, profile_id BIGINT, piece_id BIGINT, INDEX profile_id_idx (profile_id), INDEX piece_id_idx (piece_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE profile_player (id BIGINT AUTO_INCREMENT, profile_id BIGINT, player_id BIGINT, INDEX profile_id_idx (profile_id), INDEX player_id_idx (player_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE question_translation (id BIGINT, name VARCHAR(150), question TEXT, question_data TEXT, lang CHAR(2), PRIMARY KEY(id, lang)) ENGINE = INNODB;
CREATE TABLE question (id BIGINT AUTO_INCREMENT, piece_id BIGINT, type VARCHAR(20), category_id BIGINT, multimedia_id BIGINT, exercise_type VARCHAR(20), feedback_ok BIGINT, feedback_error BIGINT, feedback_time BIGINT, rank BIGINT, INDEX piece_id_idx (piece_id), INDEX category_id_idx (category_id), INDEX multimedia_id_idx (multimedia_id), INDEX feedback_time_idx (feedback_time), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE question_multimedia (id BIGINT AUTO_INCREMENT, question_id BIGINT, multimedia_id BIGINT, INDEX question_id_idx (question_id), INDEX multimedia_id_idx (multimedia_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE question_option_translation (id BIGINT, content TEXT, feedback TEXT, option_data TEXT, lang CHAR(2), PRIMARY KEY(id, lang)) ENGINE = INNODB;
CREATE TABLE question_option (id BIGINT AUTO_INCREMENT, question_id BIGINT, is_correct TINYINT(1) DEFAULT '0', rank BIGINT, INDEX question_id_idx (question_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE user (id BIGINT AUTO_INCREMENT, player_id BIGINT, name VARCHAR(255) NOT NULL, surname VARCHAR(255), email VARCHAR(150) NOT NULL UNIQUE, password VARCHAR(128) NOT NULL, algorithm VARCHAR(128) DEFAULT 'sha1' NOT NULL, salt VARCHAR(128), token VARCHAR(255) NOT NULL UNIQUE, is_active TINYINT(1) DEFAULT '0', last_login DATETIME, credentials VARCHAR(100), is_tutor TINYINT(1) DEFAULT '0', avatar_min VARCHAR(255), avatar_med VARCHAR(255), avatar_max VARCHAR(255), biography TEXT, url_web VARCHAR(255), pass_change_date DATETIME, pass_change_token VARCHAR(255), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX player_id_idx (player_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE user_session (id BIGINT AUTO_INCREMENT, user_id BIGINT, ip VARCHAR(50), user_agent TEXT, accept_language VARCHAR(255) NOT NULL, date_logout DATETIME, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX user_id_idx (user_id), PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE variables (id BIGINT AUTO_INCREMENT, slug VARCHAR(255), value TEXT, description TEXT, PRIMARY KEY(id)) ENGINE = INNODB;
CREATE TABLE zone_translation (id BIGINT, name VARCHAR(100), lang CHAR(2), PRIMARY KEY(id, lang)) ENGINE = INNODB;
CREATE TABLE zone (id BIGINT AUTO_INCREMENT, country VARCHAR(10), iso_code VARCHAR(10), remote_id VARCHAR(20), is_special TINYINT(1) DEFAULT '0', PRIMARY KEY(id)) ENGINE = INNODB;
ALTER TABLE about ADD CONSTRAINT about_multimedia_id_multimedia_id FOREIGN KEY (multimedia_id) REFERENCES multimedia(id) ON DELETE CASCADE;
ALTER TABLE administrator_session ADD CONSTRAINT administrator_session_administrator_id_administrator_id FOREIGN KEY (administrator_id) REFERENCES administrator(id) ON DELETE SET NULL;
ALTER TABLE answer ADD CONSTRAINT answer_question_option_id_question_option_id FOREIGN KEY (question_option_id) REFERENCES question_option(id) ON DELETE CASCADE;
ALTER TABLE answer ADD CONSTRAINT answer_question_id_question_id FOREIGN KEY (question_id) REFERENCES question(id) ON DELETE CASCADE;
ALTER TABLE answer ADD CONSTRAINT answer_game_id_game_id FOREIGN KEY (game_id) REFERENCES game(id) ON DELETE CASCADE;
ALTER TABLE category_translation ADD CONSTRAINT category_translation_id_category_id FOREIGN KEY (id) REFERENCES category(id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE category ADD CONSTRAINT category_piece_id_piece_id FOREIGN KEY (piece_id) REFERENCES piece(id) ON DELETE CASCADE;
ALTER TABLE category ADD CONSTRAINT category_multimedia_id_multimedia_id FOREIGN KEY (multimedia_id) REFERENCES multimedia(id) ON DELETE SET NULL;
ALTER TABLE challenge ADD CONSTRAINT challenge_winner_id_player_id FOREIGN KEY (winner_id) REFERENCES player(id) ON DELETE SET NULL;
ALTER TABLE challenge ADD CONSTRAINT challenge_player2_id_player_id FOREIGN KEY (player2_id) REFERENCES player(id) ON DELETE CASCADE;
ALTER TABLE challenge ADD CONSTRAINT challenge_player1_id_player_id FOREIGN KEY (player1_id) REFERENCES player(id) ON DELETE CASCADE;
ALTER TABLE challenge_answer ADD CONSTRAINT challenge_answer_challenge_id_challenge_id FOREIGN KEY (challenge_id) REFERENCES challenge(id) ON DELETE CASCADE;
ALTER TABLE challenge_answer ADD CONSTRAINT challenge_answer_answer_id_answer_id FOREIGN KEY (answer_id) REFERENCES answer(id) ON DELETE CASCADE;
ALTER TABLE configuration_translation ADD CONSTRAINT configuration_translation_id_configuration_id FOREIGN KEY (id) REFERENCES configuration(id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE custom1_translation ADD CONSTRAINT custom1_translation_id_custom1_id FOREIGN KEY (id) REFERENCES custom1(id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE custom2_translation ADD CONSTRAINT custom2_translation_id_custom2_id FOREIGN KEY (id) REFERENCES custom2(id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE custom3_translation ADD CONSTRAINT custom3_translation_id_custom3_id FOREIGN KEY (id) REFERENCES custom3(id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE documentation ADD CONSTRAINT documentation_multimedia_id_multimedia_id FOREIGN KEY (multimedia_id) REFERENCES multimedia(id) ON DELETE CASCADE;
ALTER TABLE feedback_translation ADD CONSTRAINT feedback_translation_id_feedback_id FOREIGN KEY (id) REFERENCES feedback(id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE forum_message_translation ADD CONSTRAINT forum_message_translation_id_forum_message_id FOREIGN KEY (id) REFERENCES forum_message(id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE forum_message ADD CONSTRAINT forum_message_title_id_forum_title_id FOREIGN KEY (title_id) REFERENCES forum_title(id) ON DELETE CASCADE;
ALTER TABLE forum_message ADD CONSTRAINT forum_message_player_id_player_id FOREIGN KEY (player_id) REFERENCES player(id) ON DELETE SET NULL;
ALTER TABLE forum_title_translation ADD CONSTRAINT forum_title_translation_id_forum_title_id FOREIGN KEY (id) REFERENCES forum_title(id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE game ADD CONSTRAINT game_zone_id_zone_id FOREIGN KEY (zone_id) REFERENCES zone(id) ON DELETE CASCADE;
ALTER TABLE game ADD CONSTRAINT game_profile_player_id_profile_player_id FOREIGN KEY (profile_player_id) REFERENCES profile_player(id) ON DELETE CASCADE;
ALTER TABLE game ADD CONSTRAINT game_player_id_player_id FOREIGN KEY (player_id) REFERENCES player(id) ON DELETE CASCADE;
ALTER TABLE game ADD CONSTRAINT game_level_id_level_id FOREIGN KEY (level_id) REFERENCES level(id) ON DELETE CASCADE;
ALTER TABLE game ADD CONSTRAINT game_event_id_event_id FOREIGN KEY (event_id) REFERENCES event(id) ON DELETE CASCADE;
ALTER TABLE game ADD CONSTRAINT game_custom3_id_custom3_id FOREIGN KEY (custom3_id) REFERENCES custom3(id) ON DELETE CASCADE;
ALTER TABLE game ADD CONSTRAINT game_custom2_id_custom2_id FOREIGN KEY (custom2_id) REFERENCES custom2(id) ON DELETE CASCADE;
ALTER TABLE game ADD CONSTRAINT game_custom1_id_custom1_id FOREIGN KEY (custom1_id) REFERENCES custom1(id) ON DELETE CASCADE;
ALTER TABLE game_configuration ADD CONSTRAINT game_configuration_game_id_game_id FOREIGN KEY (game_id) REFERENCES game(id) ON DELETE CASCADE;
ALTER TABLE game_configuration ADD CONSTRAINT game_configuration_configuration_id_configuration_id FOREIGN KEY (configuration_id) REFERENCES configuration(id) ON DELETE CASCADE;
ALTER TABLE game_multimedia ADD CONSTRAINT game_multimedia_multimedia_id_multimedia_id FOREIGN KEY (multimedia_id) REFERENCES multimedia(id) ON DELETE CASCADE;
ALTER TABLE game_multimedia ADD CONSTRAINT game_multimedia_game_id_game_id FOREIGN KEY (game_id) REFERENCES game(id) ON DELETE CASCADE;
ALTER TABLE glosary_translation ADD CONSTRAINT glosary_translation_id_glosary_id FOREIGN KEY (id) REFERENCES glosary(id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE instructions ADD CONSTRAINT instructions_multimedia_id_multimedia_id FOREIGN KEY (multimedia_id) REFERENCES multimedia(id) ON DELETE CASCADE;
ALTER TABLE level_translation ADD CONSTRAINT level_translation_id_level_id FOREIGN KEY (id) REFERENCES level(id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE multimedia_translation ADD CONSTRAINT multimedia_translation_id_multimedia_id FOREIGN KEY (id) REFERENCES multimedia(id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE piece_translation ADD CONSTRAINT piece_translation_id_piece_id FOREIGN KEY (id) REFERENCES piece(id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE piece_level ADD CONSTRAINT piece_level_piece_id_piece_id FOREIGN KEY (piece_id) REFERENCES piece(id) ON DELETE CASCADE;
ALTER TABLE piece_level ADD CONSTRAINT piece_level_level_id_level_id FOREIGN KEY (level_id) REFERENCES level(id) ON DELETE CASCADE;
ALTER TABLE player ADD CONSTRAINT player_zone_id_zone_id FOREIGN KEY (zone_id) REFERENCES zone(id) ON DELETE SET NULL;
ALTER TABLE player ADD CONSTRAINT player_event_id_event_id FOREIGN KEY (event_id) REFERENCES event(id) ON DELETE SET NULL;
ALTER TABLE player ADD CONSTRAINT player_custom3_id_custom3_id FOREIGN KEY (custom3_id) REFERENCES custom3(id) ON DELETE SET NULL;
ALTER TABLE player ADD CONSTRAINT player_custom2_id_custom2_id FOREIGN KEY (custom2_id) REFERENCES custom2(id) ON DELETE SET NULL;
ALTER TABLE player ADD CONSTRAINT player_custom1_id_custom1_id FOREIGN KEY (custom1_id) REFERENCES custom1(id) ON DELETE SET NULL;
ALTER TABLE player ADD CONSTRAINT player_administrator_id_administrator_id FOREIGN KEY (administrator_id) REFERENCES administrator(id) ON DELETE SET NULL;
ALTER TABLE profile_translation ADD CONSTRAINT profile_translation_id_profile_id FOREIGN KEY (id) REFERENCES profile(id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE profile_category ADD CONSTRAINT profile_category_profile_id_profile_id FOREIGN KEY (profile_id) REFERENCES profile(id) ON DELETE SET NULL;
ALTER TABLE profile_category ADD CONSTRAINT profile_category_category_id_category_id FOREIGN KEY (category_id) REFERENCES category(id) ON DELETE SET NULL;
ALTER TABLE profile_piece ADD CONSTRAINT profile_piece_profile_id_profile_id FOREIGN KEY (profile_id) REFERENCES profile(id) ON DELETE SET NULL;
ALTER TABLE profile_piece ADD CONSTRAINT profile_piece_piece_id_piece_id FOREIGN KEY (piece_id) REFERENCES piece(id) ON DELETE SET NULL;
ALTER TABLE profile_player ADD CONSTRAINT profile_player_profile_id_profile_id FOREIGN KEY (profile_id) REFERENCES profile(id) ON DELETE SET NULL;
ALTER TABLE profile_player ADD CONSTRAINT profile_player_player_id_player_id FOREIGN KEY (player_id) REFERENCES player(id) ON DELETE SET NULL;
ALTER TABLE question_translation ADD CONSTRAINT question_translation_id_question_id FOREIGN KEY (id) REFERENCES question(id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE question ADD CONSTRAINT question_piece_id_piece_id FOREIGN KEY (piece_id) REFERENCES piece(id) ON DELETE CASCADE;
ALTER TABLE question ADD CONSTRAINT question_multimedia_id_multimedia_id FOREIGN KEY (multimedia_id) REFERENCES multimedia(id) ON DELETE SET NULL;
ALTER TABLE question ADD CONSTRAINT question_feedback_time_feedback_id FOREIGN KEY (feedback_time) REFERENCES feedback(id) ON DELETE SET NULL;
ALTER TABLE question ADD CONSTRAINT question_category_id_category_id FOREIGN KEY (category_id) REFERENCES category(id) ON DELETE SET NULL;
ALTER TABLE question_multimedia ADD CONSTRAINT question_multimedia_question_id_question_id FOREIGN KEY (question_id) REFERENCES question(id) ON DELETE CASCADE;
ALTER TABLE question_multimedia ADD CONSTRAINT question_multimedia_multimedia_id_multimedia_id FOREIGN KEY (multimedia_id) REFERENCES multimedia(id) ON DELETE CASCADE;
ALTER TABLE question_option_translation ADD CONSTRAINT question_option_translation_id_question_option_id FOREIGN KEY (id) REFERENCES question_option(id) ON UPDATE CASCADE ON DELETE CASCADE;
ALTER TABLE question_option ADD CONSTRAINT question_option_question_id_question_id FOREIGN KEY (question_id) REFERENCES question(id) ON DELETE CASCADE;
ALTER TABLE user ADD CONSTRAINT user_player_id_player_id FOREIGN KEY (player_id) REFERENCES player(id) ON DELETE CASCADE;
ALTER TABLE user_session ADD CONSTRAINT user_session_user_id_user_id FOREIGN KEY (user_id) REFERENCES user(id) ON DELETE SET NULL;
ALTER TABLE zone_translation ADD CONSTRAINT zone_translation_id_zone_id FOREIGN KEY (id) REFERENCES zone(id) ON UPDATE CASCADE ON DELETE CASCADE;
