Merge branch 'feature/event_scoped_admin' into homo
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?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
|
||||
{
|
||||
// Validate before changing the schema, including soft-deleted reservations.
|
||||
if (DB::table('desfile_entry_reservations as reservations')
|
||||
->leftJoin('variantes', 'variantes.id', '=', 'reservations.variant_id')
|
||||
->leftJoin('catalog_items', 'catalog_items.id', '=', 'variantes.catalog_item_id')
|
||||
->whereNull('catalog_items.id')->exists()) {
|
||||
throw new LogicException('No se puede determinar el catálogo de todas las reservas existentes.');
|
||||
}
|
||||
|
||||
Schema::rename('desfile_reservation_batches', 'reservation_batches');
|
||||
Schema::rename('desfile_entry_reservations', 'entry_reservations');
|
||||
|
||||
Schema::table('entry_reservations', function (Blueprint $table): void {
|
||||
$table->foreignId('catalog_item_id')->nullable()
|
||||
->constrained('catalog_items')->restrictOnDelete();
|
||||
$table->unsignedBigInteger('variant_id')->nullable()->change();
|
||||
});
|
||||
|
||||
DB::table('entry_reservations')->update([
|
||||
'catalog_item_id' => DB::raw('(SELECT catalog_item_id FROM variantes WHERE variantes.id = entry_reservations.variant_id)'),
|
||||
]);
|
||||
|
||||
Schema::table('entry_reservations', function (Blueprint $table): void {
|
||||
$table->unsignedBigInteger('catalog_item_id')->nullable(false)->change();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
// The old schema cannot represent tickets without variants. Never discard them.
|
||||
if (DB::table('entry_reservations')->whereNull('variant_id')->exists()) {
|
||||
throw new LogicException('No se puede revertir mientras existan reservas sin variante.');
|
||||
}
|
||||
|
||||
Schema::table('entry_reservations', function (Blueprint $table): void {
|
||||
$table->dropConstrainedForeignId('catalog_item_id');
|
||||
$table->unsignedBigInteger('variant_id')->nullable(false)->change();
|
||||
});
|
||||
|
||||
Schema::rename('entry_reservations', 'desfile_entry_reservations');
|
||||
Schema::rename('reservation_batches', 'desfile_reservation_batches');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
private const MENU_CODE = 'adminapp.ticket-reservations';
|
||||
|
||||
private const TENANT_CODE = 'onticket';
|
||||
|
||||
public function up(): void
|
||||
{
|
||||
if (! DB::table('menues')->where('code', 'main.adminapp')->exists()) {
|
||||
// Reference data is added by seeders on fresh installations.
|
||||
return;
|
||||
}
|
||||
|
||||
$now = now();
|
||||
|
||||
DB::transaction(function () use ($now): void {
|
||||
DB::table('menues')->updateOrInsert(
|
||||
['code' => self::MENU_CODE],
|
||||
[
|
||||
'label' => 'Reserva de Tickets',
|
||||
'parent_menu_code' => 'main.adminapp',
|
||||
'content_type' => 'dynamic',
|
||||
'static_content_schema' => null,
|
||||
'route' => '/admin/ticket-reservations',
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
],
|
||||
);
|
||||
|
||||
DB::table('tenants_menues')
|
||||
->where('menu_code', self::MENU_CODE)
|
||||
->where('tenant_code', '!=', self::TENANT_CODE)
|
||||
->delete();
|
||||
|
||||
if (DB::table('tenants')->where('codigo', self::TENANT_CODE)->exists()) {
|
||||
DB::table('tenants_menues')->updateOrInsert(
|
||||
[
|
||||
'tenant_code' => self::TENANT_CODE,
|
||||
'menu_code' => self::MENU_CODE,
|
||||
],
|
||||
[
|
||||
'static_content' => null,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
DB::table('roles')
|
||||
->whereIn('codigo', ['admin', 'adminapp'])
|
||||
->pluck('codigo')
|
||||
->each(function (string $roleCode): void {
|
||||
DB::table('roles_menues')->updateOrInsert([
|
||||
'rol_codigo' => $roleCode,
|
||||
'menu_codigo' => self::MENU_CODE,
|
||||
]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
DB::transaction(function (): void {
|
||||
DB::table('tenants_menues')
|
||||
->where('menu_code', self::MENU_CODE)
|
||||
->delete();
|
||||
|
||||
DB::table('roles_menues')
|
||||
->where('menu_codigo', self::MENU_CODE)
|
||||
->delete();
|
||||
|
||||
DB::table('menues')
|
||||
->where('code', self::MENU_CODE)
|
||||
->delete();
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user