<?php
declare(strict_types=1);
if(($_GET['upgrade']??'')!=='1'){http_response_code(403);exit('Invalid upgrade request.');}
$config=require __DIR__.'/config.php';
$d=$config['db'];
$pdo=new PDO("mysql:host={$d['host']};port=".($d['port']??3306).";dbname={$d['name']};charset=".($d['charset']??'utf8mb4'),$d['user'],$d['pass'],[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);
$sql=file_get_contents(__DIR__.'/database/migrations/002_client_workspace_content.sql');
$statements=array_filter(array_map('trim',preg_split('/;\s*(?:\r?\n|$)/',$sql)));
header('Content-Type: text/plain; charset=utf-8');
try{foreach($statements as $statement)$pdo->exec($statement);echo "Upgrade complete. Delete upgrade.php now.\n";}catch(Throwable $e){http_response_code(500);echo "Upgrade stopped: ".$e->getMessage()."\n";}
