Seebad 0.3 stays in this release. With a single landlord every host still reaches the default website. Co-authored-by: Cursor <cursoragent@cursor.com>
69 lines
2.1 KiB
PHP
69 lines
2.1 KiB
PHP
<?php
|
|
|
|
use Illuminate\Database\Migrations\Migration;
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
return new class extends Migration
|
|
{
|
|
/**
|
|
* Membership is the role inside one landlord. The operator flag stays off here: it is granted
|
|
* afterwards with users:promote-operator, never by copying the old global role.
|
|
*/
|
|
public function up(): void
|
|
{
|
|
Schema::table('users', function (Blueprint $table) {
|
|
$table->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');
|
|
});
|
|
}
|
|
};
|