feat(tenant): add Desfile footer background asset migration

- Add footer background image for Desfile Pura Tendencia
- Upload and associate the asset with the tenant during migration
- Extend migration coverage to verify attachment creation and storage
This commit is contained in:
2026-08-12 13:54:05 -03:00
parent f50d3d0587
commit 45d74e166f
3 changed files with 92 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
return new class extends Migration
{
private const TENANT_CODE = 'desfile_pura_tendencia';
private const FILENAME = 'desfile_pura_tendencia_footer_background.png';
public function up(): void
{
$tenant = DB::table('tenants')
->where('codigo', self::TENANT_CODE)
->first(['id', 'footer_bg_image_id']);
if ($tenant === null || $tenant->footer_bg_image_id !== null) {
return;
}
$sourcePath = public_path(
'images/tennants/desfile_pura_tendencia/'.self::FILENAME
);
if (! is_file($sourcePath)) {
throw new RuntimeException("Image not found at path: {$sourcePath}");
}
$contents = file_get_contents($sourcePath);
if ($contents === false) {
throw new RuntimeException("Could not read image at path: {$sourcePath}");
}
$key = (string) Str::uuid();
$storedPath = 'tenants/'.self::TENANT_CODE.'/'.$key.'.png';
if (! Storage::disk('s3')->put($storedPath, $contents)) {
throw new RuntimeException("Could not store image at path: {$storedPath}");
}
try {
DB::transaction(function () use ($contents, $key, $storedPath): void {
$attachmentId = DB::table('attachments')->insertGetId([
'key' => $key,
'path' => $storedPath,
'filename' => self::FILENAME,
'type' => 'image',
'mime_type' => 'image/png',
'extension' => 'png',
'size' => strlen($contents),
'created_at' => now(),
'updated_at' => now(),
]);
DB::table('tenants')
->where('codigo', self::TENANT_CODE)
->update([
'footer_bg_image_id' => $attachmentId,
'updated_at' => now(),
]);
});
} catch (Throwable $throwable) {
Storage::disk('s3')->delete($storedPath);
throw $throwable;
}
}
public function down(): void
{
// The attachment may already be referenced externally; keep this data
// migration irreversible instead of deleting a potentially active asset.
}
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

View File

@@ -31,6 +31,11 @@ class CreateDesfilePuraTendenciaTenantTest extends TestCase
);
$migration->up();
$footerBackgroundMigration = require database_path(
'migrations/2026_08_12_060000_set_desfile_footer_background_image.php'
);
$footerBackgroundMigration->up();
$this->assertDatabaseHas('tenants', [
'codigo' => 'desfile_pura_tendencia',
'nombre' => 'Desfile Pura Tendencia',
@@ -85,11 +90,20 @@ class CreateDesfilePuraTendenciaTenantTest extends TestCase
'filename' => 'desfile_pura_tendencia_hero.png',
'type' => 'image',
]);
$footerBackgroundImageId = DB::table('tenants')
->where('codigo', 'desfile_pura_tendencia')
->value('footer_bg_image_id');
$this->assertDatabaseHas('attachments', [
'id' => $footerBackgroundImageId,
'filename' => 'desfile_pura_tendencia_footer_background.png',
'type' => 'image',
]);
foreach ([
'desfile_pura_tendencia_header.png',
'desfile_pura_tendencia_footer.png',
'desfile_pura_tendencia_hero.png',
'desfile_pura_tendencia_footer_background.png',
'entrada_pasarela.png',
] as $filename) {
$path = DB::table('attachments')->where('filename', $filename)->value('path');