schema->createTable('advertising_campaign_domains', function (SchemaBuilder $table) { $table->id(); $table->varchar('cuid', 64)->unique()->comment('CUID2 identifier'); $table->unsignedBigInteger('campaign_id')->index()->comment('Foreign key to advertising_campaigns'); $table->unsignedBigInteger('site_domain_id')->index()->comment('Foreign key to advertising_site_domains'); $table->tinyInteger('status')->default(1)->index()->comment('1=active, 0=inactive, -1=deleted'); $table->json('targeting_settings')->nullable()->comment('Domain-specific targeting settings'); $table->unsignedBigInteger('created_by')->index()->comment('User who created this association'); $table->timestamps(); $table->timestamp('deleted_at')->nullable()->index(); // Foreign key constraints $table->foreignKey('campaign_id', 'advertising_campaigns', 'id', 'CASCADE', 'CASCADE'); $table->foreignKey('site_domain_id', 'advertising_site_domains', 'id', 'CASCADE', 'CASCADE'); $table->foreignKey('created_by', 'users', 'id', 'CASCADE', 'CASCADE'); // Unique constraint to prevent duplicate campaign-domain associations $table->unique(['campaign_id', 'site_domain_id'], 'unique_campaign_domain'); // Indexes for performance $table->index(['campaign_id', 'status'], 'idx_campaign_status'); $table->index(['site_domain_id', 'status'], 'idx_domain_status'); }); } public function down(): void { $this->schema->dropTable('advertising_campaign_domains'); } }