feat: [email] 테넌트 메일 설정 마이그레이션 및 모델 추가

- tenant_mail_configs 테이블 생성 (SMTP 설정, 브랜딩, 연결 테스트 결과)
- mail_logs 테이블 생성 (발송 이력 추적)
- TenantMailConfig, MailLog 모델 추가 (options JSON 정책 준수)
This commit is contained in:
김보곤
2026-03-12 07:42:06 +09:00
parent eeda6d980e
commit 918ae0ebc1
4 changed files with 222 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('tenant_mail_configs', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
$table->string('provider', 20)->default('platform')->comment('발송 방식: platform, smtp, ses, mailgun');
$table->string('from_address', 255)->comment('발신 이메일');
$table->string('from_name', 255)->comment('발신자명');
$table->string('reply_to', 255)->nullable()->comment('회신 주소');
$table->boolean('is_verified')->default(false)->comment('도메인 검증 여부');
$table->unsignedInteger('daily_limit')->default(500)->comment('일일 발송 한도');
$table->boolean('is_active')->default(true)->comment('활성 여부');
$table->json('options')->nullable()->comment('SMTP 설정, 브랜딩, 연결 테스트 결과');
$table->unsignedBigInteger('created_by')->nullable()->comment('생성자');
$table->unsignedBigInteger('updated_by')->nullable()->comment('수정자');
$table->unsignedBigInteger('deleted_by')->nullable()->comment('삭제자');
$table->timestamps();
$table->softDeletes();
$table->unique('tenant_id', 'uq_tenant_mail_configs');
$table->index(['tenant_id', 'is_active']);
$table->foreign('tenant_id')->references('id')->on('tenants')->cascadeOnDelete();
});
}
public function down(): void
{
Schema::dropIfExists('tenant_mail_configs');
}
};

View File

@@ -0,0 +1,34 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('mail_logs', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
$table->string('mailable_type', 100)->comment('Mailable 클래스명');
$table->string('to_address', 255)->comment('수신자');
$table->string('from_address', 255)->comment('발신자');
$table->string('subject', 500)->comment('제목');
$table->string('status', 20)->default('queued')->comment('상태: queued, sent, failed, bounced');
$table->timestamp('sent_at')->nullable()->comment('발송 시각');
$table->json('options')->nullable()->comment('에러 메시지, 재시도 횟수, 관련 모델');
$table->timestamps();
$table->index(['tenant_id', 'status'], 'idx_mail_logs_tenant_status');
$table->index(['tenant_id', 'created_at'], 'idx_mail_logs_tenant_date');
$table->index(['tenant_id', 'mailable_type'], 'idx_mail_logs_mailable');
$table->foreign('tenant_id')->references('id')->on('tenants')->cascadeOnDelete();
});
}
public function down(): void
{
Schema::dropIfExists('mail_logs');
}
};