CREATE TABLE IF NOT EXISTS prefix_test (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    title char(255) NOT NULL,
    description TEXT,
    creator bigint(20) UNSIGNED DEFAULT NULL,
    created TIMESTAMP DEFAULT NOW(),
    modified TIMESTAMP,
    active BOOLEAN DEFAULT FALSE,
    position int(4),
    FOREIGN KEY (creator) REFERENCES prefix_users (id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_test_groups (
    test_id bigint(20) UNSIGNED DEFAULT NULL,
    group_id bigint(20) UNSIGNED DEFAULT NULL,
    FOREIGN KEY (test_id) REFERENCES prefix_test (id) ON DELETE CASCADE,
    FOREIGN KEY (group_id) REFERENCES prefix_groups (id) ON DELETE CASCADE,
    PRIMARY KEY test_group (test_id, group_id)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_folder (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    folder bigint(20) UNSIGNED DEFAULT NULL,
    title char(255) NOT NULL,
    description TEXT,
    creator bigint(20) UNSIGNED DEFAULT NULL,
    created TIMESTAMP DEFAULT NOW(),
    modified TIMESTAMP,
    position int(4),
    status ENUM('draft', 'final') DEFAULT 'draft',
    security ENUM('public', 'private') DEFAULT 'public',
    deleted BOOLEAN DEFAULT FALSE,
    FOREIGN KEY (creator) REFERENCES prefix_users (id) ON DELETE SET NULL,
    FOREIGN KEY (folder) REFERENCES prefix_folder (id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_test_folder (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    type char(255) NOT NULL DEFAULT 'TestFolder',
    folder bigint(20) UNSIGNED DEFAULT NULL,
    title char(255) NOT NULL,
    description TEXT,
    creator bigint(20) UNSIGNED DEFAULT NULL,
    created TIMESTAMP DEFAULT NOW(),
    modified TIMESTAMP,
    rights char(255) NOT NULL,
    info TEXT,
    authors TEXT,
    position int(4),
    status ENUM('draft', 'final') DEFAULT 'draft',
    security ENUM('public', 'private') DEFAULT 'public',
    deleted BOOLEAN DEFAULT FALSE,
    locked BOOLEAN DEFAULT FALSE,
    test bigint(20) UNSIGNED DEFAULT NULL,
    cache TEXT,
    cached TIMESTAMP,
    FOREIGN KEY (creator) REFERENCES prefix_users (id) ON DELETE SET NULL,
    FOREIGN KEY (test) REFERENCES prefix_test (id) ON DELETE CASCADE,
    FOREIGN KEY (folder) REFERENCES prefix_folder (id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_test_folder_cache (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    test_folder bigint(20) UNSIGNED DEFAULT NULL,
    html LONGTEXT,
    csv LONGTEXT,
    created TIMESTAMP DEFAULT NOW(),
    stopped TIMESTAMP,
    running BOOLEAN DEFAULT TRUE,
    error TEXT,
    examinees int(5),
    FOREIGN KEY (test_folder) REFERENCES prefix_test_folder (id) ON DELETE CASCADE,
    UNIQUE (test_folder)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_answer (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    test bigint(20) UNSIGNED DEFAULT NULL,
    examinee bigint(20) UNSIGNED DEFAULT NULL,
    begin TIMESTAMP DEFAULT NOW(),
    end TIMESTAMP,
    chapter bigint(20) UNSIGNED DEFAULT NULL,
    last_page INT(5) DEFAULT -1,
    current_page INT(5) DEFAULT 0,
    FOREIGN KEY (examinee) REFERENCES prefix_examinees (id) ON DELETE SET NULL,
    FOREIGN KEY (test) REFERENCES prefix_test (id) ON DELETE SET NULL,
    FOREIGN KEY (chapter) REFERENCES prefix_test_folder (id) ON DELETE SET NULL,
    UNIQUE examinee_answer (test, examinee)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_chapter (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    chapter bigint(20) UNSIGNED DEFAULT NULL,
    answer bigint(20) UNSIGNED NOT NULL,
    examinee bigint(20) UNSIGNED DEFAULT NULL,
    locked BOOLEAN DEFAULT FALSE,
    FOREIGN KEY (answer) REFERENCES prefix_answer (id) ON DELETE CASCADE,
    FOREIGN KEY (chapter) REFERENCES prefix_test_folder (id) ON DELETE SET NULL,
    FOREIGN KEY (examinee) REFERENCES prefix_examinees (id) ON DELETE CASCADE,
    UNIQUE examinee_chapter (chapter, answer, examinee)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_base_object (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    type char(255) NOT NULL,
    title char(255) NOT NULL,
    instructions TEXT,
    instructions_top BOOLEAN DEFAULT TRUE,
    creator bigint(20) UNSIGNED DEFAULT NULL,
    created TIMESTAMP DEFAULT NOW(),
    modified TIMESTAMP,
    time int(6),
    rights char(255) NOT NULL,
    info TEXT,
    authors TEXT,
    folder bigint(20) UNSIGNED NOT NULL,
    position int(4),
    status ENUM('draft', 'final') DEFAULT 'draft',
    security ENUM('public', 'private') DEFAULT 'public',
    deleted BOOLEAN DEFAULT FALSE,
    locked BOOLEAN DEFAULT FALSE,
    time_button BOOLEAN DEFAULT FALSE,
    screenshot bigint(20) UNSIGNED DEFAULT NULL,
    FOREIGN KEY (screenshot) REFERENCES prefix_images (id) ON DELETE SET NULL,
    FOREIGN KEY (folder) REFERENCES prefix_test_folder (id) ON DELETE CASCADE,
    FOREIGN KEY (creator) REFERENCES prefix_users (id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_text_stimulus (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    body TEXT,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_tmt_task (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    elements TEXT,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_tmt_answer (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    examinee bigint(20) UNSIGNED DEFAULT NULL,
    elements TEXT,
    faults INT(3),
    load_time INT(6),
    task_time INT(6),
    start INT(11),
    end INT(11),
    time_load INT(11),
    time_start INT(11),
    time_end INT(11),
    time_submit INT(11),
    FOREIGN KEY (examinee) REFERENCES prefix_examinees (id) ON DELETE SET NULL,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE,
    UNIQUE examinee_answer (base_id, examinee)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_drag_task (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    body_image bigint(20) UNSIGNED DEFAULT NULL,
    elements TEXT,
    answer_required BOOLEAN DEFAULT FALSE,
    text_title TEXT,
    text_input BOOLEAN DEFAULT FALSE,
    text_value TEXT,
    text_rows TINYINT(4) DEFAULT 3,
    text_cols TINYINT(4) DEFAULT 25,
    text_charcount INT(11) DEFAULT 0,
    text_charcounter BOOLEAN DEFAULT FALSE,
    FOREIGN KEY (body_image) REFERENCES prefix_images (id) ON DELETE SET NULL,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_image_drag_task (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    drag_image_1 bigint(20) UNSIGNED DEFAULT NULL,
    drag_image_2 bigint(20) UNSIGNED DEFAULT NULL,
    drag_image_3 bigint(20) UNSIGNED DEFAULT NULL,
    drag_image_4 bigint(20) UNSIGNED DEFAULT NULL,
    drag_image_5 bigint(20) UNSIGNED DEFAULT NULL,
    drag_image_6 bigint(20) UNSIGNED DEFAULT NULL,
    elements TEXT,
    element_size TINYINT(4) DEFAULT 1,
    answer_required BOOLEAN DEFAULT FALSE,
    text_title TEXT,
    text_input BOOLEAN DEFAULT FALSE,
    text_value TEXT,
    text_rows TINYINT(4) DEFAULT 3,
    text_cols TINYINT(4) DEFAULT 25,
    text_charcount INT(11) DEFAULT 0,
    text_charcounter BOOLEAN DEFAULT FALSE,
    FOREIGN KEY (drag_image_1) REFERENCES prefix_images (id) ON DELETE SET NULL,
    FOREIGN KEY (drag_image_2) REFERENCES prefix_images (id) ON DELETE SET NULL,
    FOREIGN KEY (drag_image_3) REFERENCES prefix_images (id) ON DELETE SET NULL,
    FOREIGN KEY (drag_image_4) REFERENCES prefix_images (id) ON DELETE SET NULL,
    FOREIGN KEY (drag_image_5) REFERENCES prefix_images (id) ON DELETE SET NULL,
    FOREIGN KEY (drag_image_6) REFERENCES prefix_images (id) ON DELETE SET NULL,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_image_drag_answer (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    examinee bigint(20) UNSIGNED DEFAULT NULL,
    answer TEXT,
    start INT(11),
    end INT(11),
    textfield TEXT,
    time_load INT(11),
    time_start INT(11),
    time_end INT(11),
    time_submit INT(11),
    FOREIGN KEY (examinee) REFERENCES prefix_examinees (id) ON DELETE SET NULL,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE,
    UNIQUE examinee_answer (base_id, examinee)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_ks_task (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    elements TEXT,
    task_type TINYINT DEFAULT 1,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;


CREATE TABLE IF NOT EXISTS prefix_ks_answer (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    examinee bigint(20) UNSIGNED DEFAULT NULL,
    elements TEXT,
    start INT(11),
    end INT(11),
    time_load INT(11),
    time_start INT(11),
    time_end INT(11),
    time_submit INT(11),
    FOREIGN KEY (examinee) REFERENCES prefix_examinees (id) ON DELETE SET NULL,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE,
    UNIQUE examinee_answer (base_id, examinee)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_slider_task (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    options TEXT,
    corrects TEXT,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_slider_answer (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    examinee bigint(20) UNSIGNED DEFAULT NULL,
    answer TEXT,
    time_load INT(11),
    time_start INT(11),
    time_end INT(11),
    time_submit INT(11),
    FOREIGN KEY (examinee) REFERENCES prefix_examinees (id) ON DELETE SET NULL,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE,
    UNIQUE examinee_answer (base_id, examinee)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_choice_task (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    body_image bigint(20) UNSIGNED DEFAULT NULL,
    body_video char(255) DEFAULT NULL,
    video_zoom INT DEFAULT 100,
    video_autoplay BOOLEAN DEFAULT FALSE,
    table_height INT DEFAULT 0,
    table_width INT DEFAULT 0,
    multiple_choice BOOLEAN DEFAULT FALSE,
    answer_required BOOLEAN DEFAULT FALSE,
    choices_per_page INT DEFAULT 0,
    table_has_border BOOLEAN DEFAULT FALSE,
    text_title TEXT,
    text_input BOOLEAN DEFAULT FALSE,
    text_value TEXT,
    text_rows TINYINT(4) DEFAULT 3,
    text_cols TINYINT(4) DEFAULT 25,
    text_charcount INT(11) DEFAULT 0,
    text_charcounter BOOLEAN DEFAULT FALSE,
    text_pos TINYINT(1) DEFAULT 1,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE,
    FOREIGN KEY (body_image) REFERENCES prefix_images (id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_choice_answer (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    examinee bigint(20) UNSIGNED DEFAULT NULL,
    textfield TEXT,
    start INT(11),
    end INT(11),
    time_load INT(11),
    time_start INT(11),
    time_end INT(11),
    time_submit INT(11),
    FOREIGN KEY (examinee) REFERENCES prefix_examinees (id) ON DELETE SET NULL,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE,
    UNIQUE examinee_answer (base_id, examinee)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_picture_stimulus (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    body_image bigint(20) UNSIGNED DEFAULT NULL,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE,
    FOREIGN KEY (body_image) REFERENCES prefix_images (id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_multi_picture_stimulus (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    display_all BOOLEAN DEFAULT TRUE,
    table_height INT DEFAULT 1,
    table_width INT DEFAULT 1,
    table_has_border BOOLEAN DEFAULT FALSE,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_word_stimulus (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    display_all BOOLEAN DEFAULT TRUE,
    table_height INT DEFAULT 1,
    table_width INT DEFAULT 1,
    table_has_border BOOLEAN DEFAULT FALSE,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_sound_stimulus (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    sound bigint(20) UNSIGNED DEFAULT NULL,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE,
    FOREIGN KEY (sound) REFERENCES prefix_sounds (id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_sound_task (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    sound bigint(20) UNSIGNED DEFAULT NULL,
    sound_autoplay BOOLEAN DEFAULT FALSE,
    table_height INT DEFAULT 0,
    table_width INT DEFAULT 0,
    multiple_choice BOOLEAN DEFAULT FALSE,
    answer_required BOOLEAN DEFAULT FALSE,
    choices_per_page INT DEFAULT 0,
    table_has_border BOOLEAN DEFAULT FALSE,
    text_title TEXT,
    text_input BOOLEAN DEFAULT FALSE,
    text_value TEXT,
    text_rows TINYINT(4) DEFAULT 3,
    text_cols TINYINT(4) DEFAULT 25,
    text_pos TINYINT(1) DEFAULT 1,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE,
    FOREIGN KEY (sound) REFERENCES prefix_sounds (id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_sound_answer (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    examinee bigint(20) UNSIGNED DEFAULT NULL,
    textfield TEXT,
    start INT(11),
    end INT(11),
    time_load INT(11),
    time_start INT(11),
    time_end INT(11),
    time_submit INT(11),
    FOREIGN KEY (examinee) REFERENCES prefix_examinees (id) ON DELETE SET NULL,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE,
    UNIQUE examinee_answer (base_id, examinee)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_sound_stimulus (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    sound bigint(20) UNSIGNED DEFAULT NULL,
    sound_autoplay BOOLEAN DEFAULT FALSE,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE,
    FOREIGN KEY (sound) REFERENCES prefix_sounds (id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_questionnaire (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    questions_per_page INT DEFAULT 0,
    questions_in_table BOOLEAN DEFAULT FALSE,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_questionnaire_answer (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    examinee bigint(20) UNSIGNED DEFAULT NULL,
    time_load INT(11),
    time_start INT(11),
    time_end INT(11),
    time_submit INT(11),
    FOREIGN KEY (examinee) REFERENCES prefix_examinees (id) ON DELETE SET NULL,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE,
    UNIQUE examinee_answer (base_id, examinee)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_questions (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    parent bigint(20) UNSIGNED NOT NULL,
    title TEXT,
    text_title TEXT,
    text_input BOOLEAN DEFAULT FALSE,
    text_value TEXT,
    text_rows TINYINT(4) DEFAULT 3,
    text_cols TINYINT(4) DEFAULT 25,
    text_charcount INT(11) DEFAULT 0,
    text_charcounter BOOLEAN DEFAULT FALSE,
    text_pos TINYINT(1) DEFAULT 1,
    text_before TINYINT(1) DEFAULT 0,
    margin_top INT(6) DEFAULT 0,
    margin_bottom INT(6) DEFAULT 0,
    position int(4),
    multiple_choice BOOLEAN DEFAULT FALSE,
    answer_required BOOLEAN DEFAULT FALSE,
    table_has_border BOOLEAN DEFAULT FALSE,
    use_question_title BOOLEAN DEFAULT TRUE,
    format TINYINT(1) DEFAULT 1,
    locked BOOLEAN DEFAULT FALSE,
    FOREIGN KEY (parent) REFERENCES prefix_base_object (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_questions_answer (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    question_id bigint(20) UNSIGNED NOT NULL,
    examinee bigint(20) UNSIGNED DEFAULT NULL,
    textfield TEXT,
    start INT(11),
    end INT(11),
    FOREIGN KEY (examinee) REFERENCES prefix_examinees (id) ON DELETE SET NULL,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE,
    FOREIGN KEY (question_id) REFERENCES prefix_questions (id) ON DELETE CASCADE,
    UNIQUE examinee_answer (base_id, question_id, examinee)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_choices (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    parent bigint(20) UNSIGNED NOT NULL,
    nr INT DEFAULT 0,
    question bigint(20) UNSIGNED DEFAULT NULL,
    title TEXT,
    image bigint(20) UNSIGNED DEFAULT NULL,
    use_title BOOLEAN DEFAULT FALSE,
    already_checked BOOLEAN DEFAULT FALSE,
    right_choice_1 BOOLEAN DEFAULT FALSE,
    right_choice_2 BOOLEAN DEFAULT FALSE,
    position TINYINT(1) DEFAULT 1,
    pos int(4),
    locked BOOLEAN DEFAULT FALSE,
    FOREIGN KEY (parent) REFERENCES prefix_base_object (id) ON DELETE CASCADE,
    FOREIGN KEY (question) REFERENCES prefix_questions (id) ON DELETE SET NULL,
    FOREIGN KEY (image) REFERENCES prefix_images (id) ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_choices_answer (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    question_id bigint(20) UNSIGNED DEFAULT NULL,
    choice_id bigint(20) UNSIGNED NOT NULL,
    examinee bigint(20) UNSIGNED DEFAULT NULL,
    choice TINYINT(1) DEFAULT 0,
    start INT(11),
    end INT(11),
    FOREIGN KEY (examinee) REFERENCES prefix_examinees (id) ON DELETE SET NULL,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE,
    FOREIGN KEY (question_id) REFERENCES prefix_questions (id) ON DELETE SET NULL,
    FOREIGN KEY (choice_id) REFERENCES prefix_choices (id) ON DELETE CASCADE,
    UNIQUE examinee_answer (examinee, base_id, choice_id)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_flower_task (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    table_height INT DEFAULT 1,
    table_width INT DEFAULT 1,
    flower_table TEXT,
    right_choice TEXT,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_flower_answer (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    examinee bigint(20) UNSIGNED DEFAULT NULL,
    choice TINYINT(1),
    clicked INT(5),
    start INT(11),
    end INT(11),
    time_load INT(11),
    time_start INT(11),
    time_end INT(11),
    time_submit INT(11),
    FOREIGN KEY (examinee) REFERENCES prefix_examinees (id) ON DELETE SET NULL,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE,
    UNIQUE examinee_answer (base_id, examinee)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_hedgehog_task (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    table_height INT DEFAULT 1,
    table_width INT DEFAULT 1,
    task_type ENUM('hedgehog', 'dog') DEFAULT 'hedgehog',
    ask_number_of_steps BOOLEAN DEFAULT TRUE,
    landscape_table TEXT,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_hedgehog_answer (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    examinee bigint(20) UNSIGNED DEFAULT NULL,
    total INT(5) DEFAULT 0,
    empty INT(5) DEFAULT 0,
    hill INT(5) DEFAULT 0,
    river INT(5) DEFAULT 0,
    answer INT(5) DEFAULT 0,
    moves TEXT,
    start INT(11),
    end INT(11),
    time_load INT(11),
    time_start INT(11),
    time_end INT(11),
    time_submit INT(11),
    FOREIGN KEY (examinee) REFERENCES prefix_examinees (id) ON DELETE SET NULL,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE,
    UNIQUE examinee_answer (base_id, examinee)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_keeper_task (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    table_height INT DEFAULT 8,
    table_width INT DEFAULT 8,
    text_title TEXT,
    text_input BOOLEAN DEFAULT FALSE,
    text_value TEXT,
    text_rows TINYINT(4) DEFAULT 3,
    text_cols TINYINT(4) DEFAULT 25,
    text_pos TINYINT(1) DEFAULT 1,
    floor TEXT,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_keeper_answer (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    examinee bigint(20) UNSIGNED DEFAULT NULL,
    different INT(5) DEFAULT 0,
    walls INT(5) DEFAULT 0,
    textfield TEXT,
    moves TEXT,
    steps TEXT,
    load_time INT(11),
    start INT(11),
    end INT(11),
    time_load INT(11),
    time_start INT(11),
    time_end INT(11),
    time_submit INT(11),
    FOREIGN KEY (examinee) REFERENCES prefix_examinees (id) ON DELETE SET NULL,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE,
    UNIQUE examinee_answer (base_id, examinee)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_timeelapse_task (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    elements TEXT,
    tasks INT(5) DEFAULT 1,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_timeelapse_answer (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    examinee bigint(20) UNSIGNED DEFAULT NULL,
    elements TEXT,
    start INT(11),
    end INT(11),
    time_load INT(11),
    time_start INT(11),
    time_end INT(11),
    time_submit INT(11),
    FOREIGN KEY (examinee) REFERENCES prefix_examinees (id) ON DELETE SET NULL,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE,
    UNIQUE examinee_answer (base_id, examinee)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

CREATE TABLE IF NOT EXISTS prefix_screenshot (
    id bigint(20) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
    base_id bigint(20) UNSIGNED NOT NULL,
    screenshot BLOB,
    created TIMESTAMP DEFAULT NOW(),
    modified TIMESTAMP,
    FOREIGN KEY (base_id) REFERENCES prefix_base_object (id) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;
