<?php

try {
    $pdo = new PDO('mysql:host=127.0.0.1;dbname=kenyan_pos', 'root', '');
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Database connection successful\n";
    
    // Create cache table
    $sql = "CREATE TABLE cache (
        `key` varchar(255) NOT NULL,
        value mediumtext NOT NULL,
        expiration int NOT NULL,
        PRIMARY KEY (`key`)
    )";
    
    $pdo->exec($sql);
    echo "Cache table created successfully\n";
    
    // Create personal_access_tokens table for Sanctum
    $sql = "CREATE TABLE personal_access_tokens (
        id bigint unsigned NOT NULL AUTO_INCREMENT,
        tokenable_type varchar(255) NOT NULL,
        tokenable_id bigint unsigned NOT NULL,
        name varchar(255) NOT NULL,
        token varchar(64) NOT NULL UNIQUE,
        abilities text,
        last_used_at timestamp NULL DEFAULT NULL,
        expires_at timestamp NULL DEFAULT NULL,
        created_at timestamp NULL DEFAULT NULL,
        updated_at timestamp NULL DEFAULT NULL,
        PRIMARY KEY (id),
        KEY personal_access_tokens_tokenable_type_tokenable_id_index (tokenable_type,tokenable_id)
    )";
    
    $pdo->exec($sql);
    echo "Personal access tokens table created successfully\n";
    
} catch(Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
}