8 lines
2.7 KiB
JavaScript
8 lines
2.7 KiB
JavaScript
import fs from 'node:fs';import path from 'node:path';import crypto from 'node:crypto';import {spawnSync} from 'node:child_process';
|
|
const state=JSON.parse(fs.readFileSync('C:/laragon/data/sgf-tempo/run/modular-regression-current.json')),reference=path.join(state.root,'private/stock-prefix-reference-431ec7714799'),ref=JSON.parse(fs.readFileSync(path.join(reference,'reference.json')));if(state.port!==55439||!/^[a-f0-9]{12}$/.test(state.id))throw Error('Owned QA cluster required');
|
|
const tag=crypto.randomBytes(6).toString('hex'),root=path.join(state.root,'private/stock-prefix-'+tag),database='compras_receipts_test_'+tag,role='payable_history_native_'+tag,password=crypto.randomBytes(32).toString('hex');fs.mkdirSync(root);const admin=fs.readFileSync(path.join(state.root,'private/admin-password.txt'),'utf8').trim();
|
|
const pg=input=>{const r=spawnSync('C:/Program Files/PostgreSQL/17/bin/psql.exe',['-h','127.0.0.1','-p','55439','-U','sgf_regression_owner','-d','postgres','-Atq','-v','ON_ERROR_STOP=1'],{input,encoding:'utf8',windowsHide:true,env:{...process.env,PGPASSWORD:admin}});if(r.status!==0)throw Error('QA prefix provisioning failed');return r.stdout.trim();};if(pg("SELECT current_setting('cluster_name')")!=='sgf_modular_regression_'+state.id)throw Error('Wrong physical cluster');pg(`CREATE ROLE ${role} LOGIN PASSWORD '${password}' NOSUPERUSER NOCREATEDB NOCREATEROLE NOREPLICATION NOBYPASSRLS; CREATE DATABASE ${database} OWNER ${role}; REVOKE ALL ON DATABASE ${database} FROM PUBLIC;`);
|
|
const storage=path.join(root,'storage');for(const d of ['framework/cache/data','framework/views','framework/sessions','logs','cache'])fs.mkdirSync(path.join(storage,d),{recursive:true});fs.copyFileSync(path.join(reference,'StockValuationBaseline.php'),path.join(root,'StockValuationBaseline.php'));
|
|
const settings={tag,root,database,role,password,storage,run:state.id,native:path.resolve('../compras'),ledger:path.resolve('packages/general-ledger'),app_key:'base64:'+crypto.randomBytes(32).toString('base64'),reference:ref,compatibility_settings:path.join(state.root,'private/stock-ledger-b6b0e5d2fbc5/settings.json')};fs.writeFileSync(path.join(root,'settings.json'),JSON.stringify(settings,null,2));
|
|
const r=spawnSync('C:/laragon/tools/sgf-tempo/php-8.4.27/php.exe',[path.resolve('scripts/stock-ledger-entry.php'),path.join(root,'settings.json'),'prefix-review'],{encoding:'utf8',windowsHide:true,timeout:180000,maxBuffer:2*1024*1024});fs.writeFileSync(path.join(root,'prefix-output.log'),r.stdout+'\n'+r.stderr);console.log(JSON.stringify({tag,exit_code:r.status,proof_present:fs.existsSync(path.join(root,'prefix-review.json'))}));process.exitCode=r.status===0&&fs.existsSync(path.join(root,'prefix-review.json'))?0:1;
|