From 562cc948229189ef39b44e88e46787d94ecc5890 Mon Sep 17 00:00:00 2001 From: daengdeni Date: Sat, 24 May 2025 17:04:31 +0700 Subject: [PATCH] refactor(database): ubah tipe kolom dari date/datetime/decimal menjadi string di berbagai tabel Ubah tipe kolom di database yang sebelumnya menggunakan date, datetime, atau decimal menjadi string. Langkah ini meningkatkan fleksibilitas penyimpanan data. - `customers` table: - Ubah tipe kolom `date_of_birth` dari `date` menjadi `string`. - `accounts` table: - Ubah tipe kolom `opening_date` dari `date` menjadi `string`. - Ubah tipe kolom `closure_date` dari `date` menjadi `string`. - Revisi kolom `start_year_bal` menjadi `string` dengan parameter yang disesuaikan. - `ft_txn_type_condition` table: - Ubah tipe kolom `date_time` dari `dateTime` menjadi `string`. - `data_captures` table: - Ubah tipe kolom `value_date`, `exposure_date`, dan `accounting_date` dari `date` menjadi `string`. - Ubah tipe kolom `date_time` dari `dateTime` menjadi `string`. - Ubah tipe kolom `amount_lcy`, `amount_fcy`, dan `exchange_rate` dari `decimal` menjadi `string`. - `temp_arrangements` table: - Ubah tipe kolom `orig_contract_date` dan `start_date` dari `date` menjadi `string`. - Model changes: - Hapus properti `casts` dari model berikut: - `AtmTransaction` - `DataCapture` - `FtTxnTypeCondition` --- app/Models/AtmTransaction.php | 12 ----- app/Models/DataCapture.php | 10 ----- app/Models/FtTxnTypeCondition.php | 9 ---- ..._of_birth_to_string_in_customers_table.php | 32 +++++++++++++ ...ate_fileds_to_string_in_accounts_table.php | 45 +++++++++++++++++++ ...date_time_fileds_to_string_in_fx_table.php | 32 +++++++++++++ ...ileds_to_string_in_data_captures_table.php | 42 +++++++++++++++++ ...ileds_to_string_in_data_captures_table.php | 36 +++++++++++++++ ...s_to_string_in_temp_arrangements_table.php | 34 ++++++++++++++ 9 files changed, 221 insertions(+), 31 deletions(-) create mode 100644 database/migrations/2025_05_24_162629_change_date_of_birth_to_string_in_customers_table.php create mode 100644 database/migrations/2025_05_24_162736_change_date_fileds_to_string_in_accounts_table.php create mode 100644 database/migrations/2025_05_24_163509_change_date_time_fileds_to_string_in_fx_table.php create mode 100644 database/migrations/2025_05_24_163625_change_date_time_fileds_to_string_in_data_captures_table.php create mode 100644 database/migrations/2025_05_24_164036_change_decimal_fileds_to_string_in_data_captures_table.php create mode 100644 database/migrations/2025_05_24_165711_change_date_fields_to_string_in_temp_arrangements_table.php diff --git a/app/Models/AtmTransaction.php b/app/Models/AtmTransaction.php index 312eb55..50aa193 100644 --- a/app/Models/AtmTransaction.php +++ b/app/Models/AtmTransaction.php @@ -30,16 +30,4 @@ 'trans_status', 'proc_code', ]; - - /** - * The attributes that should be cast. - * - * @var array - */ - protected $casts = [ - 'booking_date' => 'datetime', - 'value_date' => 'datetime', - 'txn_amount' => 'decimal:2', - 'chrg_amount' => 'decimal:2', - ]; } diff --git a/app/Models/DataCapture.php b/app/Models/DataCapture.php index 654890a..8ac6e36 100644 --- a/app/Models/DataCapture.php +++ b/app/Models/DataCapture.php @@ -61,14 +61,4 @@ 'co_code', 'date_time' ]; - - protected $casts = [ - 'amount_lcy' => 'decimal:2', - 'amount_fcy' => 'decimal:2', - 'exchange_rate' => 'decimal:6', - 'value_date' => 'date', - 'exposure_date' => 'date', - 'accounting_date' => 'date', - 'date_time' => 'datetime' - ]; } diff --git a/app/Models/FtTxnTypeCondition.php b/app/Models/FtTxnTypeCondition.php index 9dd7d2c..ea3c988 100644 --- a/app/Models/FtTxnTypeCondition.php +++ b/app/Models/FtTxnTypeCondition.php @@ -49,13 +49,4 @@ 'txn_code_cr', 'txn_code_dr', ]; - - /** - * The attributes that should be cast. - * - * @var array - */ - protected $casts = [ - 'date_time' => 'datetime', - ]; } diff --git a/database/migrations/2025_05_24_162629_change_date_of_birth_to_string_in_customers_table.php b/database/migrations/2025_05_24_162629_change_date_of_birth_to_string_in_customers_table.php new file mode 100644 index 0000000..b674212 --- /dev/null +++ b/database/migrations/2025_05_24_162629_change_date_of_birth_to_string_in_customers_table.php @@ -0,0 +1,32 @@ +string('date_of_birth')->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + * Change date_of_birth column back to date type + */ + public function down(): void + { + Schema::table('customers', function (Blueprint $table) { + // Convert back to date type + $table->date('date_of_birth')->nullable()->change(); + }); + } + }; diff --git a/database/migrations/2025_05_24_162736_change_date_fileds_to_string_in_accounts_table.php b/database/migrations/2025_05_24_162736_change_date_fileds_to_string_in_accounts_table.php new file mode 100644 index 0000000..d4b5c6a --- /dev/null +++ b/database/migrations/2025_05_24_162736_change_date_fileds_to_string_in_accounts_table.php @@ -0,0 +1,45 @@ +string('opening_date')->nullable()->change(); + + // Change closure_date from date to string + $table->string('closure_date')->nullable()->change(); + + // Fix the start_year_bal column which has incorrect parameters + // First drop the column + $table->string('start_year_bal',255)->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + * Change string fields back to date type + */ + public function down(): void + { + Schema::table('accounts', function (Blueprint $table) { + // Change opening_date back to date + $table->date('opening_date')->nullable()->change(); + + // Change closure_date back to date + $table->date('closure_date')->nullable()->change(); + + // Drop and recreate start_year_bal with original definition + $table->string('start_year_bal',15)->nullable()->change(); + }); + } + }; diff --git a/database/migrations/2025_05_24_163509_change_date_time_fileds_to_string_in_fx_table.php b/database/migrations/2025_05_24_163509_change_date_time_fileds_to_string_in_fx_table.php new file mode 100644 index 0000000..481ce90 --- /dev/null +++ b/database/migrations/2025_05_24_163509_change_date_time_fileds_to_string_in_fx_table.php @@ -0,0 +1,32 @@ +string('date_time')->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + * Change date_time column back to dateTime type + */ + public function down(): void + { + Schema::table('ft_txn_type_condition', function (Blueprint $table) { + // Change date_time back to dateTime + $table->dateTime('date_time')->nullable()->change(); + }); + } + }; diff --git a/database/migrations/2025_05_24_163625_change_date_time_fileds_to_string_in_data_captures_table.php b/database/migrations/2025_05_24_163625_change_date_time_fileds_to_string_in_data_captures_table.php new file mode 100644 index 0000000..7580810 --- /dev/null +++ b/database/migrations/2025_05_24_163625_change_date_time_fileds_to_string_in_data_captures_table.php @@ -0,0 +1,42 @@ +string('value_date')->nullable()->change(); + $table->string('exposure_date')->nullable()->change(); + $table->string('accounting_date')->nullable()->change(); + + // Change dateTime field to string + $table->string('date_time')->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + * Change string fields back to date and dateTime types + */ + public function down(): void + { + Schema::table('data_captures', function (Blueprint $table) { + // Change string fields back to date + $table->date('value_date')->nullable()->change(); + $table->date('exposure_date')->nullable()->change(); + $table->date('accounting_date')->nullable()->change(); + + // Change string field back to dateTime + $table->dateTime('date_time')->nullable()->change(); + }); + } + }; diff --git a/database/migrations/2025_05_24_164036_change_decimal_fileds_to_string_in_data_captures_table.php b/database/migrations/2025_05_24_164036_change_decimal_fileds_to_string_in_data_captures_table.php new file mode 100644 index 0000000..9081ae8 --- /dev/null +++ b/database/migrations/2025_05_24_164036_change_decimal_fileds_to_string_in_data_captures_table.php @@ -0,0 +1,36 @@ +string('amount_lcy')->nullable()->change(); + $table->string('amount_fcy')->nullable()->change(); + $table->string('exchange_rate')->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + * Change string fields back to decimal types + */ + public function down(): void + { + Schema::table('data_captures', function (Blueprint $table) { + // Change string fields back to decimal with original precision and scale + $table->decimal('amount_lcy', 20, 2)->nullable()->change(); + $table->decimal('amount_fcy', 20, 2)->nullable()->change(); + $table->decimal('exchange_rate', 20, 6)->nullable()->change(); + }); + } + }; diff --git a/database/migrations/2025_05_24_165711_change_date_fields_to_string_in_temp_arrangements_table.php b/database/migrations/2025_05_24_165711_change_date_fields_to_string_in_temp_arrangements_table.php new file mode 100644 index 0000000..29a56b0 --- /dev/null +++ b/database/migrations/2025_05_24_165711_change_date_fields_to_string_in_temp_arrangements_table.php @@ -0,0 +1,34 @@ +string('orig_contract_date')->nullable()->change(); + $table->string('start_date')->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + * Change string fields back to date type + */ + public function down(): void + { + Schema::table('temp_arrangements', function (Blueprint $table) { + // Change string fields back to date + $table->date('orig_contract_date')->nullable()->change(); + $table->date('start_date')->nullable()->change(); + }); + } + };