-- ============================================================
-- vibration_drive – Migration 002: Links table
-- ============================================================

SET NAMES utf8mb4;

CREATE TABLE IF NOT EXISTS `vibration_link` (
    `id`            INT UNSIGNED    NOT NULL AUTO_INCREMENT,
    `workspace_id`  INT UNSIGNED    NOT NULL,
    `folder_id`     INT UNSIGNED    NULL DEFAULT NULL,
    `url`           TEXT            NOT NULL,
    `title`         VARCHAR(500)    NULL,
    `description`   TEXT            NULL,
    `thumbnail_url` TEXT            NULL,
    `site_name`     VARCHAR(200)    NULL,
    `og_type`       VARCHAR(50)     NULL COMMENT 'video, article, website, music…',
    `submitted_ip`  VARCHAR(45)     NULL,
    `is_approved`   TINYINT(1)      NOT NULL DEFAULT 1,
    `is_deleted`    TINYINT(1)      NOT NULL DEFAULT 0,
    `created_at`    DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP,
    `updated_at`    DATETIME        NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    PRIMARY KEY (`id`),
    INDEX `idx_link_workspace` (`workspace_id`),
    INDEX `idx_link_folder`    (`folder_id`),
    INDEX `idx_link_approved`  (`is_approved`, `is_deleted`),
    CONSTRAINT `fk_link_workspace` FOREIGN KEY (`workspace_id`) REFERENCES `vibration_workspace`(`id`) ON DELETE CASCADE,
    CONSTRAINT `fk_link_folder`    FOREIGN KEY (`folder_id`)    REFERENCES `vibration_folder`(`id`)    ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
