make(Kernel::class)->bootstrap(); DB::beginTransaction(); try { DB::statement('SET TRANSACTION READ ONLY'); $records = app(InvestmentGeography::class)->publicReferences()->whereIn('location_type', ['country', 'province', 'district']) ->orderByRaw("CASE location_type WHEN 'country' THEN 0 WHEN 'province' THEN 1 ELSE 2 END") ->get(['id', 'parent_id', 'name', 'location_type', 'code', 'source_code', 'source_system', 'external_id', 'data_classification', 'version_no']); $path = storage_path('app/private/demography-registry-snapshot.json'); file_put_contents($path, json_encode(['read_only' => true, 'captured_at' => gmdate(DATE_ATOM), 'records' => $records], JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); echo json_encode(['read_only' => true, 'counts' => $records->countBy('location_type')->all(), 'snapshot_sha256' => hash_file('sha256', $path)], JSON_THROW_ON_ERROR).PHP_EOL; } finally { DB::rollBack(); }