This commit is contained in:
@@ -6,23 +6,33 @@ use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('attachment_form', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->unsignedBigInteger('form_id');
|
||||
$table->string('table_name', 100)->comment('nama tabel form yang direferensikan');
|
||||
$table->string('file_category', 100)->nullable();
|
||||
$table->string('file_path', 255);
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
// Pengecekan agar tidak error jika tabel sudah ada di database
|
||||
if (!Schema::hasTable('attachment_form')) {
|
||||
Schema::create('attachment_form', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->unsignedBigInteger('form_id');
|
||||
$table->string('table_name', 100)->comment('nama tabel form yang direferensikan');
|
||||
$table->string('file_category', 100)->nullable();
|
||||
$table->string('file_path', 255);
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
$table->index(['form_id', 'table_name'], 'idx_form_table');
|
||||
});
|
||||
// Menambahkan index untuk performa query
|
||||
$table->index(['form_id', 'table_name'], 'idx_form_table');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('attachment_form');
|
||||
}
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
<?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::table('budget_control', function (Blueprint $table) {
|
||||
// CEK: Hanya tambah kolom jika belum ada di database
|
||||
if (!Schema::hasColumn('budget_control', 'region_id')) {
|
||||
$table->unsignedBigInteger('region_id')->nullable()->after('cabang_id');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('budget_control', function (Blueprint $table) {
|
||||
if (Schema::hasColumn('budget_control', 'region_id')) {
|
||||
$table->dropColumn('region_id');
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('budget_control', function (Blueprint $table) {
|
||||
// Menambahkan kolom bukti transfer (berisi path file)
|
||||
$table->string('transfer_proof')->after('remarks')->nullable();
|
||||
|
||||
// Menambahkan status transfer untuk approval Accounting
|
||||
$table->enum('transfer_status', ['Pending', 'Approved', 'Rejected'])
|
||||
->default('Pending')
|
||||
->after('transfer_proof');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('budget_control', function (Blueprint $table) {
|
||||
// Menghapus kolom jika migration di-rollback
|
||||
$table->dropColumn(['transfer_proof', 'transfer_status']);
|
||||
});
|
||||
}
|
||||
};
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
// TAHAP 1: Ubah kolom menjadi string (VARCHAR) agar bisa menerima teks apapun
|
||||
Schema::table('budget_control', function (Blueprint $table) {
|
||||
$table->string('transfer_status')->change();
|
||||
});
|
||||
|
||||
// TAHAP 2: Update data lama ke status baru
|
||||
// Kita tangani semua kemungkinan data agar tidak ada yang 'nyangkut'
|
||||
DB::table('budget_control')
|
||||
->where('transfer_status', 'Approved')
|
||||
->update(['transfer_status' => 'Validated']);
|
||||
|
||||
// Opsional: Jika ada data kosong/null, amankan ke 'Pending'
|
||||
DB::table('budget_control')
|
||||
->whereNull('transfer_status')
|
||||
->orWhere('transfer_status', '')
|
||||
->update(['transfer_status' => 'Pending']);
|
||||
|
||||
// TAHAP 3: Kembalikan kolom ke ENUM dengan definisi baru
|
||||
Schema::table('budget_control', function (Blueprint $table) {
|
||||
$table->enum('transfer_status', ['Pending', 'Waiting Approval', 'Validated', 'Rejected'])
|
||||
->default('Pending')
|
||||
->change();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
// Rollback: Kembalikan ke definisi awal jika diperlukan
|
||||
Schema::table('budget_control', function (Blueprint $table) {
|
||||
$table->enum('transfer_status', ['Pending', 'Approved', 'Rejected'])
|
||||
->default('Pending')
|
||||
->change();
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
// FK ke tabel region dan cabang
|
||||
$table->foreignId('region_id')->after('password')->nullable()->constrained('region');
|
||||
$table->foreignId('cabang_id')->after('region_id')->nullable()->constrained('cabang');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
//
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,93 @@
|
||||
<?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. Jika tabel belum ada sama sekali, buat baru dengan struktur lengkap
|
||||
if (!Schema::hasTable('transactions')) {
|
||||
Schema::create('transactions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('cabang_id')->constrained('cabang')->onDelete('cascade');
|
||||
$table->foreignId('budget_control_id')->nullable()->constrained('budget_control')->onDelete('set null');
|
||||
$table->date('transaction_date');
|
||||
$table->string('reference_number')->unique();
|
||||
$table->string('description');
|
||||
$table->decimal('amount', 15, 2);
|
||||
$table->enum('type', ['DEBIT', 'CREDIT']);
|
||||
$table->string('category')->default('General');
|
||||
$table->string('periode_month');
|
||||
$table->year('periode_year');
|
||||
$table->foreignId('created_by')->constrained('admins');
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. JIKA TABEL SUDAH EXIST: Tambahkan kolom baru tanpa merusak / menimpa kolom cabang_id yang sudah ada
|
||||
Schema::table('transactions', function (Blueprint $table) {
|
||||
|
||||
// Pastikan cabang_id tidak dibuat ulang, kita hanya memastikan tipenya aman jika belum ada
|
||||
if (!Schema::hasColumn('transactions', 'cabang_id')) {
|
||||
$table->foreignId('cabang_id')->constrained('cabang')->onDelete('cascade');
|
||||
}
|
||||
|
||||
// Tambahkan kolom pendukung lainnya secara aman jika belum eksis di database
|
||||
if (!Schema::hasColumn('transactions', 'budget_control_id')) {
|
||||
$table->foreignId('budget_control_id')->nullable()->after('cabang_id')->constrained('budget_control')->onDelete('set null');
|
||||
}
|
||||
|
||||
if (!Schema::hasColumn('transactions', 'transaction_date')) {
|
||||
$table->date('transaction_date')->nullable()->after('budget_control_id');
|
||||
}
|
||||
|
||||
if (!Schema::hasColumn('transactions', 'reference_number')) {
|
||||
$table->string('reference_number')->nullable()->after('transaction_date');
|
||||
}
|
||||
|
||||
if (!Schema::hasColumn('transactions', 'description')) {
|
||||
$table->string('description')->nullable()->after('reference_number');
|
||||
}
|
||||
|
||||
if (!Schema::hasColumn('transactions', 'amount')) {
|
||||
$table->decimal('amount', 15, 2)->default(0)->after('description');
|
||||
}
|
||||
|
||||
if (!Schema::hasColumn('transactions', 'type')) {
|
||||
$table->enum('type', ['DEBIT', 'CREDIT'])->default('CREDIT')->after('amount');
|
||||
}
|
||||
|
||||
if (!Schema::hasColumn('transactions', 'category')) {
|
||||
$table->string('category')->default('General')->after('type');
|
||||
}
|
||||
|
||||
if (!Schema::hasColumn('transactions', 'periode_month')) {
|
||||
$table->string('periode_month')->nullable()->after('category');
|
||||
}
|
||||
|
||||
if (!Schema::hasColumn('transactions', 'periode_year')) {
|
||||
$table->year('periode_year')->nullable()->after('periode_month');
|
||||
}
|
||||
|
||||
if (!Schema::hasColumn('transactions', 'created_by')) {
|
||||
// Buat nullable dulu agar baris data lama yang sudah exist tidak error saat migrasi berjalan
|
||||
$table->foreignId('created_by')->nullable()->after('periode_year')->constrained('admins');
|
||||
}
|
||||
|
||||
if (!Schema::hasColumn('transactions', 'deleted_at')) {
|
||||
$table->softDeletes();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
// Opsional: Hanya drop jika Anda benar-benar sedang di fase development murni
|
||||
// Schema::dropIfExists('transactions');
|
||||
}
|
||||
};
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('form_entertainment_presentation', function (Blueprint $table) {
|
||||
$table->string('jabatan')->nullable()->after('status');
|
||||
$table->string('nama_perusahaan')->nullable()->after('jabatan');
|
||||
$table->string('jenis_usaha')->nullable()->after('nama_perusahaan');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('form_entertainment_presentation', function (Blueprint $table) {
|
||||
$table->dropColumn(['jabatan', 'nama_perusahaan', 'jenis_usaha']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
protected $tables = [
|
||||
'form_up_country',
|
||||
'form_vehicle_running_cost',
|
||||
'form_entertainment_presentation',
|
||||
'form_meeting_seminar',
|
||||
'form_others'
|
||||
];
|
||||
|
||||
public function up(): void
|
||||
{
|
||||
foreach ($this->tables as $table) {
|
||||
if (Schema::hasTable($table) && !Schema::hasColumn($table, 'rejected_by')) {
|
||||
Schema::table($table, function (Blueprint $table) {
|
||||
// Menambahkan kolom rejected_by sebagai foreign key ke tabel admins
|
||||
$table->unsignedBigInteger('rejected_by')->nullable()->after('status');
|
||||
$table->timestamp('rejected_at')->nullable()->after('rejected_by');
|
||||
|
||||
$table->foreign('rejected_by')->references('id')->on('admins')->onDelete('set null');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
foreach ($this->tables as $table) {
|
||||
if (Schema::hasColumn($table, 'rejected_by')) {
|
||||
Schema::table($table, function (Blueprint $table) {
|
||||
$table->dropForeign([$table . '_rejected_by_foreign']);
|
||||
$table->dropColumn(['rejected_by', 'rejected_at']);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
protected $tables = [
|
||||
'form_up_country',
|
||||
'form_vehicle_running_cost',
|
||||
'form_entertainment_presentation',
|
||||
'form_meeting_seminar'
|
||||
];
|
||||
|
||||
public function up(): void
|
||||
{
|
||||
foreach ($this->tables as $table) {
|
||||
if (Schema::hasTable($table) && !Schema::hasColumn($table, 'kategori_id')) {
|
||||
Schema::table($table, function (Blueprint $bp) {
|
||||
// Kita panggil nama tabel asli Anda 'kategori' di dalam fungsi constrained()
|
||||
$bp->foreignId('kategori_id')
|
||||
->nullable()
|
||||
->after('user_id')
|
||||
->constrained('kategori') // <-- PERBAIKAN: Menembak tabel 'kategori'
|
||||
->onDelete('set null');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
foreach ($this->tables as $table) {
|
||||
if (Schema::hasColumn($table, 'kategori_id')) {
|
||||
Schema::table($table, function (Blueprint $bp) use ($table) {
|
||||
$bp->dropForeign($table . '_kategori_id_foreign');
|
||||
$bp->dropColumn('kategori_id');
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user