Files
Investidor-V2/outputs/investmoz-parques-L1-QA-20261016/prepare.py
T
nala cef6e201c7
tests / ci (push) Canceled after 0s
versao nrgocios 2
2026-10-16 20:11:05 +02:00

29 lines
3.2 KiB
Python

from pathlib import Path
import datetime,hashlib,json,shutil,subprocess
root=Path(__file__).resolve().parents[2];out=Path(__file__).resolve().parent
private=Path('C:/Users/macbook/.config/investmoz/parques-L1-QA-20261016');qa=private/'source'
sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest()
assert not private.exists();private.mkdir(parents=True);qa.mkdir()
baseline={p.relative_to(root).as_posix():sha(p)for f in ['app','config','routes','database','resources','public/build']for p in(root/f).rglob('*')if p.is_file()}
(out/'ATIVO-ANTES.json').write_text(json.dumps({'files':baseline,'protected':{n:sha(root/n)for n in ['.env','composer.lock','package-lock.json']}},indent=2),'utf-8')
for folder in ['app','config','routes','database','resources','bootstrap','public/build']:shutil.copytree(root/folder,qa/folder)
for n in ['artisan','composer.json','composer.lock','package.json','package-lock.json','tsconfig.json','vite.config.ts']:shutil.copy2(root/n,qa/n)
for f in ['storage/framework/cache/data','storage/framework/views','storage/framework/sessions','storage/logs','storage/app/private','storage/app/public']:(qa/f).mkdir(parents=True,exist_ok=True)
for n in ['vendor','node_modules']:subprocess.run(['cmd.exe','/d','/c','mklink','/J',str(qa/n),str(root/n)],check=True,capture_output=True)
assert not(qa/'bootstrap/cache/config.php').exists()
pg=Path('C:/Program Files/PostgreSQL/17/bin');args=['-h','127.0.0.1','-p','55441','-U','postgres'];db='parks_l1_20261016_test'
assert subprocess.run([str(pg/'psql.exe'),*args,'-d','postgres','-Atc','SELECT inet_server_port()'],capture_output=True,text=True,check=True).stdout.strip()=='55441'
dump=private/'base-QA.dump';subprocess.run([str(pg/'pg_dump.exe'),*args,'-d','parks_operational_20261016_test','-Fc','-f',str(dump)],check=True,capture_output=True)
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)
old=Path('C:/Users/macbook/.config/investmoz/parques-QA-20261016');env=(old/'source/.env').read_text('utf-8').replace('parks_operational_20261016_test',db).replace('18532','18533').replace('parks_operational_qa','parks_l1_qa')
(qa/'.env').write_text(env,'utf-8')
boot=(root/'outputs/investmoz-parques-QA-20261016/boot-QA.php').read_text('utf-8').replace('parques-QA-20261016','parques-L1-QA-20261016').replace('parks_operational_20261016_test',db)
(out/'boot-QA.php').write_text(boot,'utf-8')
# Preserve existing QA support bytes and credentials only in the private QA area.
shutil.copytree(old/'source/storage/app/private',qa/'storage/app/private',dirs_exist_ok=True)
if(old/'fixture-private.json').exists():
f=json.loads((old/'fixture-private.json').read_text('utf-8'));f.update(database=db,url='http://127.0.0.1:18533');(private/'fixture-private.json').write_text(json.dumps(f),'utf-8')
(out/'QA-ISOLAMENTO.json').write_text(json.dumps({'source':str(qa),'database':db,'port':55441,'url':'http://127.0.0.1:18533','reference':'prior isolated QA; no active data copied','dump_sha256':sha(dump),'at':datetime.datetime.now(datetime.timezone.utc).isoformat(),'active_authorized':False},indent=2),'utf-8')
print('QA copy prepared on isolated port 55441; active source unchanged')