From 3b3a1da5c36b6f822d7bbabc9d9be75c5cc8c8c0 Mon Sep 17 00:00:00 2001 From: eko54r Date: Tue, 5 May 2026 17:18:42 +0700 Subject: [PATCH] update migration --- ...25_05_13_102231_create_employees_table.php | 38 ++++++++++--------- ..._05_13_152009_create_leave_types_table.php | 18 +++++---- .../2025_05_14_090651_create_leaves_table.php | 30 ++++++++------- ...025_05_14_124928_create_holidays_table.php | 20 +++++----- ..._05_14_162716_create_attendances_table.php | 28 +++++++------- ...025_05_15_105035_create_payrolls_table.php | 28 +++++++------- ...05036_add_new_fields_to_multiple_table.php | 8 ++-- 7 files changed, 92 insertions(+), 78 deletions(-) diff --git a/Modules/HrmAddon/Database/migrations/2025_05_13_102231_create_employees_table.php b/Modules/HrmAddon/Database/migrations/2025_05_13_102231_create_employees_table.php index d4332cac..96195b76 100644 --- a/Modules/HrmAddon/Database/migrations/2025_05_13_102231_create_employees_table.php +++ b/Modules/HrmAddon/Database/migrations/2025_05_13_102231_create_employees_table.php @@ -11,24 +11,26 @@ */ public function up(): void { - Schema::create('employees', function (Blueprint $table) { - $table->id(); - $table->string('name'); - $table->foreignId('business_id')->constrained()->cascadeOnDelete(); - $table->foreignId('designation_id')->nullable()->constrained()->nullOnDelete(); - $table->foreignId('department_id')->nullable()->constrained()->nullOnDelete(); - $table->foreignId('shift_id')->nullable()->constrained()->nullOnDelete(); - $table->double('amount', 10, 2)->default(0); - $table->string('image')->nullable(); - $table->string('phone'); - $table->string('email')->nullable(); - $table->string('gender'); - $table->string('country')->nullable(); - $table->date('birth_date')->nullable(); - $table->date('join_date')->nullable(); - $table->string('status')->default('active'); // active || terminated || suspended - $table->timestamps(); - }); + if (!Schema::hasTable('employees')) { + Schema::create('employees', function (Blueprint $table) { + $table->id(); + $table->string('name'); + $table->foreignId('business_id')->constrained()->cascadeOnDelete(); + $table->foreignId('designation_id')->nullable()->constrained()->nullOnDelete(); + $table->foreignId('department_id')->nullable()->constrained()->nullOnDelete(); + $table->foreignId('shift_id')->nullable()->constrained()->nullOnDelete(); + $table->double('amount', 10, 2)->default(0); + $table->string('image')->nullable(); + $table->string('phone'); + $table->string('email')->nullable(); + $table->string('gender'); + $table->string('country')->nullable(); + $table->date('birth_date')->nullable(); + $table->date('join_date')->nullable(); + $table->string('status')->default('active'); // active || terminated || suspended + $table->timestamps(); + }); + } } /** diff --git a/Modules/HrmAddon/Database/migrations/2025_05_13_152009_create_leave_types_table.php b/Modules/HrmAddon/Database/migrations/2025_05_13_152009_create_leave_types_table.php index 0e3df1c1..145728de 100644 --- a/Modules/HrmAddon/Database/migrations/2025_05_13_152009_create_leave_types_table.php +++ b/Modules/HrmAddon/Database/migrations/2025_05_13_152009_create_leave_types_table.php @@ -11,14 +11,16 @@ */ public function up(): void { - Schema::create('leave_types', function (Blueprint $table) { - $table->id(); - $table->foreignId('business_id')->constrained()->cascadeOnDelete(); - $table->string('name'); - $table->text('description')->nullable(); - $table->boolean('status')->default(1); - $table->timestamps(); - }); + if (!Schema::hasTable('leave_types')) { + Schema::create('leave_types', function (Blueprint $table) { + $table->id(); + $table->foreignId('business_id')->constrained()->cascadeOnDelete(); + $table->string('name'); + $table->text('description')->nullable(); + $table->boolean('status')->default(1); + $table->timestamps(); + }); + } } /** diff --git a/Modules/HrmAddon/Database/migrations/2025_05_14_090651_create_leaves_table.php b/Modules/HrmAddon/Database/migrations/2025_05_14_090651_create_leaves_table.php index 380b9d77..cfb12518 100644 --- a/Modules/HrmAddon/Database/migrations/2025_05_14_090651_create_leaves_table.php +++ b/Modules/HrmAddon/Database/migrations/2025_05_14_090651_create_leaves_table.php @@ -11,20 +11,22 @@ */ public function up(): void { - Schema::create('leaves', function (Blueprint $table) { - $table->id(); - $table->foreignId('business_id')->constrained()->cascadeOnDelete(); - $table->foreignId('employee_id')->constrained()->cascadeOnDelete(); - $table->foreignId('leave_type_id')->nullable()->constrained()->nullOnDelete(); - $table->foreignId('department_id')->nullable()->constrained()->nullOnDelete(); - $table->date('start_date'); - $table->date('end_date'); - $table->double('leave_duration'); - $table->string('month'); - $table->string('status')->default('pending'); // rejected, pending, approved - $table->text('description')->nullable(); - $table->timestamps(); - }); + if (!Schema::hasTable('leaves')) { + Schema::create('leaves', function (Blueprint $table) { + $table->id(); + $table->foreignId('business_id')->constrained()->cascadeOnDelete(); + $table->foreignId('employee_id')->constrained()->cascadeOnDelete(); + $table->foreignId('leave_type_id')->nullable()->constrained()->nullOnDelete(); + $table->foreignId('department_id')->nullable()->constrained()->nullOnDelete(); + $table->date('start_date'); + $table->date('end_date'); + $table->double('leave_duration'); + $table->string('month'); + $table->string('status')->default('pending'); // rejected, pending, approved + $table->text('description')->nullable(); + $table->timestamps(); + }); + } } /** diff --git a/Modules/HrmAddon/Database/migrations/2025_05_14_124928_create_holidays_table.php b/Modules/HrmAddon/Database/migrations/2025_05_14_124928_create_holidays_table.php index 4e45533c..340d620c 100644 --- a/Modules/HrmAddon/Database/migrations/2025_05_14_124928_create_holidays_table.php +++ b/Modules/HrmAddon/Database/migrations/2025_05_14_124928_create_holidays_table.php @@ -11,15 +11,17 @@ */ public function up(): void { - Schema::create('holidays', function (Blueprint $table) { - $table->id(); - $table->foreignId('business_id')->constrained()->cascadeOnDelete(); - $table->string('name'); - $table->date('start_date'); - $table->date('end_date'); - $table->text('description')->nullable(); - $table->timestamps(); - }); + if (!Schema::hasTable('holidays')) { + Schema::create('holidays', function (Blueprint $table) { + $table->id(); + $table->foreignId('business_id')->constrained()->cascadeOnDelete(); + $table->string('name'); + $table->date('start_date'); + $table->date('end_date'); + $table->text('description')->nullable(); + $table->timestamps(); + }); + } } /** diff --git a/Modules/HrmAddon/Database/migrations/2025_05_14_162716_create_attendances_table.php b/Modules/HrmAddon/Database/migrations/2025_05_14_162716_create_attendances_table.php index f5db1d5f..b58179cb 100644 --- a/Modules/HrmAddon/Database/migrations/2025_05_14_162716_create_attendances_table.php +++ b/Modules/HrmAddon/Database/migrations/2025_05_14_162716_create_attendances_table.php @@ -11,19 +11,21 @@ */ public function up(): void { - Schema::create('attendances', function (Blueprint $table) { - $table->id(); - $table->foreignId('business_id')->constrained()->cascadeOnDelete(); - $table->foreignId('employee_id')->constrained()->cascadeOnDelete(); - $table->foreignId('shift_id')->nullable()->constrained()->nullOnDelete(); - $table->time('time_in'); - $table->time('time_out'); - $table->date('date'); - $table->time('duration'); - $table->string('month'); - $table->longText('note')->nullable(); - $table->timestamps(); - }); + if (!Schema::hasTable('attendances')) { + Schema::create('attendances', function (Blueprint $table) { + $table->id(); + $table->foreignId('business_id')->constrained()->cascadeOnDelete(); + $table->foreignId('employee_id')->constrained()->cascadeOnDelete(); + $table->foreignId('shift_id')->nullable()->constrained()->nullOnDelete(); + $table->time('time_in'); + $table->time('time_out'); + $table->date('date'); + $table->time('duration'); + $table->string('month'); + $table->longText('note')->nullable(); + $table->timestamps(); + }); + } } /** diff --git a/Modules/HrmAddon/Database/migrations/2025_05_15_105035_create_payrolls_table.php b/Modules/HrmAddon/Database/migrations/2025_05_15_105035_create_payrolls_table.php index 52ec5cb9..af18e29c 100644 --- a/Modules/HrmAddon/Database/migrations/2025_05_15_105035_create_payrolls_table.php +++ b/Modules/HrmAddon/Database/migrations/2025_05_15_105035_create_payrolls_table.php @@ -11,19 +11,21 @@ */ public function up(): void { - Schema::create('payrolls', function (Blueprint $table) { - $table->id(); - $table->foreignId('business_id')->constrained()->cascadeOnDelete(); - $table->foreignId('employee_id')->constrained()->cascadeOnDelete(); - $table->foreignId('payment_type_id')->nullable()->constrained()->nullOnDelete(); - $table->string('month'); - $table->string('puid'); - $table->date('date')->nullable(); - $table->double('amount', 10, 2); - $table->string('payemnt_year'); - $table->longText('note')->nullable(); - $table->timestamps(); - }); + if (!Schema::hasTable('payrolls')) { + Schema::create('payrolls', function (Blueprint $table) { + $table->id(); + $table->foreignId('business_id')->constrained()->cascadeOnDelete(); + $table->foreignId('employee_id')->constrained()->cascadeOnDelete(); + $table->foreignId('payment_type_id')->nullable()->constrained()->nullOnDelete(); + $table->string('month'); + $table->string('puid'); + $table->date('date')->nullable(); + $table->double('amount', 10, 2); + $table->string('payemnt_year'); + $table->longText('note')->nullable(); + $table->timestamps(); + }); + } } /** diff --git a/Modules/HrmAddon/Database/migrations/2025_08_19_105036_add_new_fields_to_multiple_table.php b/Modules/HrmAddon/Database/migrations/2025_08_19_105036_add_new_fields_to_multiple_table.php index 79f8121c..80bb5526 100644 --- a/Modules/HrmAddon/Database/migrations/2025_08_19_105036_add_new_fields_to_multiple_table.php +++ b/Modules/HrmAddon/Database/migrations/2025_08_19_105036_add_new_fields_to_multiple_table.php @@ -12,9 +12,11 @@ public function up(): void { // HOLIDAYS, ATTENDANCES, LEAVES, PAYROLLS, employees foreach (['holidays', 'attendances', 'leaves', 'payrolls', 'employees'] as $tableName) { - Schema::table($tableName, function (Blueprint $table) { - $table->foreignId('branch_id')->nullable()->after('business_id')->constrained('branches')->nullOnDelete(); - }); + if (!Schema::hasColumn($tableName, 'branch_id')) { + Schema::table($tableName, function (Blueprint $table) { + $table->foreignId('branch_id')->nullable()->after('business_id')->constrained('branches')->nullOnDelete(); + }); + } } }