DROP TABLE IF EXISTS b_iblock_element_property;
DROP TABLE IF EXISTS b_iblock_property;
DROP TABLE IF EXISTS b_iblock_element;
DROP TABLE IF EXISTS b_file;

CREATE TABLE b_file (
    ID INT PRIMARY KEY,
    SUBDIR VARCHAR(255),
    FILE_NAME VARCHAR(255)
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

CREATE TABLE b_iblock_element (
    ID INT PRIMARY KEY,
    IBLOCK_ID INT,
    IBLOCK_SECTION_ID INT NULL,
    WF_PARENT_ELEMENT_ID INT NULL,
    XML_ID VARCHAR(255) NULL,
    NAME VARCHAR(255),
    ACTIVE CHAR(1) DEFAULT 'Y',
    CODE VARCHAR(255),
    PREVIEW_PICTURE INT NULL,
    PREVIEW_TEXT TEXT,
    DETAIL_TEXT TEXT,
    DATE_CREATE DATETIME DEFAULT CURRENT_TIMESTAMP,
    TIMESTAMP_X DATETIME DEFAULT CURRENT_TIMESTAMP
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

CREATE TABLE b_iblock_property (
    ID INT PRIMARY KEY,
    IBLOCK_ID INT,
    NAME VARCHAR(255),
    CODE VARCHAR(255),
    ACTIVE CHAR(1) DEFAULT 'Y'
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

CREATE TABLE b_iblock_element_property (
    ID INT PRIMARY KEY AUTO_INCREMENT,
    IBLOCK_PROPERTY_ID INT,
    IBLOCK_ELEMENT_ID INT,
    VALUE TEXT,
    INDEX idx_element (IBLOCK_ELEMENT_ID),
    INDEX idx_property (IBLOCK_PROPERTY_ID)
) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

