Files
AFC-Demo/app/Console/Commands/TransformDataPoolCommand.php
T
cbazza 1cb38d7080 chore: major project cleanup and restructuring
## Dokumentation
- Entfernt AGENTS.md (redundant zu CLAUDE.md)
- Verschoben: 3 Dokumentationen von root → docs/
- Gelöscht: 8 historische Migrations-Pläne aus docs/archive/
- Entfernt: misc/ Ordner komplett (43 Dateien)

## Struktur
- Erstellt: database/queries/ für SQL Test-Queries (4 Dateien)
- Erstellt: database/schemas/ für Schema-Dokumentation (17 Dateien)
  - output_keys_mapping/ (8 CSV-Mappings)
  - migration-diagrams/ (4 Diagramme)

## Code-Qualität
- Formatiert: 7 Style-Issues in 74 Dateien mit Laravel Pint
- Gefixed: Migration für PostgreSQL/SQLite Kompatibilität
- Gefixed: 2 fehlgeschlagene Tests (CSRF + Text-Assertion)

## Tests
- Alle 73 Tests bestehen jetzt (100% Success Rate)
- AuthenticationTest: CSRF-Token Fix für Logout-Test
- CompanySearchTest: Text-Assertion aktualisiert

## Ergebnis
- Root ist sauber (nur CLAUDE.md)
- Dokumentation strukturiert in docs/
- Database-Dateien organisiert in database/
- Code entspricht Style-Guide
- Alle Tests bestehen
2025-11-21 10:00:32 +01:00

145 lines
4.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Console\Commands;
use App\Jobs\TransformDataPoolToProduction;
use Illuminate\Console\Command;
use function Laravel\Prompts\confirm;
use function Laravel\Prompts\info;
use function Laravel\Prompts\spin;
use function Laravel\Prompts\table;
use function Laravel\Prompts\warning;
class TransformDataPoolCommand extends Command
{
/**
* The name and signature of the console command.
*/
protected $signature = 'backend:transform-data-pool
{--batch-size=100 : Number of records to process per batch}
{--queue : Dispatch the job to the queue instead of running synchronously}
{--stats : Show statistics only, do not perform transformation}';
/**
* The console command description.
*/
protected $description = 'Transform backend_data_pool into companies and transactions tables';
/**
* Execute the console command.
*/
public function handle(): int
{
// Show stats only
if ($this->option('stats')) {
return $this->showStats();
}
info('Preparing for DATA POOL TRANSFORMATION');
warning('This will create/update companies and transactions from the data pool.');
if (! $this->option('no-interaction') && ! confirm('Do you want to continue?', true)) {
info('Transformation cancelled.');
return self::SUCCESS;
}
$batchSize = (int) $this->option('batch-size');
// Show current stats before transformation
$this->showStatsBefore();
// Create the job
$job = new TransformDataPoolToProduction(batchSize: $batchSize);
// Execute the job
if ($this->option('queue')) {
info('Dispatching job to queue...');
dispatch($job);
info('Job dispatched successfully!');
} else {
info('Running transformation synchronously...');
spin(
fn () => $job->handle(app(\App\Services\KycRiskCalculator::class)),
'Transforming data...'
);
info('Transformation completed successfully!');
}
// Show stats after transformation
$this->showStatsAfter();
return self::SUCCESS;
}
/**
* Show statistics only
*/
private function showStats(): int
{
$job = new TransformDataPoolToProduction;
$stats = $job->getStats();
info('Data Pool Transformation Statistics');
table(
['Metric', 'Value'],
[
['Data Pool Transactions', number_format($stats['data_pool_transactions'])],
['Companies in Database', number_format($stats['companies_count'])],
['Transactions in Database', number_format($stats['transactions_count'])],
['Migrated Transactions', number_format($stats['migrated_transactions'])],
]
);
return self::SUCCESS;
}
/**
* Show stats before transformation
*/
private function showStatsBefore(): void
{
$job = new TransformDataPoolToProduction;
$stats = $job->getStats();
$this->newLine();
info('Stats BEFORE transformation:');
table(
['Metric', 'Value'],
[
['Data Pool Transactions', number_format($stats['data_pool_transactions'])],
['Companies in Database', number_format($stats['companies_count'])],
['Migrated Transactions', number_format($stats['migrated_transactions'])],
]
);
$this->newLine();
}
/**
* Show stats after transformation
*/
private function showStatsAfter(): void
{
$job = new TransformDataPoolToProduction;
$stats = $job->getStats();
$this->newLine();
info('Stats AFTER transformation:');
table(
['Metric', 'Value'],
[
['Data Pool Transactions', number_format($stats['data_pool_transactions'])],
['Companies in Database', number_format($stats['companies_count'])],
['Migrated Transactions', number_format($stats['migrated_transactions'])],
]
);
$this->newLine();
}
}