27 lines
3.4 KiB
Python
27 lines
3.4 KiB
Python
from pathlib import Path
|
|
import json, hashlib, shutil, subprocess, datetime
|
|
root=Path.cwd();out=Path(__file__).resolve().parent
|
|
private=Path('C:/Users/macbook/.config/investmoz/documentos-publicos-QA-20261018');qa=private/'source'
|
|
assert not private.exists();qa.mkdir(parents=True)
|
|
sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
|
|
baseline={'files':{p.relative_to(root).as_posix():sha(p) for folder in ['app','config','routes','database','resources','public/build'] for p in (root/folder).rglob('*') if p.is_file()},'protected':{n:sha(root/n) for n in ['.env','composer.lock','package-lock.json']}}
|
|
(out/'ATIVO-ANTES.json').write_text(json.dumps(baseline,indent=2),'utf-8')
|
|
for folder in ['app','config','routes','database','resources','bootstrap','public/build']:shutil.copytree(root/folder,qa/folder)
|
|
for n in ['composer.json','composer.lock','package.json','package-lock.json','tsconfig.json','vite.config.ts']:shutil.copy2(root/n,qa/n)
|
|
for folder in ['storage/framework/cache/data','storage/framework/views','storage/framework/sessions','storage/logs','storage/app/private','storage/app/public']:(qa/folder).mkdir(parents=True,exist_ok=True)
|
|
for n in ['vendor','node_modules']:subprocess.run(['powershell','-NoProfile','-Command',f"New-Item -ItemType Junction -Path '{qa/n}' -Target '{root/n}' | Out-Null"],check=True,capture_output=True)
|
|
pg=Path('C:/Program Files/PostgreSQL/17/bin');args=['-h','127.0.0.1','-p','55441','-U','postgres'];db='public_documents_20261018_test'
|
|
assert subprocess.run([str(pg/'psql.exe'),*args,'-d','postgres','-Atc','SELECT inet_server_port()'],check=True,capture_output=True,text=True).stdout.strip()=='55441'
|
|
backup=json.loads((root/'outputs/investmoz-sectores-duplicacoes-ativacao-20261018/FRESH-BACKUP.json').read_text('utf-8'));dump=Path(backup['private_directory'])/'destination.dump';assert sha(dump)==backup['dump_sha256']
|
|
subprocess.run([str(pg/'createdb.exe'),*args,db],check=True,capture_output=True)
|
|
subprocess.run([str(pg/'pg_restore.exe'),*args,'-d',db,'--exit-on-error','--no-owner','--no-privileges',str(dump)],check=True,capture_output=True)
|
|
previous=Path('C:/Users/macbook/.config/investmoz/sectores-duplicacoes-QA-20261018/step4/source')
|
|
env=(previous/'.env').read_text('utf-8').replace('sectors_step4_20261018_test',db).replace('18544','18546');(qa/'.env').write_text(env,'utf-8')
|
|
for folder in ['storage/app/private','storage/app/public']:
|
|
shutil.copytree(root/folder,qa/folder,dirs_exist_ok=True)
|
|
old=root/'outputs/investmoz-sectores-duplicacoes-QA-20261018/boot-QA.php';boot=old.read_text('utf-8').replace('sectores-duplicacoes-QA-20261018/source','documentos-publicos-QA-20261018/source').replace('sectors_dedup_current_20261018_test',db)
|
|
(out/'boot-QA.php').write_text(boot,'utf-8');(out/'router-QA.php').write_bytes((old.parent/'router-QA.php').read_bytes())
|
|
(qa/'artisan').write_text("<?php require '"+(out/'boot-QA.php').as_posix()+"';exit($app->handleCommand(new Symfony\\Component\\Console\\Input\\ArgvInput));",'utf-8')
|
|
(out/'QA-ISOLAMENTO.json').write_text(json.dumps({'at':datetime.datetime.now(datetime.timezone.utc).isoformat(),'source':str(qa),'database':db,'port':55441,'url':'http://127.0.0.1:18546','base':'validated destination backup before sector association; document tables preserved by sector rollout','dump_sha256':sha(dump),'active_connections':0,'active_changes':0},indent=2),'utf-8')
|
|
print('Isolated document presentation QA prepared; active untouched')
|