feat: BelongsToWorkspace on NameClaim, DnsTicket, NameActivity

Multi-tenant scoping via CorePHP tenant package. workspace_id column
added to all three tables. Existing records backfilled to workspace 1
(Lethean CIC). workspaceContextRequired=false allows public API calls
without workspace context.

Commit #100.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Claude 2026-04-04 12:55:34 +01:00
parent d1873dbe09
commit 1e34701e71
No known key found for this signature in database
GPG key ID: AF404715446AEB41
3 changed files with 51 additions and 0 deletions

View file

@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('name_claims', function (Blueprint $table) {
$table->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'));
}
};

View file

@ -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',
];

View file

@ -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 = [