Files
sam-api/database/migrations/2025_07_26_000818_create_roles_table.php
kent f5534e437b fix : 테이블 추가 및 수정
- 신규 (user_roles, user_tenants)
- 수정 (roles, tenants, users)
2025-07-26 01:23:02 +09:00

37 lines
1.3 KiB
PHP

<?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');
});
}
};