feat(tenant): separate admin and storefront website types
This commit is contained in:
132
database/migrations/2026_09_17_000000_split_website_types.php
Normal file
132
database/migrations/2026_09_17_000000_split_website_types.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?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
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('storefront_website_types', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('codigo')->unique();
|
||||
$table->string('nombre');
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
DB::table('website_type')->orderBy('id')->chunk(100, function ($types): void {
|
||||
foreach ($types as $type) {
|
||||
DB::table('storefront_website_types')->insert([
|
||||
'id' => $type->id,
|
||||
'codigo' => $type->codigo,
|
||||
'nombre' => $type->nombre,
|
||||
'created_at' => $type->created_at,
|
||||
'updated_at' => $type->updated_at,
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
Schema::table('tenants', function (Blueprint $table): void {
|
||||
$table->string('storefront_website_type_code')->nullable();
|
||||
});
|
||||
|
||||
DB::table('tenants')->orderBy('id')->chunk(100, function ($tenants): void {
|
||||
foreach ($tenants as $tenant) {
|
||||
$type = $tenant->website_type_code
|
||||
? DB::table('website_type')->where('codigo', $tenant->website_type_code)->first()
|
||||
: null;
|
||||
|
||||
DB::table('tenants')->where('id', $tenant->id)->update([
|
||||
'storefront_website_type_code' => $tenant->website_type_code,
|
||||
'site_title' => $tenant->site_title ?? $type?->site_title,
|
||||
'favicon_id' => $tenant->favicon_id ?? $type?->favicon_id,
|
||||
]);
|
||||
}
|
||||
});
|
||||
|
||||
if (DB::getDriverName() !== 'sqlite') {
|
||||
Schema::table('tenants', fn (Blueprint $table) => $table->dropForeign(['website_type_code']));
|
||||
Schema::table('website_type_extras', fn (Blueprint $table) => $table->dropForeign(['website_type_code']));
|
||||
Schema::table('website_type_integrations', fn (Blueprint $table) => $table->dropForeign(['website_type_code']));
|
||||
}
|
||||
|
||||
Schema::rename('website_type', 'admin_website_types');
|
||||
Schema::rename('website_type_extras', 'storefront_website_type_extras');
|
||||
Schema::rename('website_type_integrations', 'admin_website_type_integrations');
|
||||
|
||||
Schema::table('tenants', fn (Blueprint $table) => $table->renameColumn('website_type_code', 'admin_website_type_code'));
|
||||
Schema::table('storefront_website_type_extras', fn (Blueprint $table) => $table->renameColumn('website_type_code', 'storefront_website_type_code'));
|
||||
Schema::table('admin_website_type_integrations', fn (Blueprint $table) => $table->renameColumn('website_type_code', 'admin_website_type_code'));
|
||||
|
||||
if (DB::getDriverName() === 'sqlite') {
|
||||
Schema::disableForeignKeyConstraints();
|
||||
Schema::create('storefront_website_type_extras_rebuilt', function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->string('storefront_website_type_code');
|
||||
$table->foreign('storefront_website_type_code')->references('codigo')->on('storefront_website_types')->cascadeOnUpdate()->cascadeOnDelete();
|
||||
$table->string('codigo')->nullable();
|
||||
$table->string('nombre');
|
||||
$table->text('descripcion');
|
||||
$table->boolean('is_required')->default(false);
|
||||
$table->json('config_schema');
|
||||
$table->timestamps();
|
||||
$table->unique(['storefront_website_type_code', 'codigo']);
|
||||
});
|
||||
DB::table('storefront_website_type_extras')->orderBy('id')->chunk(100, function ($extras): void {
|
||||
foreach ($extras as $extra) {
|
||||
DB::table('storefront_website_type_extras_rebuilt')->insert((array) $extra);
|
||||
}
|
||||
});
|
||||
Schema::drop('storefront_website_type_extras');
|
||||
Schema::rename('storefront_website_type_extras_rebuilt', 'storefront_website_type_extras');
|
||||
Schema::enableForeignKeyConstraints();
|
||||
}
|
||||
|
||||
Schema::table('tenants', function (Blueprint $table): void {
|
||||
if (DB::getDriverName() !== 'sqlite') {
|
||||
$table->foreign('admin_website_type_code')->references('codigo')->on('admin_website_types')->cascadeOnUpdate()->nullOnDelete();
|
||||
}
|
||||
$table->foreign('storefront_website_type_code')->references('codigo')->on('storefront_website_types')->cascadeOnUpdate()->nullOnDelete();
|
||||
});
|
||||
if (DB::getDriverName() !== 'sqlite') {
|
||||
Schema::table('storefront_website_type_extras', function (Blueprint $table): void {
|
||||
$table->foreign('storefront_website_type_code')->references('codigo')->on('storefront_website_types')->cascadeOnUpdate()->cascadeOnDelete();
|
||||
});
|
||||
Schema::table('admin_website_type_integrations', function (Blueprint $table): void {
|
||||
$table->foreign('admin_website_type_code')->references('codigo')->on('admin_website_types')->cascadeOnDelete();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (DB::getDriverName() === 'sqlite') {
|
||||
throw new RuntimeException('SQLite rollback is unsupported for this foreign-key refactor. Recreate the test database instead.');
|
||||
}
|
||||
|
||||
Schema::table('tenants', function (Blueprint $table): void {
|
||||
$table->dropForeign(['admin_website_type_code']);
|
||||
$table->dropForeign(['storefront_website_type_code']);
|
||||
});
|
||||
Schema::table('storefront_website_type_extras', fn (Blueprint $table) => $table->dropForeign(['storefront_website_type_code']));
|
||||
Schema::table('admin_website_type_integrations', fn (Blueprint $table) => $table->dropForeign(['admin_website_type_code']));
|
||||
|
||||
Schema::table('tenants', fn (Blueprint $table) => $table->renameColumn('admin_website_type_code', 'website_type_code'));
|
||||
Schema::table('storefront_website_type_extras', fn (Blueprint $table) => $table->renameColumn('storefront_website_type_code', 'website_type_code'));
|
||||
Schema::table('admin_website_type_integrations', fn (Blueprint $table) => $table->renameColumn('admin_website_type_code', 'website_type_code'));
|
||||
|
||||
Schema::rename('admin_website_types', 'website_type');
|
||||
Schema::rename('storefront_website_type_extras', 'website_type_extras');
|
||||
Schema::rename('admin_website_type_integrations', 'website_type_integrations');
|
||||
|
||||
Schema::table('tenants', function (Blueprint $table): void {
|
||||
$table->foreign('website_type_code')->references('codigo')->on('website_type')->cascadeOnUpdate()->nullOnDelete();
|
||||
$table->dropColumn('storefront_website_type_code');
|
||||
});
|
||||
Schema::table('website_type_extras', fn (Blueprint $table) => $table->foreign('website_type_code')->references('codigo')->on('website_type')->cascadeOnUpdate()->cascadeOnDelete());
|
||||
Schema::table('website_type_integrations', fn (Blueprint $table) => $table->foreign('website_type_code')->references('codigo')->on('website_type')->cascadeOnDelete());
|
||||
Schema::dropIfExists('storefront_website_types');
|
||||
}
|
||||
};
|
||||
@@ -78,7 +78,8 @@ class DesfilePuraTendenciaSeeder extends Seeder
|
||||
'checkout_editing_policy' => 'disabled',
|
||||
'display_cart_item_images' => false,
|
||||
'scanner_category_validation_enabled' => false,
|
||||
'website_type_code' => 'onticket',
|
||||
'admin_website_type_code' => 'onticket',
|
||||
'storefront_website_type_code' => 'onticket',
|
||||
'header_logo' => $this->uploadedImage(
|
||||
'images/tennants/desfile_pura_tendencia/desfile_pura_tendencia_header.png',
|
||||
'desfile_pura_tendencia_header.png',
|
||||
|
||||
@@ -6,7 +6,7 @@ use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Attachable\Services\AttachmentService;
|
||||
use App\Domains\Client\Models\Client;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
use App\Domains\Tenant\Models\WebsiteType;
|
||||
use App\Domains\Tenant\Models\AdminWebsiteType;
|
||||
use App\Domains\Tenant\Services\TenantService;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
@@ -56,7 +56,7 @@ class TenantSeeder extends Seeder
|
||||
['name' => 'OnTicket'],
|
||||
);
|
||||
|
||||
$onTicketType = WebsiteType::query()->where('codigo', 'onticket')->firstOrFail();
|
||||
$onTicketType = AdminWebsiteType::query()->where('codigo', 'onticket')->firstOrFail();
|
||||
|
||||
$onTicketTenant = Tenant::query()->where('codigo', 'onticket')->first();
|
||||
|
||||
@@ -75,7 +75,8 @@ class TenantSeeder extends Seeder
|
||||
'footer_bg_color' => $onTicketType->surface_color,
|
||||
'display_categories' => false,
|
||||
'display_seach_bar' => false,
|
||||
'website_type_code' => $onTicketType->codigo,
|
||||
'admin_website_type_code' => $onTicketType->codigo,
|
||||
'storefront_website_type_code' => $onTicketType->codigo,
|
||||
'header_logo' => $this->uploadedImage(
|
||||
'images/tennants/onticket/onticket_logo.png',
|
||||
'onticket_logo.png',
|
||||
@@ -127,7 +128,8 @@ class TenantSeeder extends Seeder
|
||||
'header_logo' => $this->uploadedImage('images/tennants/sonder/sonder_header.png', 'sonder_header.png'),
|
||||
'footer_logo' => $this->uploadedImage('images/tennants/sonder/sonder_footer.png', 'sonder_footer.png'),
|
||||
'social_media' => self::SOCIAL_MEDIA,
|
||||
'website_type_code' => 'shopit',
|
||||
'admin_website_type_code' => 'shopit',
|
||||
'storefront_website_type_code' => 'shopit',
|
||||
'extras' => [
|
||||
'carousel' => [
|
||||
$this->uploadedImage(
|
||||
@@ -195,7 +197,8 @@ class TenantSeeder extends Seeder
|
||||
'futbol_infantil_favicon.png',
|
||||
),
|
||||
'social_media' => self::SOCIAL_MEDIA,
|
||||
'website_type_code' => 'onticket',
|
||||
'admin_website_type_code' => 'onticket',
|
||||
'storefront_website_type_code' => 'onticket',
|
||||
'extras' => [
|
||||
'heroConfig' => [
|
||||
'title_html' => '<h1>Fiesta Fútbol Infantil</h1>',
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Domains\Tenant\Services\WebsiteTypeService;
|
||||
use App\Domains\Tenant\Services\AdminWebsiteTypeService;
|
||||
use App\Domains\Tenant\Models\StorefrontWebsiteType;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use RuntimeException;
|
||||
@@ -22,7 +23,7 @@ class WebsiteTypeSeeder extends Seeder
|
||||
'border_color' => '#EAEAEA',
|
||||
];
|
||||
|
||||
public function __construct(private readonly WebsiteTypeService $websiteTypeService) {}
|
||||
public function __construct(private readonly AdminWebsiteTypeService $websiteTypeService) {}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
@@ -40,7 +41,9 @@ class WebsiteTypeSeeder extends Seeder
|
||||
],
|
||||
);
|
||||
|
||||
$shopIt->extras()->updateOrCreate(
|
||||
$shopItStorefront = StorefrontWebsiteType::query()->updateOrCreate(['codigo' => 'shopit'], ['nombre' => 'ShopIt']);
|
||||
|
||||
$shopItStorefront->extras()->updateOrCreate(
|
||||
['codigo' => 'carousel'],
|
||||
[
|
||||
'nombre' => 'Carrusel principal',
|
||||
@@ -75,7 +78,9 @@ class WebsiteTypeSeeder extends Seeder
|
||||
],
|
||||
);
|
||||
|
||||
$onTicket->extras()->updateOrCreate(
|
||||
$onTicketStorefront = StorefrontWebsiteType::query()->updateOrCreate(['codigo' => 'onticket'], ['nombre' => 'OnTicket']);
|
||||
|
||||
$onTicketStorefront->extras()->updateOrCreate(
|
||||
['codigo' => 'heroConfig'],
|
||||
[
|
||||
'nombre' => 'Configuración del hero',
|
||||
@@ -100,7 +105,7 @@ class WebsiteTypeSeeder extends Seeder
|
||||
],
|
||||
);
|
||||
|
||||
$onTicket->extras()->updateOrCreate(
|
||||
$onTicketStorefront->extras()->updateOrCreate(
|
||||
['codigo' => 'eventConfig'],
|
||||
[
|
||||
'nombre' => 'Información del evento',
|
||||
@@ -127,7 +132,7 @@ class WebsiteTypeSeeder extends Seeder
|
||||
],
|
||||
);
|
||||
|
||||
$onTicket->extras()->updateOrCreate(
|
||||
$onTicketStorefront->extras()->updateOrCreate(
|
||||
['codigo' => 'additionalInfoConfig'],
|
||||
[
|
||||
'nombre' => 'Información adicional',
|
||||
|
||||
Reference in New Issue
Block a user