boolean('is_operator')->default(false); }); Schema::create('tenant_user', function (Blueprint $table) { $table->id(); $table->foreignId('tenant_id')->constrained()->cascadeOnDelete(); $table->foreignId('user_id')->constrained()->cascadeOnDelete(); $table->string('role'); $table->timestamps(); $table->unique(['tenant_id', 'user_id']); }); Schema::create('tenant_access_logs', function (Blueprint $table) { $table->id(); $table->foreignId('tenant_id')->constrained()->cascadeOnDelete(); $table->foreignId('user_id')->constrained()->cascadeOnDelete(); $table->timestamp('created_at')->useCurrent(); }); $tenantId = DB::table('tenants')->where('slug', 'stommer')->value('id'); if ($tenantId === null) { return; } $now = now(); foreach (DB::table('users')->whereNotNull('role')->get(['id', 'role']) as $user) { DB::table('tenant_user')->insert([ 'tenant_id' => $tenantId, 'user_id' => $user->id, 'role' => $user->role, 'created_at' => $now, 'updated_at' => $now, ]); } } /** * Drops memberships and the operator flag. Accounts and their old role column stay. */ public function down(): void { Schema::dropIfExists('tenant_access_logs'); Schema::dropIfExists('tenant_user'); Schema::table('users', function (Blueprint $table) { $table->dropColumn('is_operator'); }); } };