Files
Investidor-V2/outputs/investmoz-parques-integral-QA-20261018/prepare.py
T
nala cf003c8623
tests / ci (push) Canceled after 0s
versao nrgocios 4
2026-10-18 15:57:06 +02:00

19 lines
4.1 KiB
Python

from pathlib import Path
import json,hashlib,shutil,subprocess,datetime
out=Path(__file__).resolve().parent;root=out.parents[1];private=Path('C:/Users/macbook/.config/investmoz/parques-integral-QA-20261018');qa=private/'source';old=Path('C:/Users/macbook/.config/investmoz/parques-L1-QA-20261016');sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest();assert not private.exists();qa.mkdir(parents=True)
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 d in ['storage/framework/cache/data','storage/framework/views','storage/framework/sessions','storage/logs','storage/app/private','storage/app/public']:(qa/d).mkdir(parents=True,exist_ok=True)
for n in ['vendor','node_modules']:subprocess.run(['powershell','-NoProfile','-Command',"New-Item -ItemType Junction -Path '"+str(qa/n)+"' -Target '"+str(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='parks_integral_20261018_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_l1_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)
# Accepted navigation schema is copied from existing isolated QA, not installed or tested again.
nav=private/'navigation-base.sql';subprocess.run([str(pg/'pg_dump.exe'),*args,'-d','navigation_consolidation_20261016_test','--schema-only','--no-owner','--no-privileges','-t','investor_navigation_preferences','-f',str(nav)],check=True,capture_output=True);subprocess.run([str(pg/'psql.exe'),*args,'-d',db,'-v','ON_ERROR_STOP=1','-f',str(nav)],check=True,capture_output=True)
subprocess.run([str(pg/'psql.exe'),*args,'-d',db,'-v','ON_ERROR_STOP=1','-c',"INSERT INTO migrations(migration,batch) SELECT '2026_10_16_150000_create_investor_navigation_preferences',max(batch) FROM migrations"],check=True,capture_output=True)
env=(old/'source/.env').read_text('utf-8').replace('parks_l1_20261016_test',db).replace('18533','18540');(qa/'.env').write_text(env,'utf-8');shutil.copytree(old/'source/storage/app/private',qa/'storage/app/private',dirs_exist_ok=True)
f=json.loads((old/'fixture-private.json').read_text('utf-8'));f.update(database=db,url='http://127.0.0.1:18540');(private/'fixture-private.json').write_text(json.dumps(f),'utf-8')
previous=root/'outputs/investmoz-parques-L1-QA-20261016';boot=(previous/'boot-QA.php').read_text('utf-8').replace('parques-L1-QA-20261016','parques-integral-QA-20261018').replace('parks_l1_20261016_test',db);(out/'boot-QA.php').write_text(boot,'utf-8');(out/'router-QA.php').write_bytes((previous/'router-QA.php').read_bytes());(qa/'artisan').write_text("#!/usr/bin/env php\n<?php\ndefine('LARAVEL_START',microtime(true));require '"+(out/'boot-QA.php').as_posix()+"';exit($app->handleCommand(new Symfony\\Component\\Console\\Input\\ArgvInput));\n",'utf-8')
(out/'QA-ISOLAMENTO.json').write_text(json.dumps({'source':str(qa),'database':db,'port':55441,'url':f['url'],'base':'previous isolated L1 QA, navigation schema copied from isolated navigation QA','active_connections':0,'active_changes':0,'new_migration':False,'at':datetime.datetime.now(datetime.timezone.utc).isoformat(),'dump_sha256':sha(dump)},indent=2),'utf-8');print('Isolated QA prepared; L1 and navigation base reused; no active connection or change')