فینورا پرو - سامانه جامع حسابداری و صدور فاکتور

fix(a02): remove stale duplicate tail after rebuilding manifest parser

davoodmehraban89 committed Oct 30, 2026 at 20:35 UTC de4b9b7d0f23fb5e59ab767f0be1ebc552cfed98
1 file changed -96
scripts/a02-isolated-schema-inventory.ps1
-96
@@ -386,102 +386,6 @@ if($Mode -eq 'DecryptManifest'){
386 return
387 }
388
389 -$conn=$null
390 -try{
391 - Assert-Target $InstanceName $DatabaseName
392 - $source=if($InstanceName -ceq 'FINORAMIG'){'lpc:.\FINORAMIG'}else{'(localdb)\'+$InstanceName}
393 - $connectionString='Data Source='+$source+';Initial Catalog=master;Integrated Security=True;Connect Timeout=15;Encrypt=False;Pooling=False;'
394 - $conn=[Data.SqlClient.SqlConnection]::new($connectionString);$conn.Open()
395 - $check=$conn.CreateCommand()
396 - $check.CommandText='SELECT state_desc FROM sys.databases WHERE name=@db;'
397 - [void]$check.Parameters.Add('@db',[Data.SqlDbType]::NVarChar,128)
398 - $check.Parameters['@db'].Value=$DatabaseName
399 - $status=$check.ExecuteScalar();$check.Dispose()
400 - if($null -eq $status -or [string]$status -cne 'ONLINE'){throw 'A02_RESTORE_NOT_ONLINE'}
401 - $conn.ChangeDatabase($DatabaseName)
402 - $manifest=Get-SchemaData $conn
403 - if($Mode -eq 'Inspect'){
404 - [pscustomobject]@{
405 - status='isolated-schema-inventoried'
406 - fingerprintSha256=$manifest.schemaFingerprintSha256
407 - tableCount=$manifest.tableCount;columnCount=$manifest.columnCount
408 - primaryKeyCount=$manifest.primaryKeyCount;foreignKeyCount=$manifest.foreignKeyCount
409 - userRowsRead=$false;databaseModified=$false;canImport=$false
410 - }|ConvertTo-Json -Compress
411 - }else{
412 - if([string]::IsNullOrWhiteSpace($OutputPath)){throw 'A02_PRIVATE_OUTPUT_PATH_REQUIRED'}
413 - $json=ConvertTo-Json -InputObject $manifest -Depth 20
414 - $plain=[Text.Encoding]::UTF8.GetBytes($json)
415 - if($plain.Length -gt 33554432){throw 'A02_PRIVATE_MANIFEST_TOO_LARGE'}
416 - Add-Type -AssemblyName System.Security -ErrorAction Stop
417 - $cipher=[Security.Cryptography.ProtectedData]::Protect(
418 - $plain,$script:ManifestEntropy,[Security.Cryptography.DataProtectionScope]::CurrentUser)
419 - $header=[Text.Encoding]::ASCII.GetBytes($script:ManifestHeader)
420 - $payload=New-Object byte[] ($header.Length+1+$cipher.Length)
421 - [Buffer]::BlockCopy($header,0,$payload,0,$header.Length)
422 - $payload[$header.Length]=10
423 - [Buffer]::BlockCopy($cipher,0,$payload,$header.Length+1,$cipher.Length)
424 - Write-RestrictedFile $OutputPath $payload
425 - [pscustomobject]@{
426 - status='private-schema-manifest-encrypted'
427 - tableCount=$manifest.tableCount;columnCount=$manifest.columnCount
428 - primaryKeyCount=$manifest.primaryKeyCount;foreignKeyCount=$manifest.foreignKeyCount
429 - dpapiScope='CurrentUser';fileAclRestricted=$true
430 - userRowsRead=$false;databaseModified=$false;canImport=$false
431 - }|ConvertTo-Json -Compress
432 - }
433 -}catch{
434 - Write-Error 'A02_SCHEMA_INVENTORY_OR_PRIVATE_EXPORT_FAILED'
435 - exit 2
436 -}finally{if($null -ne $conn){$conn.Dispose()}}
437 - -or
438 - [int]$manifest.tableCount -lt 1 -or
439 - [int]$manifest.columnCount -lt 1 -or
440 - $manifest.userRowsRead -ne $false -or
441 - $manifest.databaseModified -ne $false -or
442 - $manifest.canImport -ne $false){
443 - throw 'A02_PRIVATE_MANIFEST_CONTRACT_INVALID'
444 - }
445 - return ,$plain
446 -}
447 -
448 -if($Mode -eq 'Test'){
449 - Assert-Target 'FINORAMIG' 'FinoraHoloo_0123456789abcdef0123456789abcdef'
450 - Assert-Target 'FinoraA02_0123456789ab' 'A02Restore_0123456789ab'
451 - foreach($pair in @(@('FINORAMIG','master'),@('FINORAMIG','Holoo1'),
452 - @('master','FinoraHoloo_0123456789abcdef0123456789abcdef'),
453 - @('FinoraA02_0123456789ab','A02Restore_aaaaaaaaaaaa'))){
454 - $blocked=$false
455 - try{Assert-Target $pair[0] $pair[1]}catch{$blocked=$true}
456 - if(-not $blocked){throw 'A02_UNSAFE_TARGET_ACCEPTED'}
457 - }
458 - $rows=@(
459 - [pscustomobject]@{SchemaName='dbo';TableName='Synthetic';ColumnName='id';DataType='int';Ordinal=1;MaxLength=4;Precision=10;Scale=0;IsNullable=0;IsIdentity=0;IsComputed=0},
460 - [pscustomobject]@{SchemaName='dbo';TableName='Synthetic';ColumnName='amount';DataType='bigint';Ordinal=2;MaxLength=8;Precision=19;Scale=0;IsNullable=0;IsIdentity=0;IsComputed=0}
461 - )
462 - $h=Fingerprint $rows;[array]::Reverse($rows)
463 - if((Fingerprint $rows) -cne $h){throw 'A02_FINGERPRINT_NOT_ORDER_INDEPENDENT'}
464 - $rows[0].ColumnName='changed'
465 - if((Fingerprint $rows) -ceq $h){throw 'A02_FINGERPRINT_NOT_CHANGE_SENSITIVE'}
466 - [pscustomobject]@{
467 - status='schema-fingerprint-selftest-passed';sqlOpened=$false
468 - userRowsRead=$false;databaseModified=$false;canImport=$false
469 - }|ConvertTo-Json -Compress
470 - return
471 -}
472 -
473 -if($Mode -eq 'DecryptManifest'){
474 - try{
475 - if([string]::IsNullOrWhiteSpace($InputPath) -or [string]::IsNullOrWhiteSpace($OutputPath)){
476 - throw 'A02_PRIVATE_MANIFEST_PATHS_REQUIRED'
477 - }
478 - $plain=Read-EncryptedManifest $InputPath
479 - Write-RestrictedFile $OutputPath $plain
480 - [pscustomobject]@{status='private-schema-manifest-decrypted';plaintextFileAclRestricted=$true;userRowsRead=$false;databaseModified=$false;canImport=$false}|ConvertTo-Json -Compress
481 - }catch{Write-Error 'A02_PRIVATE_MANIFEST_DECRYPT_FAILED';exit 2}
482 - return
483 -}
484 -
389 $conn=$null
390 try{
391 Assert-Target $InstanceName $DatabaseName