feat(webstatement): tambah migration dan model ProvinceCore
Perubahan yang dilakukan: - Membuat migration untuk tabel province_core dengan field code dan name. - Menambahkan model ProvinceCore dengan beberapa scope dan method helper. - Mengimplementasikan logging untuk semua operasi database yang berkaitan. - Menambahkan dukungan transaction rollback untuk menjaga integritas data. - Membuat seeder untuk data provinsi seluruh Indonesia. - Menambahkan validasi dan method utility untuk keperluan dropdown. - Menggunakan PostgreSQL ILIKE untuk pencarian yang bersifat case-insensitive. - Menambahkan index pada kolom tertentu untuk optimasi performa query. - Mengimplementasikan event model untuk memantau operasi CRUD. - Menyesuaikan struktur file agar sesuai dengan arsitektur Laravel modules. Tujuan perubahan: - Menyediakan data master provinsi yang dapat digunakan secara global. - Memastikan efisiensi dan keamanan data pada proses insert/update. - Mendukung pengembangan fitur yang membutuhkan referensi data provinsi.
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Menjalankan migrasi untuk membuat tabel province_core
|
||||
* Tabel ini menyimpan data master provinsi dengan kode dan nama
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
Schema::create('province_core', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('code', 10)->unique()->comment('Kode provinsi unik');
|
||||
$table->string('name', 255)->comment('Nama provinsi');
|
||||
$table->timestamps();
|
||||
|
||||
// Index untuk performa pencarian
|
||||
$table->index(['code']);
|
||||
$table->index(['name']);
|
||||
});
|
||||
|
||||
DB::commit();
|
||||
Log::info('Migration province_core table berhasil dibuat');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollback();
|
||||
Log::error('Migration province_core table gagal: ' . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Membalikkan migrasi dengan menghapus tabel province_core
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
Schema::dropIfExists('province_core');
|
||||
|
||||
DB::commit();
|
||||
Log::info('Migration rollback province_core table berhasil');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
DB::rollback();
|
||||
Log::error('Migration rollback province_core table gagal: ' . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user