$migration->up())->toThrow(LogicException::class) ->and(Schema::hasColumn('requisitions', 'budget_distribution_preparation'))->toBeFalse(); }); test('local preparation uses the same schema definition and preserves previous records under its exact scope', function () { if (DB::getDriverName() !== 'pgsql') { $this->markTestSkipped('Exact native identity is checked on isolated PostgreSQL.'); } receiptFixture(); $columns = Schema::getColumnListing('requisitions'); $before = DB::table('requisitions')->select($columns)->get()->toJson(); config(['budget-distributions.schema_installation' => ['database' => DB::connection()->getDatabaseName(), 'username' => DB::connection()->getConfig('username')]]); $migration = require database_path('deployment-migrations/2026_11_22_000004_create_budget_distributions.php'); app()->instance('env', 'local'); try { $migration->up(); } finally { app()->instance('env', 'testing'); } expect(DB::table('requisitions')->select($columns)->get()->toJson())->toBe($before) ->and(DB::table('budget_distributions')->count())->toBe(0) ->and(DB::table('requisitions')->whereNotNull('budget_distribution_preparation')->count())->toBe(0) ->and(fn () => $migration->down())->toThrow(LogicException::class); }); test('staged pilot schema refuses an incorrect target and operational production environment', function () { receiptFixture(); config(['budget-distributions.schema_installation' => ['database' => 'different_database', 'username' => DB::connection()->getConfig('username')]]); $migration = require database_path('deployment-migrations/2026_11_22_000004_create_budget_distributions.php'); expect(fn () => $migration->up())->toThrow(LogicException::class); app()->instance('env', 'production'); try { expect(fn () => $migration->up())->toThrow(LogicException::class) ->and(Schema::hasColumn('requisitions', 'budget_distribution_preparation'))->toBeFalse(); } finally { app()->instance('env', 'testing'); } });