From 595ab89390b967b862119e0045a6bec7600fe8ff Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Thu, 10 Jul 2025 09:00:19 +0700 Subject: [PATCH] feat(database): tambah field alamat dan referensi lokal ke tabel customers Menambahkan migration untuk field tambahan pada tabel customers: - Menambahkan field home_rt dan home_rw untuk RT/RW alamat rumah - Menambahkan field ktp_rt dan ktp_rw untuk RT/RW alamat KTP - Menambahkan field local_ref dengan tipe TEXT untuk referensi lokal panjang - Semua field dibuat nullable untuk fleksibilitas data - Menambahkan index untuk kombinasi RT/RW untuk performa query - Menambahkan comment pada setiap field untuk dokumentasi - Menyediakan method down() lengkap untuk rollback migration - Menggunakan tipe data yang sesuai untuk setiap field --- app/Models/Customer.php | 8 ++- ...dd_additional_field_to_customers_table.php | 61 +++++++++++++++++++ 2 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 database/migrations/2025_07_10_015051_add_additional_field_to_customers_table.php diff --git a/app/Models/Customer.php b/app/Models/Customer.php index 67e8dec..a7726d7 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -24,9 +24,13 @@ class Customer extends Model 'email', 'sector', 'customer_type', - 'birth_incorp_date' + 'birth_incorp_date', + 'home_rt', + 'home_rw', + 'ktp_rt', + 'ktp_rw', + 'local_ref' ]; - public function accounts(){ return $this->hasMany(Account::class, 'customer_code', 'customer_code'); } diff --git a/database/migrations/2025_07_10_015051_add_additional_field_to_customers_table.php b/database/migrations/2025_07_10_015051_add_additional_field_to_customers_table.php new file mode 100644 index 0000000..eb18e06 --- /dev/null +++ b/database/migrations/2025_07_10_015051_add_additional_field_to_customers_table.php @@ -0,0 +1,61 @@ +string('home_rt', 10)->nullable()->comment('RT alamat rumah'); + $table->string('home_rw', 10)->nullable()->comment('RW alamat rumah'); + + // Field RT dan RW untuk alamat KTP + $table->string('ktp_rt', 10)->nullable()->comment('RT alamat KTP'); + $table->string('ktp_rw', 10)->nullable()->comment('RW alamat KTP'); + + // Field untuk referensi lokal dengan tipe data TEXT untuk menampung data panjang + $table->text('local_ref')->nullable()->comment('Referensi lokal dengan data panjang'); + + // Menambahkan index untuk performa query jika diperlukan + $table->index(['home_rt', 'home_rw'], 'idx_customers_home_rt_rw'); + $table->index(['ktp_rt', 'ktp_rw'], 'idx_customers_ktp_rt_rw'); + }); + } + + /** + * Reverse the migrations. + * + * Menghapus field yang ditambahkan jika migration di-rollback + */ + public function down(): void + { + Schema::table('customers', function (Blueprint $table) { + // Hapus index terlebih dahulu + $table->dropIndex('idx_customers_home_rt_rw'); + $table->dropIndex('idx_customers_ktp_rt_rw'); + + // Hapus kolom yang ditambahkan + $table->dropColumn([ + 'home_rt', + 'home_rw', + 'ktp_rt', + 'ktp_rw', + 'local_ref' + ]); + }); + } +}; \ No newline at end of file