KTV/database/migrations/2025_08_03_162846_create_broadcast_table.php

45 lines
1.6 KiB
PHP
Raw Normal View History

2025-08-13 14:44:52 +08:00
<?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('broadcast_templates', function (Blueprint $table) {
$table->id();
$table->text('content')->comment('公告內容'); // e.g., "親愛的 **name**,歡迎光臨!"
$table->enum('color', ['white', 'red', 'green','blue'])->default('white')->comment('顯示顏色');
$table->boolean('is_active')->default(true); // 啟用狀態
$table->timestamps();
});
Schema::create('text_broadcasts', function (Blueprint $table) {
$table->id();
$table->foreignId('template_id')->nullable()->constrained('broadcast_templates')->nullOnDelete();
$table->text('content'); // Final content with variables replaced
$table->enum('target_type', ['all', 'rooms'])->default('all');
$table->timestamps();
});
Schema::create('text_broadcast_room', function (Blueprint $table) {
$table->id();
$table->foreignId('text_broadcast_id')->constrained()->onDelete('cascade');
$table->foreignId('room_id')->constrained()->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('text_broadcast_room');
Schema::dropIfExists('text_broadcasts');
Schema::dropIfExists('broadcast_templates');
}
};