Files
sam-api/database/migrations/2025_07_26_000818_create_roles_table.php

37 lines
1.3 KiB
PHP
Raw Normal View History

<?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
{
// 1. 컬럼 nullable 해제, 주석 보강, soft delete 추가
Schema::table('roles', function (Blueprint $table) {
// tenant_id NOT NULL로 변경
$table->unsignedBigInteger('tenant_id')->nullable(false)->change();
$table->string('name', 50)->comment('역할명')->change();
$table->string('description', 255)->nullable()->comment('설명')->change();
// deleted_at 추가 (soft delete)
$table->softDeletes()->comment('삭제일시(소프트삭제)');
});
// 2. (권장) 유니크 인덱스 보장: 한 테넌트 내에서 동일한 역할명 중복 불가
Schema::table('roles', function (Blueprint $table) {
$table->unique(['tenant_id', 'name'], 'uk_roles_tenant_name');
});
}
public function down(): void
{
Schema::table('roles', function (Blueprint $table) {
// 롤백시 soft delete 및 인덱스 제거
$table->dropSoftDeletes();
$table->dropUnique('uk_roles_tenant_name');
});
}
};