<?php
require_once 'includes/db.php';

// Create the product_comments table
try {
    $sql = "
    CREATE TABLE IF NOT EXISTS `product_comments` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `product_id` int(11) NOT NULL,
      `user_id` int(11) NOT NULL,
      `comment` text NOT NULL,
      `created_at` datetime DEFAULT current_timestamp(),
      PRIMARY KEY (`id`),
      KEY `product_id` (`product_id`),
      KEY `user_id` (`user_id`),
      CONSTRAINT `product_comments_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE CASCADE,
      CONSTRAINT `product_comments_ibfk_2` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
    ";
    
    $pdo->exec($sql);
    echo "Table 'product_comments' created successfully!";
} catch (Exception $e) {
    echo "Error creating table: " . $e->getMessage();
}
?>