<?php
require_once __DIR__ . '/../../db/config.php';

$pdo = db();

$columns = [
    'nip' => 'VARCHAR(255) DEFAULT NULL',
    'industry' => 'VARCHAR(255) DEFAULT NULL',
    'company_size_revenue' => 'VARCHAR(255) DEFAULT NULL',
    'business_description' => 'TEXT DEFAULT NULL',
    'company_logo_path' => 'VARCHAR(255) DEFAULT NULL',
    'person_photo_path' => 'VARCHAR(255) DEFAULT NULL',
    'gains_sheet_path' => 'VARCHAR(255) DEFAULT NULL',
    'top_wanted_contacts_path' => 'VARCHAR(255) DEFAULT NULL',
    'top_owned_contacts_path' => 'VARCHAR(255) DEFAULT NULL'
];

$sql_check_columns = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'people'";
$stmt_check = $pdo->query($sql_check_columns);
$existing_columns = $stmt_check->fetchAll(PDO::FETCH_COLUMN);

$sql_alter_parts = [];
foreach ($columns as $column_name => $column_definition) {
    if (!in_array($column_name, $existing_columns)) {
        $sql_alter_parts[] = "ADD COLUMN `$column_name` $column_definition";
    }
}

if (!empty($sql_alter_parts)) {
    $sql = "ALTER TABLE people " . implode(', ', $sql_alter_parts);
    try {
        $pdo->exec($sql);
        echo "Migration 019 completed successfully: Added new fields to people table.\n";
    } catch (PDOException $e) {
        die("Migration 019 failed: " . $e->getMessage() . "\n");
    }
} else {
    echo "Migration 019 skipped: All columns already exist.\n";
}

