diff --git a/app/database/migrations/2026_06_28_100100_create_autopodbor_competitors.php b/app/database/migrations/2026_06_28_100100_create_autopodbor_competitors.php new file mode 100644 index 00000000..610df0ed --- /dev/null +++ b/app/database/migrations/2026_06_28_100100_create_autopodbor_competitors.php @@ -0,0 +1,43 @@ +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'); + } +}; diff --git a/app/tests/Feature/Autopodbor/AutopodborCompetitorsSchemaTest.php b/app/tests/Feature/Autopodbor/AutopodborCompetitorsSchemaTest.php new file mode 100644 index 00000000..6b82a156 --- /dev/null +++ b/app/tests/Feature/Autopodbor/AutopodborCompetitorsSchemaTest.php @@ -0,0 +1,11 @@ +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(); +});