make(Kernel::class)->bootstrap(); $db = DB::connection(); $report = $db->transaction(function () use ($db) { $db->statement('SET TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ ONLY'); return [ 'options_query_plan' => $db->select("EXPLAIN (FORMAT JSON) SELECT id,name FROM geo_locations WHERE deleted_at IS NULL AND parent_id=? AND location_type='district' ORDER BY name LIMIT 100", [$db->table('geo_locations')->where('location_type', 'province')->whereNull('deleted_at')->value('id')]), 'counts' => $db->select('SELECT location_type,count(*) FROM geo_locations WHERE deleted_at IS NULL GROUP BY location_type ORDER BY location_type'), 'duplicate_names' => $db->select('SELECT parent_id,location_type,lower(trim(name)) as name,count(*) FROM geo_locations WHERE deleted_at IS NULL GROUP BY parent_id,location_type,lower(trim(name)) HAVING count(*)>1'), 'invalid_parents' => $db->select("SELECT g.id,g.location_type FROM geo_locations g LEFT JOIN geo_locations p ON p.id=g.parent_id WHERE g.deleted_at IS NULL AND (g.location_type='country' AND g.parent_id IS NOT NULL OR g.location_type IN ('province','district','admin_post','locality') AND (p.id IS NULL OR p.deleted_at IS NOT NULL OR p.location_type <> CASE g.location_type WHEN 'province' THEN 'country' WHEN 'district' THEN 'province' WHEN 'admin_post' THEN 'district' WHEN 'locality' THEN 'admin_post' END))"), 'sectors' => $db->table('sectors')->whereNull('deleted_at')->orderBy('id')->get(['id', 'name', 'slug']), 'php' => PHP_VERSION, 'laravel' => app()->version(), 'postgres' => $db->selectOne('SHOW server_version')->server_version, 'postgis' => $db->selectOne('SELECT postgis_lib_version() as version')->version, ]; }); echo json_encode($report, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR).PHP_EOL;