feat(proactive): integrate private supply observations and demonstrate Gurue comparison in QA

This commit is contained in:
2026-10-28 17:19:55 +02:00
parent 150bef4b89
commit 2f58b7d438
19 changed files with 1104 additions and 19 deletions
@@ -0,0 +1,49 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('proactive_supply_sources', function ($t) {
$t->char('sha256',64)->primary();
$t->text('name');
$t->text('period');
$t->text('limitations');
$t->jsonb('receipt');
$t->timestampTz('imported_at');
});
Schema::create('proactive_supply_observations', function ($t) {
$t->char('id',64)->primary();
$t->char('source_hash',64);
$t->foreign('source_hash')->references('sha256')->on('proactive_supply_sources')->restrictOnDelete();
$t->text('sheet');
$t->integer('row_number');
$t->char('entity_key',64)->index();
foreach (['name','province','district','cae','activity','sector','source_date'] as $field) $t->text($field);
$t->char('fingerprint',64)->index();
$t->char('duplicate_of',64)->nullable();
$t->boolean('identity_conflict')->default(false);
$t->uuid('territory_id')->nullable()->index();
$t->text('territory_resolution');
$t->index(['province','district']);
$t->unique(['source_hash','sheet','row_number']);
});
// Technical defence of the private-analysis scope, not a new business role.
foreach (['proactive_supply_sources','proactive_supply_observations'] as $table) {
DB::statement("ALTER TABLE {$table} ENABLE ROW LEVEL SECURITY");
DB::statement("ALTER TABLE {$table} FORCE ROW LEVEL SECURITY");
DB::statement("CREATE POLICY {$table}_private_read ON {$table} FOR SELECT USING (current_setting('app.proactive_supply_read',true)='internal' AND NULLIF(current_setting('app.actor_user_id',true),'')::bigint IS NOT NULL)");
}
}
public function down(): void
{
if (DB::table('proactive_supply_sources')->exists()) throw new RuntimeException('Preserve imported source history before rollback.');
Schema::dropIfExists('proactive_supply_observations');
Schema::dropIfExists('proactive_supply_sources');
}
};