diff --git a/app/Mod/Names/Migrations/2026_04_04_add_workspace_to_names_tables.php b/app/Mod/Names/Migrations/2026_04_04_add_workspace_to_names_tables.php new file mode 100644 index 0000000..a1cc18e --- /dev/null +++ b/app/Mod/Names/Migrations/2026_04_04_add_workspace_to_names_tables.php @@ -0,0 +1,41 @@ +foreignId('workspace_id')->nullable()->after('id')->constrained('workspaces')->nullOnDelete(); + $table->index('workspace_id'); + }); + + Schema::table('dns_tickets', function (Blueprint $table) { + $table->foreignId('workspace_id')->nullable()->after('id')->constrained('workspaces')->nullOnDelete(); + $table->index('workspace_id'); + }); + + Schema::table('name_activity', function (Blueprint $table) { + $table->foreignId('workspace_id')->nullable()->after('id')->constrained('workspaces')->nullOnDelete(); + $table->index('workspace_id'); + }); + + // Backfill existing records with workspace 1 (Lethean CIC) + $wsId = \Illuminate\Support\Facades\DB::table('workspaces')->where('slug', 'lethean')->value('id'); + if ($wsId) { + \Illuminate\Support\Facades\DB::table('name_claims')->whereNull('workspace_id')->update(['workspace_id' => $wsId]); + \Illuminate\Support\Facades\DB::table('dns_tickets')->whereNull('workspace_id')->update(['workspace_id' => $wsId]); + \Illuminate\Support\Facades\DB::table('name_activity')->whereNull('workspace_id')->update(['workspace_id' => $wsId]); + } + } + + public function down(): void + { + Schema::table('name_claims', fn (Blueprint $t) => $t->dropColumn('workspace_id')); + Schema::table('dns_tickets', fn (Blueprint $t) => $t->dropColumn('workspace_id')); + Schema::table('name_activity', fn (Blueprint $t) => $t->dropColumn('workspace_id')); + } +}; diff --git a/app/Mod/Names/Models/DnsTicket.php b/app/Mod/Names/Models/DnsTicket.php index b3363f2..92c9705 100644 --- a/app/Mod/Names/Models/DnsTicket.php +++ b/app/Mod/Names/Models/DnsTicket.php @@ -15,6 +15,10 @@ use Illuminate\Database\Eloquent\Model; */ class DnsTicket extends Model { + use \Core\Tenant\Concerns\BelongsToWorkspace; + + protected bool $workspaceContextRequired = false; + protected $fillable = [ 'ticket_id', 'name', @@ -22,6 +26,7 @@ class DnsTicket extends Model 'tx_id', 'records', 'address', + 'workspace_id', 'comment', ]; diff --git a/app/Mod/Names/Models/NameClaim.php b/app/Mod/Names/Models/NameClaim.php index 5eab753..40f2f1f 100644 --- a/app/Mod/Names/Models/NameClaim.php +++ b/app/Mod/Names/Models/NameClaim.php @@ -15,11 +15,16 @@ use Illuminate\Database\Eloquent\Model; */ class NameClaim extends Model { + use \Core\Tenant\Concerns\BelongsToWorkspace; + + protected bool $workspaceContextRequired = false; + protected $fillable = [ 'claim_id', 'name', 'email', 'status', + 'workspace_id', ]; protected $attributes = [