fix: [migration] 이미 존재하는 테이블/컬럼에 대한 안전 가드 추가

- hasTable/hasColumn 체크로 중복 생성 방지
- 로컬/개발서버 DB 상태 불일치 시에도 마이그레이션 안전 실행
This commit is contained in:
김보곤
2026-03-17 15:41:20 +09:00
parent b10713344a
commit a96fd254e5
15 changed files with 60 additions and 0 deletions

View File

@@ -8,6 +8,10 @@
{
public function up(): void
{
if (Schema::hasTable('quality_documents')) {
return;
}
Schema::create('quality_documents', function (Blueprint $table) {
$table->id();
$table->foreignId('tenant_id')->constrained();

View File

@@ -8,6 +8,10 @@
{
public function up(): void
{
if (Schema::hasTable('quality_document_orders')) {
return;
}
Schema::create('quality_document_orders', function (Blueprint $table) {
$table->id();
$table->foreignId('quality_document_id')->constrained()->cascadeOnDelete();

View File

@@ -8,6 +8,10 @@
{
public function up(): void
{
if (Schema::hasTable('quality_document_locations')) {
return;
}
Schema::create('quality_document_locations', function (Blueprint $table) {
$table->id();
$table->foreignId('quality_document_id')->constrained()->cascadeOnDelete();

View File

@@ -8,6 +8,10 @@
{
public function up(): void
{
if (Schema::hasTable('performance_reports')) {
return;
}
Schema::create('performance_reports', function (Blueprint $table) {
$table->id();
$table->foreignId('tenant_id')->constrained();

View File

@@ -8,6 +8,10 @@
{
public function up(): void
{
if (Schema::hasColumn('quality_document_locations', 'inspection_data')) {
return;
}
Schema::table('quality_document_locations', function (Blueprint $table) {
$table->json('inspection_data')->nullable()->after('change_reason')->comment('검사 데이터 JSON');
});

View File

@@ -8,6 +8,10 @@
{
public function up(): void
{
if (Schema::hasColumn('expense_accounts', 'journal_entry_id')) {
return;
}
Schema::table('expense_accounts', function (Blueprint $table) {
$table->unsignedBigInteger('journal_entry_id')->nullable()->after('loan_id');
$table->unsignedBigInteger('journal_entry_line_id')->nullable()->after('journal_entry_id');

View File

@@ -8,6 +8,10 @@
{
public function up(): void
{
if (Schema::hasColumn('document_template_sections', 'description')) {
return;
}
Schema::table('document_template_sections', function (Blueprint $table) {
$table->text('description')->nullable()->after('title')->comment('섹션 설명/안내문');
});

View File

@@ -17,6 +17,10 @@
*/
public function up(): void
{
if (Schema::hasColumn('account_codes', 'sub_category')) {
return;
}
Schema::table('account_codes', function (Blueprint $table) {
$table->string('sub_category', 50)->nullable()->after('category')
->comment('중분류 (current_asset, fixed_asset, selling_admin, cogs 등)');

View File

@@ -8,6 +8,10 @@
{
public function up(): void
{
if (Schema::hasColumn('quality_document_locations', 'options')) {
return;
}
Schema::table('quality_document_locations', function (Blueprint $table) {
$table->json('options')->nullable()->after('inspection_status')->comment('QMS 심사 확인 등 추가 데이터');
});

View File

@@ -9,6 +9,10 @@
public function up(): void
{
// 1) 심사 점검표 마스터
if (Schema::hasTable('audit_checklists')) {
return;
}
Schema::create('audit_checklists', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('tenant_id')->comment('테넌트ID');

View File

@@ -15,6 +15,10 @@ public function up(): void
$tables = ['document_data', 'document_approvals', 'document_attachments'];
foreach ($tables as $table) {
if (Schema::hasColumn($table, 'tenant_id')) {
continue;
}
Schema::table($table, function (Blueprint $table) {
$table->unsignedBigInteger('tenant_id')->nullable()->after('id')->comment('테넌트 ID');
$table->index('tenant_id');

View File

@@ -8,6 +8,10 @@
{
public function up(): void
{
if (Schema::hasColumn('receivings', 'certificate_file_id')) {
return;
}
Schema::table('receivings', function (Blueprint $table) {
$table->unsignedBigInteger('certificate_file_id')
->nullable()

View File

@@ -9,6 +9,10 @@
{
public function up(): void
{
if (Schema::hasTable('checklist_templates')) {
return;
}
Schema::create('checklist_templates', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('tenant_id')->comment('테넌트ID');

View File

@@ -11,6 +11,10 @@
*/
public function up(): void
{
if (! Schema::hasTable('files') || ! Schema::hasColumn('files', 'mime_type')) {
return;
}
Schema::table('files', function (Blueprint $table) {
$table->string('mime_type', 150)->change();
});

View File

@@ -9,6 +9,10 @@
{
public function up(): void
{
if (Schema::hasColumn('document_template_sections', 'file_id')) {
return;
}
Schema::table('document_template_sections', function (Blueprint $table) {
$table->unsignedBigInteger('file_id')->nullable()->after('image_path')
->comment('도해 이미지 파일 ID (files 테이블 참조)');