Skip to content

Firefly III: a personal finances manager

Add native amount column

James Cole577d671a0cef
diff --git a/database/migrations/2024_12_19_061003_add_native_amount_column.php b/database/migrations/2024_12_19_061003_add_native_amount_column.php
new file mode 100644
index 0000000000..33973d07a6
--- /dev/null
+++ b/database/migrations/2024_12_19_061003_add_native_amount_column.php
@@ -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);
+ });
+ }
+ }
+ }
+};