Add native amount column

This commit is contained in:
James Cole
2024-12-19 06:21:17 +01:00
parent 380029ffd8
commit 577d671a0c

View File

@@ -0,0 +1,50 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
private array $tables = [
'accounts' => ['native_virtual_balance'],
'account_piggy_bank' => ['native_current_amount'],
'auto_budgets' => ['native_amount'],
'available_budgets' => ['native_amount'],
'bills' => ['native_amount_min', 'native_amount_max'],
'budget_limits' => ['native_amount'],
'piggy_bank_events' => ['native_amount'],
'piggy_banks' => ['native_target_amount'],
'transactions' => ['native_amount'],
];
/**
* Run the migrations.
*/
public function up(): void
{
foreach ($this->tables as $table => $fields) {
foreach ($fields as $field) {
Schema::table($table, static function (Blueprint $table) use ($field): void {
// add amount column
$table->decimal($field, 32, 12)->nullable();
});
}
}
}
/**
* Reverse the migrations.
*/
public function down(): void
{
foreach ($this->tables as $table => $fields) {
foreach ($fields as $field) {
Schema::table($table, static function (Blueprint $table) use ($field): void {
// add amount column
$table->dropColumn($field);
});
}
}
}
};