Implement tenant announcements and audit log fixes
This commit is contained in:
34
database/factories/TenantAnnouncementFactory.php
Normal file
34
database/factories/TenantAnnouncementFactory.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Enums\TenantAnnouncementAudience;
|
||||
use App\Enums\TenantAnnouncementStatus;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\TenantAnnouncement>
|
||||
*/
|
||||
class TenantAnnouncementFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'title' => $this->faker->sentence(4),
|
||||
'body' => $this->faker->paragraph(3),
|
||||
'cta_label' => null,
|
||||
'cta_url' => null,
|
||||
'status' => TenantAnnouncementStatus::DRAFT,
|
||||
'audience' => TenantAnnouncementAudience::ALL,
|
||||
'segments' => [],
|
||||
'email_enabled' => true,
|
||||
'starts_at' => null,
|
||||
'ends_at' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('tenant_announcements', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('title', 160);
|
||||
$table->text('body');
|
||||
$table->string('cta_label', 160)->nullable();
|
||||
$table->string('cta_url', 255)->nullable();
|
||||
$table->string('status', 24)->default('draft');
|
||||
$table->string('audience', 24)->default('all');
|
||||
$table->json('segments')->nullable();
|
||||
$table->boolean('email_enabled')->default(true);
|
||||
$table->timestamp('starts_at')->nullable();
|
||||
$table->timestamp('ends_at')->nullable();
|
||||
$table->foreignIdFor(\App\Models\User::class, 'created_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->foreignIdFor(\App\Models\User::class, 'updated_by')->nullable()->constrained('users')->nullOnDelete();
|
||||
$table->timestamps();
|
||||
|
||||
$table->index(['status', 'starts_at']);
|
||||
$table->index(['audience', 'status']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('tenant_announcements');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('tenant_announcement_deliveries', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('tenant_announcement_id')->constrained('tenant_announcements')->cascadeOnDelete();
|
||||
$table->foreignId('tenant_id')->constrained('tenants')->cascadeOnDelete();
|
||||
$table->string('channel', 24)->default('mail');
|
||||
$table->string('status', 24)->default('queued');
|
||||
$table->timestamp('sent_at')->nullable();
|
||||
$table->timestamp('failed_at')->nullable();
|
||||
$table->string('failure_reason', 255)->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['tenant_announcement_id', 'tenant_id', 'channel'], 'tenant_announcement_delivery_unique');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('tenant_announcement_deliveries');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('tenant_announcement_targets', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('tenant_announcement_id')->constrained('tenant_announcements')->cascadeOnDelete();
|
||||
$table->foreignId('tenant_id')->constrained('tenants')->cascadeOnDelete();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['tenant_announcement_id', 'tenant_id'], 'tenant_announcement_target_unique');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('tenant_announcement_targets');
|
||||
}
|
||||
};
|
||||
16
database/seeders/TenantAnnouncementSeeder.php
Normal file
16
database/seeders/TenantAnnouncementSeeder.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class TenantAnnouncementSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user