Files
absdev-deployment/evidence/trusted-rehearsal-attestation/rehearsal.php
T

30 lines
1.3 KiB
PHP

<?php
require '/deps/vendor/autoload.php';
use Illuminate\Database\Capsule\Manager;
use Illuminate\Database\Migrations\DatabaseMigrationRepository;
use Illuminate\Database\Migrations\Migrator;
use Illuminate\Filesystem\Filesystem;
$config = json_decode(file_get_contents('/credential.json'), true, flags: JSON_THROW_ON_ERROR);
$capsule = new Manager();
$capsule->addConnection($config);
$capsule->setAsGlobal();
$resolver = $capsule->getDatabaseManager();
$repository = new DatabaseMigrationRepository($resolver, 'migrations');
$repository->createRepository();
$migrator = new Migrator($repository, $resolver, new Filesystem());
$paths = array_map(fn ($dir) => '/release/'.$dir, array_slice($argv, 1));
$files = $migrator->getMigrationFiles($paths);
$migrator->run($paths);
$db = $capsule->getConnection();
$checks = $db->table('rehearsal_items')->orderBy('id')->pluck('label')->all();
$files = array_map(fn ($file) => substr($file, strlen('/release/')), $files);
echo json_encode([
'laravel_version' => Composer\InstalledVersions::getPrettyVersion('laravel/framework'),
'database' => $db->selectOne('SELECT current_database() AS name')->name,
'inventory' => $files,
'history' => $repository->getRan(),
'restored_and_migrated_rows' => $checks,
], JSON_THROW_ON_ERROR);