<?php
declare(strict_types=1);
require __DIR__ . '/../../config/bootstrap.php';
use App\Core\Database;

$db=Database::getInstance();

$has=function(string $c) use($db){
  $st=$db->prepare("SELECT COUNT(*) FROM information_schema.columns WHERE table_schema=DATABASE() AND table_name='organizations' AND column_name=:c");
  $st->execute([':c'=>$c]);
  return (int)$st->fetchColumn()>0;
};

if(!$has('is_active')){
  $db->exec("ALTER TABLE organizations ADD COLUMN is_active TINYINT(1) NOT NULL DEFAULT 1");
  $db->exec("ALTER TABLE organizations ADD KEY idx_org_active (is_active)");
  echo "Added organizations.is_active\n";
} else {
  echo "organizations.is_active exists\n";
}

$db->exec("UPDATE organizations SET is_active=1 WHERE is_active IS NULL");
echo "Pack205.7 done\n";
