2025_11_21_144756_create_sms_messages.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. use Illuminate\Database\Schema\Blueprint;
  3. use Illuminate\Support\Facades\Schema;
  4. use App\Database\Migrations\TenantMigration;
  5. return new class extends TenantMigration
  6. {
  7. public function up()
  8. {
  9. Schema::create('sms_messages', function (Blueprint $t) {
  10. $t->id();
  11. $t->string('subject');
  12. $t->longText('content');
  13. $t->enum('status', ['draft', 'scheduled', 'processing', 'sent', 'failed', 'canceled'])->default('draft')->index();
  14. $t->dateTime('schedule_at')->nullable()->index();
  15. $t->dateTime('sent_at')->nullable();
  16. $t->unsignedBigInteger('created_by')->index();
  17. $t->timestamps();
  18. });
  19. Schema::create('sms_message_recipients', function (Blueprint $t) {
  20. $t->id();
  21. $t->foreignId('sms_message_id')->constrained('sms_messages')->cascadeOnDelete();
  22. $t->foreignId('member_id')->nullable()->constrained('members')->nullOnDelete();
  23. $t->string('phone');
  24. $t->enum('status', ['pending', 'sent', 'failed', 'bounced', 'skipped'])->default('pending')->index();
  25. $t->text('error_message')->nullable();
  26. $t->dateTime('sent_at')->nullable();
  27. $t->timestamps();
  28. $t->index(['sms_message_id', 'status']);
  29. });
  30. }
  31. public function down()
  32. {
  33. Schema::dropIfExists('sms_message_recipients');
  34. Schema::dropIfExists('sms_messages');
  35. }
  36. };