33 lines
1.5 KiB
PHP
33 lines
1.5 KiB
PHP
<?php
|
|
|
|
use App\Services\BudgetDistributionSchema;
|
|
use Illuminate\Database\Migrations\Migration;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
// Deliberately outside automatic migrations. Only the reviewed installer supplies this scope.
|
|
return new class extends Migration
|
|
{
|
|
public function up(): void
|
|
{
|
|
$db = DB::connection();
|
|
$scope = config('budget-distributions.schema_installation');
|
|
if (! app()->runningInConsole() || ! app()->environment(['local', 'testing', 'payable-testing'])
|
|
|| $db->getDriverName() !== 'pgsql' || $db->getConfig('host') !== '127.0.0.1'
|
|
|| ! is_array($scope) || ($scope['database'] ?? null) !== $db->getDatabaseName()
|
|
|| ($scope['username'] ?? null) !== $db->getConfig('username')
|
|
|| ! preg_match('/^compras_(receipts_test|distribution_restore)_[a-f0-9]{12}$/D', $db->getDatabaseName())) {
|
|
throw new LogicException('Distribution pilot schema requires the exact authorised installer scope.');
|
|
}
|
|
$identity = $db->selectOne('select current_database() as db, current_user as role');
|
|
if ($identity === null || $identity->db !== $scope['database'] || $identity->role !== $scope['username']) {
|
|
throw new LogicException('Distribution pilot schema identity mismatch.');
|
|
}
|
|
BudgetDistributionSchema::install();
|
|
}
|
|
|
|
public function down(): void
|
|
{
|
|
throw new LogicException('Preserve distribution history; use reviewed recovery or a compatible forward correction.');
|
|
}
|
|
};
|