Files
Investidor-V2/tools/local-qa-bootstrap.php
T
paulomassigue 14ad2f60c5
tests / ci (push) Canceled after 0s
header:navbar e footer
2026-10-19 13:07:16 +02:00

49 lines
1.9 KiB
PHP

<?php
// Technical setup for the explicitly authorised, disposable local demo only.
// The production database and authenticated installation workflow remain separate.
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
require dirname(__DIR__).'/vendor/autoload.php';
foreach (['APP_ENV' => 'testing', 'APP_CONFIG_CACHE' => dirname(__DIR__).'/storage/framework/cache/local-qa-config.php'] as $key => $value) {
putenv($key.'='.$value);
$_ENV[$key] = $_SERVER[$key] = $value;
}
$app = require dirname(__DIR__).'/bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
$connection = config('database.connections.pgsql');
if (app()->configurationIsCached() || config('database.default') !== 'pgsql'
|| $connection['host'] !== '127.0.0.1' || (string) $connection['port'] !== '55441'
|| $connection['database'] !== 'investmoz_local_test' || ! empty($connection['url'])) {
fwrite(STDERR, 'Refused: explicit isolated local QA database required.'.PHP_EOL);
exit(1);
}
$identity = DB::selectOne('SELECT current_database() AS database, inet_server_port() AS port');
if ($identity->database !== 'investmoz_local_test' || (int) $identity->port !== 55441) {
fwrite(STDERR, 'Refused: actual QA server identity differs.'.PHP_EOL);
exit(1);
}
try {
$status = Artisan::call('migrate', ['--force' => true]);
} catch (Throwable $error) {
fwrite(STDERR, 'Local QA migration failed: '.$error->getMessage().PHP_EOL);
exit(1);
}
echo Artisan::output();
if ($status !== 0) {
exit($status);
}
// Never reset an account or overwrite an existing demo on a repeated setup.
if (DB::table('sectors')->count() === 0 && DB::table('users')->count() === 0) {
$status = Artisan::call('db:seed', ['--force' => true]);
echo Artisan::output();
exit($status);
}
echo 'Existing local demo preserved; seed skipped.'.PHP_EOL;