<?php
require 'includes/db.php';
try {
    $pdo->exec("CREATE TABLE IF NOT EXISTS units (
        id INT AUTO_INCREMENT PRIMARY KEY,
        name VARCHAR(50) NOT NULL UNIQUE,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    )");
    
    $units = ['Meters', 'Yards', 'Rolls', 'Pieces', 'Kilograms', 'Grams', 'Liters', 'Cones', 'Sets'];
    $stmt = $pdo->prepare("INSERT IGNORE INTO units (name) VALUES (?)");
    foreach ($units as $u) {
        $stmt->execute([$u]);
    }
    echo "Units table created and populated successfully.";
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}
