feat(автоподбор): таблица autopodbor_competitors + RLS

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Дмитрий
2026-06-28 12:49:52 +03:00
parent e7660edd79
commit 786f796223
2 changed files with 54 additions and 0 deletions
@@ -0,0 +1,43 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
Schema::create('autopodbor_competitors', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('tenant_id');
$table->unsignedBigInteger('search_run_id')->nullable();
$table->string('name', 255);
$table->text('description')->nullable();
$table->boolean('is_federal')->default(false);
$table->smallInteger('relevance_pct')->nullable();
$table->string('origin', 16)->default('auto'); // auto|manual|resolve
$table->string('site_url', 255)->nullable();
$table->jsonb('directory_urls')->default(DB::raw("'[]'::jsonb"));
$table->jsonb('provenance')->default(DB::raw("'{}'::jsonb"));
$table->string('dedup_key', 255);
$table->unsignedBigInteger('study_run_id')->nullable();
$table->timestampTz('studied_at')->nullable();
$table->timestampTz('created_at')->useCurrent();
$table->foreign('tenant_id')->references('id')->on('tenants')->cascadeOnDelete();
$table->foreign('search_run_id')->references('id')->on('autopodbor_runs')->nullOnDelete();
$table->foreign('study_run_id')->references('id')->on('autopodbor_runs')->nullOnDelete();
$table->index(['tenant_id', 'search_run_id']);
$table->unique(['tenant_id', 'search_run_id', 'dedup_key'], 'autopodbor_competitor_dedup');
});
DB::statement('ALTER TABLE autopodbor_competitors ENABLE ROW LEVEL SECURITY');
DB::statement('ALTER TABLE autopodbor_competitors FORCE ROW LEVEL SECURITY');
DB::statement("CREATE POLICY tenant_isolation ON autopodbor_competitors USING (tenant_id = current_setting('app.current_tenant_id')::bigint)");
}
public function down(): void
{
Schema::dropIfExists('autopodbor_competitors');
}
};
@@ -0,0 +1,11 @@
<?php
use Illuminate\Support\Facades\DB;
it('создаёт autopodbor_competitors', function () {
expect(DB::getSchemaBuilder()->hasTable('autopodbor_competitors'))->toBeTrue();
expect(DB::getSchemaBuilder()->hasColumns('autopodbor_competitors', [
'id','tenant_id','search_run_id','name','description','is_federal',
'relevance_pct','origin','site_url','directory_urls','provenance',
'dedup_key','study_run_id','studied_at','created_at',
]))->toBeTrue();
});