Assign the existing site to one landlord so stommer.info can run tenancy.

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>
This commit is contained in:
LarsandCursor committed 2026-10-23 12:00:11 +02:00
1 parent d9e52c4789
commit 8ebc1a3878
93 files changed
+2506 -112

No files matched your search

@@ -0,0 +1,100 @@
<?php
use App\Tenancy\AssignLegacyData;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Add landlords and point every existing row at "Stommer". Columns start nullable so the
* assignment can run, then become required. Old code ignores the new columns.
*/
public function up(): void
{
Schema::create('tenants', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('slug')->unique();
$table->boolean('is_active')->default(true);
$table->timestamps();
});
foreach (AssignLegacyData::TABLES as $name) {
Schema::table($name, function (Blueprint $table) {
$table->foreignId('tenant_id')->nullable()->constrained()->restrictOnDelete();
});
}
AssignLegacyData::run();
foreach (AssignLegacyData::TABLES as $name) {
Schema::table($name, function (Blueprint $table) {
$table->unsignedBigInteger('tenant_id')->nullable(false)->change();
});
}
Schema::table('bookings', function (Blueprint $table) {
$table->dropUnique(['reference']);
$table->unique(['tenant_id', 'reference']);
});
Schema::table('content_blocks', function (Blueprint $table) {
$table->dropUnique(['key']);
$table->unique(['tenant_id', 'key']);
});
Schema::table('portal_emails', function (Blueprint $table) {
$table->dropUnique(['message_id']);
$table->unique(['tenant_id', 'message_id']);
});
Schema::table('properties', function (Blueprint $table) {
$table->dropUnique(['slug']);
$table->unique(['tenant_id', 'slug']);
});
Schema::table('guests', function (Blueprint $table) {
$table->index(['tenant_id', 'email']);
});
}
/**
* Drops the landlord assignment. Rows stay; the link to a landlord does not.
*/
public function down(): void
{
Schema::table('guests', function (Blueprint $table) {
$table->dropIndex(['tenant_id', 'email']);
});
Schema::table('properties', function (Blueprint $table) {
$table->dropUnique(['tenant_id', 'slug']);
$table->unique('slug');
});
Schema::table('portal_emails', function (Blueprint $table) {
$table->dropUnique(['tenant_id', 'message_id']);
$table->unique('message_id');
});
Schema::table('content_blocks', function (Blueprint $table) {
$table->dropUnique(['tenant_id', 'key']);
$table->unique('key');
});
Schema::table('bookings', function (Blueprint $table) {
$table->dropUnique(['tenant_id', 'reference']);
$table->unique('reference');
});
foreach (array_reverse(AssignLegacyData::TABLES) as $name) {
Schema::table($name, function (Blueprint $table) {
$table->dropConstrainedForeignId('tenant_id');
});
}
Schema::dropIfExists('tenants');
}
};
@@ -0,0 +1,68 @@
<?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');
});
}
};
@@ -0,0 +1,38 @@
<?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
{
/**
* A website can answer on more than one host. The existing sites.domain value is the first host.
*/
public function up(): void
{
Schema::create('site_domains', function (Blueprint $table) {
$table->id();
$table->foreignId('site_id')->constrained()->cascadeOnDelete();
$table->string('host')->unique();
$table->timestamps();
});
$now = now();
foreach (DB::table('sites')->whereNotNull('domain')->where('domain', '!=', '')->get(['id', 'domain']) as $site) {
DB::table('site_domains')->insert([
'site_id' => $site->id,
'host' => mb_strtolower($site->domain),
'created_at' => $now,
'updated_at' => $now,
]);
}
}
public function down(): void
{
Schema::dropIfExists('site_domains');
}
};