<?php
require __DIR__ . '/../bootstrap.php';

use Gestoreasy\Core\Tenant\ConnectionManager;

$tenant = $argv[1] ?? 'default';
$module = $argv[2] ?? null;
$pdo = ConnectionManager::forTenant($tenant);
if ($module) {
    $stmt = $pdo->prepare('SELECT module, filename, applied_at FROM schema_migrations WHERE module = ? ORDER BY filename');
    $stmt->execute([$module]);
} else {
    $stmt = $pdo->query('SELECT module, filename, applied_at FROM schema_migrations ORDER BY module, filename');
}
$rows = $stmt->fetchAll();
echo json_encode($rows, JSON_UNESCAPED_UNICODE) . "\n";