-- CreateTable
CREATE TABLE `private_message_files` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `private_message_id` INTEGER NOT NULL,
    `file_id` INTEGER NOT NULL,
    `upload_order` INTEGER NOT NULL DEFAULT 0,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,

    INDEX `private_message_files_private_message_id_idx`(`private_message_id`),
    INDEX `private_message_files_file_id_idx`(`file_id`),
    UNIQUE INDEX `private_message_files_private_message_id_file_id_key`(`private_message_id`, `file_id`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- CreateTable
CREATE TABLE `article_comment_files` (
    `id` INTEGER NOT NULL AUTO_INCREMENT,
    `article_comment_id` INTEGER NOT NULL,
    `file_id` INTEGER NOT NULL,
    `upload_order` INTEGER NOT NULL DEFAULT 0,
    `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
    `updated_at` DATETIME(3) NOT NULL,

    INDEX `article_comment_files_article_comment_id_idx`(`article_comment_id`),
    INDEX `article_comment_files_file_id_idx`(`file_id`),
    UNIQUE INDEX `article_comment_files_article_comment_id_file_id_key`(`article_comment_id`, `file_id`),
    PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

-- AddForeignKey
ALTER TABLE `private_message_files` ADD CONSTRAINT `private_message_files_private_message_id_fkey` FOREIGN KEY (`private_message_id`) REFERENCES `private_messages`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `private_message_files` ADD CONSTRAINT `private_message_files_file_id_fkey` FOREIGN KEY (`file_id`) REFERENCES `files`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `article_comment_files` ADD CONSTRAINT `article_comment_files_article_comment_id_fkey` FOREIGN KEY (`article_comment_id`) REFERENCES `article_comments`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE `article_comment_files` ADD CONSTRAINT `article_comment_files_file_id_fkey` FOREIGN KEY (`file_id`) REFERENCES `files`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
