SET NAMES utf8mb4;

CREATE TABLE IF NOT EXISTS user_personalization_repiquages (
    id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    user_id BIGINT UNSIGNED NOT NULL,
    field_code VARCHAR(80) NOT NULL,
    field_type VARCHAR(24) NOT NULL DEFAULT 'text',
    text_value TEXT NULL,
    asset_url VARCHAR(512) NULL,
    created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    UNIQUE KEY uq_user_personalization_repiquages_user_field (user_id, field_code),
    INDEX idx_user_personalization_repiquages_user_id (user_id),
    INDEX idx_user_personalization_repiquages_field_code (field_code),
    CONSTRAINT fk_user_personalization_repiquages_user
        FOREIGN KEY (user_id) REFERENCES users(id)
        ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
