feat(автоподбор): таблица autopodbor_competitors + RLS
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user