<?php
declare(strict_types=1);

/**
 * Adds an optional file on activity notes (PDF, Word, JPEG, PNG).
 * Run: C:\xampp\php\php.exe sql/migrate_activity_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 = 'activities' AND COLUMN_NAME = 'file_name'"
)->fetchColumn();

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

echo "Activity file migrate finished.\n";
