getLine().PHP_EOL);exit(1);}); $root=dirname(__DIR__,2);require $root.'/vendor/autoload.php';$app=require $root.'/bootstrap/app.php';(new Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables)->bootstrap($app);(new Illuminate\Foundation\Bootstrap\LoadConfiguration)->bootstrap($app); $c=config('database.connections.'.config('database.default'));if($c['database']!=='investemoz'||(int)$c['port']!==5432||!in_array($c['host'],['127.0.0.1','localhost'])||!empty($c['url']))throw new RuntimeException('Active read guard'); $b=json_decode(file_get_contents(__DIR__.'/FRESH-BACKUP.json'),true);$name=$b['restore_target']['database'];if(!preg_match('/^economic_refs_before_\d{8}_\d{6}_test$/D',$name))throw new RuntimeException('Clone read guard'); $a=new PDO('pgsql:host='.$c['host'].';port=5432;dbname=investemoz',$c['username'],$c['password'],[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);$q=new PDO('pgsql:host=127.0.0.1;port=55441;dbname='.$name,'postgres','',[PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION]);foreach([$a,$q]as$db)$db->exec('BEGIN READ ONLY'); try{ $sql="SELECT schemaname,sequencename,data_type,start_value,min_value,max_value,increment_by,cycle,cache_size,last_value FROM pg_sequences WHERE schemaname NOT LIKE 'pg_%' AND schemaname <> 'information_schema' ORDER BY schemaname,sequencename"; $before=$q->query($sql)->fetchAll(PDO::FETCH_ASSOC);$after=$a->query($sql)->fetchAll(PDO::FETCH_ASSOC);if(count($before)!==count($after))throw new RuntimeException('Sequence count changed');$changes=[]; foreach($before as$i=>$row)if($row!==$after[$i]){if($row['schemaname']!=='public'||$row['sequencename']!=='migrations_id_seq')throw new RuntimeException('Unrelated sequence changed');$expected=$row;$expected['last_value']=(int)$row['last_value']+1;if($expected!=$after[$i])throw new RuntimeException('Migration sequence unexpected');$changes[]=['sequence'=>'public.migrations_id_seq','increment'=>1];} $sql="SELECT schemaname,tablename FROM pg_tables WHERE schemaname NOT LIKE 'pg_%' AND schemaname <> 'information_schema' ORDER BY schemaname,tablename";if($a->query($sql)->fetchAll(PDO::FETCH_ASSOC)!==$q->query($sql)->fetchAll(PDO::FETCH_ASSOC))throw new RuntimeException('Unrelated tables added/removed'); $r=['at'=>gmdate('c'),'read_only'=>true,'sequences_compared'=>count($before),'authorized_sequence_changes'=>$changes,'table_set_unchanged'=>true];file_put_contents(__DIR__.'/SEQUENCIAS-FINAL.json',json_encode($r,JSON_PRETTY_PRINT|JSON_THROW_ON_ERROR).PHP_EOL);echo json_encode($r).PHP_EOL; }finally{foreach([$a,$q]as$db)$db->exec('ROLLBACK');}