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:
1 parent
d9e52c4789
commit
8ebc1a3878
93 files changed
+2506
-112
No files matched your search
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tenancy;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Points every existing row at the landlord "Stommer". Used once, when tenancy is introduced
|
||||
* on a database that already has the single-landlord data. Fresh databases have nothing to assign.
|
||||
*/
|
||||
class AssignLegacyData
|
||||
{
|
||||
/**
|
||||
* Tables that gain a tenant_id. Order is irrelevant; nothing is deleted.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public const TABLES = [
|
||||
'sites',
|
||||
'properties',
|
||||
'guests',
|
||||
'bookings',
|
||||
'channels',
|
||||
'portal_emails',
|
||||
'photos',
|
||||
'pages',
|
||||
'appearances',
|
||||
'notices',
|
||||
'faqs',
|
||||
'blocked_periods',
|
||||
'amenities',
|
||||
'reviews',
|
||||
'channel_tasks',
|
||||
'payments',
|
||||
'seasons',
|
||||
'extras',
|
||||
'special_offers',
|
||||
'channel_sync_logs',
|
||||
'content_blocks',
|
||||
];
|
||||
|
||||
public static function run(): void
|
||||
{
|
||||
$pending = false;
|
||||
|
||||
foreach (self::TABLES as $table) {
|
||||
if (DB::table($table)->whereNull('tenant_id')->exists()) {
|
||||
$pending = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $pending) {
|
||||
return;
|
||||
}
|
||||
|
||||
$tenantId = DB::table('tenants')->where('slug', 'stommer')->value('id');
|
||||
|
||||
if ($tenantId === null) {
|
||||
$tenantId = DB::table('tenants')->insertGetId([
|
||||
'name' => 'Stommer',
|
||||
'slug' => 'stommer',
|
||||
'is_active' => true,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
foreach (self::TABLES as $table) {
|
||||
DB::table($table)->whereNull('tenant_id')->update(['tenant_id' => $tenantId]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user