<?php
declare(strict_types=1);

/**
 * Adds an optional file on tasks (PDF, Word, JPEG, PNG).
 * Fresh installs already include this in schema.sql.
 * Run: C:\xampp\php\php.exe sql/migrate_task_file.php
 */
$base = dirname(__DIR__);
require $base . '/app/init.php';

$db = App\Core\Database::instance();
$pdo = $db->pdo();

$has = (int) $pdo->query(
    "SELECT COUNT(*) FROM information_schema.COLUMNS
     WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'tasks' AND COLUMN_NAME = 'file_name'"
)->fetchColumn();

if ($has < 1) {
    $pdo->exec('ALTER TABLE tasks ADD COLUMN file_name VARCHAR(180) NULL AFTER created_by');
    echo "Added tasks.file_name\n";
} else {
    echo "tasks.file_name already present\n";
}

echo "Task file migrate finished.\n";
