Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Clean up some migrations.
James Coledc7f5a562bd2
diff --git a/database/migrations/2014_11_10_172053_create_account_meta_table.php b/database/migrations/2014_11_10_172053_create_account_meta_table.phpindex 5ca584d007..698850465d 100644--- a/database/migrations/2014_11_10_172053_create_account_meta_table.php+++ b/database/migrations/2014_11_10_172053_create_account_meta_table.php@@ -19,7 +19,6 @@ class CreateAccountMetaTable extends Migration*/public function down(){- //Schema::drop('account_meta');}diff --git a/database/migrations/2014_12_13_190730_changes_for_v321.php b/database/migrations/2014_12_13_190730_changes_for_v321.phpindex a10d7785ae..d4784673b2 100644--- a/database/migrations/2014_12_13_190730_changes_for_v321.php+++ b/database/migrations/2014_12_13_190730_changes_for_v321.php@@ -87,166 +87,188 @@ class ChangesForV321 extends Migration}- public function moveBudgetsBack()+ /**+ * Run the migrations.+ *+ * @return void+ */+ public function up(){- Budget::get()->each(- function (Budget $budget) {- Component::firstOrCreate(- [- 'name' => $budget->name,- 'user_id' => $budget->user_id,- 'class' => 'Budget'- ]- );- }+ $this->createBudgetTable(); // 1.+ $this->createCategoryTable(); // 2.+ $this->createBudgetJournalTable(); // 3+ $this->createCategoryJournalTable(); // 4.+ $this->moveBudgets(); // 5.+ $this->moveCategories(); // 6.+ $this->correctNameForBudgetLimits(); // 7.+ $this->correctNameForPiggyBankEvents(); // 8.+ $this->renameBudgetToBudgetLimitInRepetitions(); // 9.+ $this->addBudgetIdFieldToBudgetLimits(); // 10.+ $this->moveComponentIdToBudgetId(); // 11.+ $this->dropComponentJournalTable(); // 12.+ $this->dropComponentRecurringTransactionTable(); // 13.+ $this->dropComponentTransactionTable(); // 14.+ $this->dropPiggyBankIdFromTransactions(); // 15.+ $this->dropComponentIdFromBudgetLimits(); // 16.+ $this->expandCurrencyTable(); // 17.++ }++ private function addBudgetIdFieldToBudgetLimits()+ {+ Schema::table(+ 'budget_limits', function (Blueprint $table) {+ $table->integer('budget_id', false, true)->nullable()->after('updated_at');+ $table->foreign('budget_id', 'bid_foreign')->references('id')->on('budgets')->onDelete('cascade');+ });}- public function moveCategoriesBack()+ private function correctNameForBudgetLimits(){- Category::get()->each(- function (Category $category) {- Component::firstOrCreate(- [- 'name' => $category->name,- 'user_id' => $category->user_id,- 'class' => 'Category'- ]- );- }+ Schema::rename('limits', 'budget_limits');+ }++ private function correctNameForPiggyBankEvents()+ {+ Schema::rename('piggybank_events', 'piggy_bank_events');++ }++ private function createBudgetJournalTable()+ {+ Schema::create(+ 'budget_transaction_journal', function (Blueprint $table) {+ $table->increments('id');+ $table->integer('budget_id')->unsigned();+ $table->integer('transaction_journal_id')->unsigned();+ $table->foreign('budget_id')->references('id')->on('budgets')->onDelete('cascade');+ $table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade');+ $table->unique(['budget_id', 'transaction_journal_id'], 'budid_tjid_unique');+ });}- public function createComponentId()+ private function createBudgetTable(){- Schema::table(- 'budget_limits', function (Blueprint $table) {- $table->integer('component_id')->unsigned();+ Schema::create(+ 'budgets', function (Blueprint $table) {+ $table->increments('id');+ $table->timestamps();+ $table->softDeletes();+ $table->string('name', 50);+ $table->integer('user_id')->unsigned();+ $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');+ $table->unique(['user_id', 'name']);});++}- public function updateComponentInBudgetLimits()+ private function createCategoryJournalTable(){- BudgetLimit::get()->each(- function (BudgetLimit $bl) {- $budgetId = $bl->budget_id;- $budget = Budget::find($budgetId);- if ($budget) {- $component = Component::where('class', 'Budget')->where('user_id', $budget->user_id)->where('name', $budget->name)->first();- if ($component) {- $bl->component_id = $component->id;- $bl->save();- }- }- }+ Schema::create(+ 'category_transaction_journal', function (Blueprint $table) {+ $table->increments('id');+ $table->integer('category_id')->unsigned();+ $table->integer('transaction_journal_id')->unsigned();+ $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');+ $table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade');+ $table->unique(['category_id', 'transaction_journal_id'], 'catid_tjid_unique');+ });}- public function createComponentIdForeignKey()+ private function createCategoryTable(){- Schema::table(- 'budget_limits', function (Blueprint $table) {- $table->foreign('component_id', 'limits_component_id_foreign')->references('id')->on('components')->onDelete('cascade');+ Schema::create(+ 'categories', function (Blueprint $table) {+ $table->increments('id');+ $table->timestamps();+ $table->softDeletes();+ $table->string('name', 50);+ $table->integer('user_id')->unsigned();+ $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');+ $table->unique(['user_id', 'name']);});}- public function dropBudgetIdColumnInBudgetLimits()+ private function createComponentId(){Schema::table('budget_limits', function (Blueprint $table) {- $table->dropForeign('bid_foreign');- $table->dropColumn('budget_id'); // also drop foreign key!+ $table->integer('component_id')->unsigned();});}- public function moveBackEntriesForBudgetsInJoinedTable()+ private function createComponentIdForeignKey(){- $set = DB::table('budget_transaction_journal')->get();- foreach ($set as $entry) {- $budget = Budget::find($entry->budget_id);- if ($budget) {- $component = Component::where('class', 'Budget')->where('name', $budget->name)->where('user_id', $budget->user_id)->first();- if ($component) {- DB::table('component_transaction_journal')->insert(- [- 'component_id' => $component->id,- 'transaction_journal_id' => $entry->transaction_journal_id- ]- );- }-- }+ Schema::table(+ 'budget_limits', function (Blueprint $table) {+ $table->foreign('component_id', 'limits_component_id_foreign')->references('id')->on('components')->onDelete('cascade');}-+ );}- public function moveBackEntriesForCategoriesInJoinedTable()+ private function dropBudgetIdColumnInBudgetLimits(){- $set = DB::table('category_transaction_journal')->get();- foreach ($set as $entry) {- $category = Category::find($entry->category_id);- if ($category) {- $component = Component::where('class', 'Category')->where('name', $category->name)->where('user_id', $category->user_id)->first();- if ($component) {- DB::table('component_transaction_journal')->insert(- [- 'component_id' => $component->id,- 'transaction_journal_id' => $entry->transaction_journal_id- ]- );- }-- }+ Schema::table(+ 'budget_limits', function (Blueprint $table) {+ $table->dropForeign('bid_foreign');+ $table->dropColumn('budget_id'); // also drop foreign key!}-+ );}- public function dropBudgetJournalTable()+ private function dropBudgetJournalTable(){Schema::dropIfExists('budget_transaction_journal');}- public function dropCategoryJournalTable()+ private function dropBudgetTable(){- Schema::dropIfExists('category_transaction_journal');+ Schema::dropIfExists('budgets');}- public function dropBudgetTable()+ private function dropCategoryJournalTable(){- Schema::dropIfExists('budgets');+ Schema::dropIfExists('category_transaction_journal');}- public function dropCategoryTable()+ private function dropCategoryTable(){Schema::dropIfExists('categories');}- public function renameBudgetLimits()+ private function dropComponentIdFromBudgetLimits(){- Schema::rename('budget_limits', 'limits');+ Schema::table(+ 'budget_limits', function (Blueprint $table) {+ $table->dropForeign('limits_component_id_foreign');+ $table->dropColumn('component_id');+ }+ );}- public function renamePiggyBankEvents()+ private function dropComponentJournalTable(){- Schema::rename('piggy_bank_events', 'piggybank_events');+ Schema::dropIfExists('component_transaction_journal');+ }+ private function dropComponentRecurringTransactionTable()+ {+ Schema::dropIfExists('component_recurring_transaction');}- public function renameBudgetLimitToBudgetInRepetitions()+ private function dropComponentTransactionTable(){- Schema::table(- 'limit_repetitions', function (Blueprint $table) {- $table->dropForeign('limit_repetitions_budget_limit_id_foreign');- $table->renameColumn('budget_limit_id', 'limit_id');- $table->foreign('limit_id')->references('id')->on('limits')->onDelete('cascade');- }- );+ Schema::dropIfExists('component_transaction');}- public function dropFieldsFromCurrencyTable()+ private function dropFieldsFromCurrencyTable(){Schema::table(@@ -257,111 +279,95 @@ class ChangesForV321 extends Migration);}- /**- * Run the migrations.- *- * @return void- */- public function up()+ private function dropPiggyBankIdFromTransactions(){- $this->createBudgetTable(); // 1.- $this->createCategoryTable(); // 2.- $this->createBudgetJournalTable(); // 3- $this->createCategoryJournalTable(); // 4.- $this->moveBudgets(); // 5.- $this->moveCategories(); // 6.- $this->correctNameForBudgetLimits(); // 7.- $this->correctNameForPiggyBankEvents(); // 8.- $this->renameBudgetToBudgetLimitInRepetitions(); // 9.- $this->addBudgetIdFieldToBudgetLimits(); // 10.- $this->moveComponentIdToBudgetId(); // 11.- $this->dropComponentJournalTable(); // 12.- $this->dropComponentRecurringTransactionTable(); // 13.- $this->dropComponentTransactionTable(); // 14.- $this->dropPiggyBankIdFromTransactions(); // 15.- $this->dropComponentIdFromBudgetLimits(); // 16.- $this->expandCurrencyTable(); // 17.-- }- public function createBudgetTable()- {- Schema::create(- 'budgets', function (Blueprint $table) {- $table->increments('id');- $table->timestamps();- $table->softDeletes();- $table->string('name', 50);- $table->integer('user_id')->unsigned();- $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');- $table->unique(['user_id', 'name']);+ Schema::table(+ 'transactions', function (Blueprint $table) {+ if (Schema::hasColumn('transactions', 'piggybank_id')) {+ $table->dropForeign('transactions_piggybank_id_foreign');+ $table->dropColumn('piggybank_id');+ }});--}- public function createCategoryTable()+ private function expandCurrencyTable(){- Schema::create(- 'categories', function (Blueprint $table) {- $table->increments('id');- $table->timestamps();- $table->softDeletes();- $table->string('name', 50);- $table->integer('user_id')->unsigned();- $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');- $table->unique(['user_id', 'name']);+ Schema::table(+ 'transaction_currencies', function (Blueprint $table) {+ $table->string('name', 48)->nullable();+ $table->string('symbol', 8)->nullable();});+ \DB::update('UPDATE `transaction_currencies` SET `symbol` = "€", `name` = "Euro" WHERE `code` = "EUR";');}- public function createBudgetJournalTable()+ private function moveBackEntriesForBudgetsInJoinedTable(){- Schema::create(- 'budget_transaction_journal', function (Blueprint $table) {- $table->increments('id');- $table->integer('budget_id')->unsigned();- $table->integer('transaction_journal_id')->unsigned();- $table->foreign('budget_id')->references('id')->on('budgets')->onDelete('cascade');- $table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade');- $table->unique(['budget_id', 'transaction_journal_id'], 'budid_tjid_unique');+ $set = DB::table('budget_transaction_journal')->get();+ /** @var \stdClass $entry */+ foreach ($set as $entry) {+ $budget = Budget::find($entry->budget_id);+ if ($budget) {+ /** @var \FireflyIII\Models\Component $component */+ $component = Component::where('class', 'Budget')->where('name', $budget->name)->where('user_id', $budget->user_id)->first();+ if ($component) {+ DB::table('component_transaction_journal')->insert(+ [+ 'component_id' => $component->id,+ 'transaction_journal_id' => $entry->transaction_journal_id,+ ]+ );+ }++ }}- );+}- public function createCategoryJournalTable()+ private function moveBackEntriesForCategoriesInJoinedTable(){- Schema::create(- 'category_transaction_journal', function (Blueprint $table) {- $table->increments('id');- $table->integer('category_id')->unsigned();- $table->integer('transaction_journal_id')->unsigned();- $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');- $table->foreign('transaction_journal_id')->references('id')->on('transaction_journals')->onDelete('cascade');- $table->unique(['category_id', 'transaction_journal_id'], 'catid_tjid_unique');+ $set = DB::table('category_transaction_journal')->get();+ /** @var \stdClass $entry */+ foreach ($set as $entry) {+ $category = Category::find($entry->category_id);+ if ($category) {+ /** @var \FireflyIII\Models\Component $component */+ $component = Component::where('class', 'Category')->where('name', $category->name)->where('user_id', $category->user_id)->first();+ if ($component) {+ DB::table('component_transaction_journal')->insert(+ [+ 'component_id' => $component->id,+ 'transaction_journal_id' => $entry->transaction_journal_id,+ ]+ );+ }++ }}- );+}- public function moveBudgets()+ private function moveBudgets(){Component::where('class', 'Budget')->get()->each(function (Component $c) {$entry = ['user_id' => $c->user_id,- 'name' => $c->name+ 'name' => $c->name,];$budget = Budget::firstOrCreate($entry);Log::debug('Migrated budget #' . $budget->id . ': ' . $budget->name);// create entry in budget_transaction_journal$connections = DB::table('component_transaction_journal')->where('component_id', $c->id)->get();+ /** @var \stdClass $connection */foreach ($connections as $connection) {DB::table('budget_transaction_journal')->insert(['budget_id' => $budget->id,- 'transaction_journal_id' => $connection->transaction_journal_id+ 'transaction_journal_id' => $connection->transaction_journal_id,]);}@@ -369,24 +375,40 @@ class ChangesForV321 extends Migration);}- public function moveCategories()+ private function moveBudgetsBack()+ {+ Budget::get()->each(+ function (Budget $budget) {+ Component::firstOrCreate(+ [+ 'name' => $budget->name,+ 'user_id' => $budget->user_id,+ 'class' => 'Budget',+ ]+ );+ }+ );+ }++ private function moveCategories(){Component::where('class', 'Category')->get()->each(function (Component $c) {$entry = ['user_id' => $c->user_id,- 'name' => $c->name+ 'name' => $c->name,];$category = Category::firstOrCreate($entry);Log::debug('Migrated category #' . $category->id . ': ' . $category->name);// create entry in category_transaction_journal$connections = DB::table('component_transaction_journal')->where('component_id', $c->id)->get();+ /** @var \stdClass $connection */foreach ($connections as $connection) {DB::table('category_transaction_journal')->insert(['category_id' => $category->id,- 'transaction_journal_id' => $connection->transaction_journal_id+ 'transaction_journal_id' => $connection->transaction_journal_id,]);}@@ -394,39 +416,22 @@ class ChangesForV321 extends Migration);}- public function correctNameForBudgetLimits()- {- Schema::rename('limits', 'budget_limits');- }-- public function correctNameForPiggyBankEvents()- {- Schema::rename('piggybank_events', 'piggy_bank_events');-- }-- public function renameBudgetToBudgetLimitInRepetitions()- {- Schema::table(- 'limit_repetitions', function (Blueprint $table) {- $table->dropForeign('limit_repetitions_limit_id_foreign');- $table->renameColumn('limit_id', 'budget_limit_id');- $table->foreign('budget_limit_id')->references('id')->on('budget_limits')->onDelete('cascade');- }- );- }-- public function addBudgetIdFieldToBudgetLimits()+ private function moveCategoriesBack(){- Schema::table(- 'budget_limits', function (Blueprint $table) {- $table->integer('budget_id', false, true)->nullable()->after('updated_at');- $table->foreign('budget_id', 'bid_foreign')->references('id')->on('budgets')->onDelete('cascade');- }+ Category::get()->each(+ function (Category $category) {+ Component::firstOrCreate(+ [+ 'name' => $category->name,+ 'user_id' => $category->user_id,+ 'class' => 'Category',+ ]+ );+ });}- public function moveComponentIdToBudgetId()+ private function moveComponentIdToBudgetId(){BudgetLimit::get()->each(function (BudgetLimit $bl) {@@ -451,53 +456,54 @@ class ChangesForV321 extends Migration}- public function dropComponentJournalTable()+ private function renameBudgetLimitToBudgetInRepetitions(){- Schema::dropIfExists('component_transaction_journal');- }-- public function dropComponentRecurringTransactionTable()- {- Schema::dropIfExists('component_recurring_transaction');+ Schema::table(+ 'limit_repetitions', function (Blueprint $table) {+ $table->dropForeign('limit_repetitions_budget_limit_id_foreign');+ $table->renameColumn('budget_limit_id', 'limit_id');+ $table->foreign('limit_id')->references('id')->on('limits')->onDelete('cascade');+ }+ );}- public function dropComponentTransactionTable()+ private function renameBudgetLimits(){- Schema::dropIfExists('component_transaction');+ Schema::rename('budget_limits', 'limits');}- public function dropPiggyBankIdFromTransactions()+ private function renameBudgetToBudgetLimitInRepetitions(){-Schema::table(- 'transactions', function (Blueprint $table) {- if (Schema::hasColumn('transactions', 'piggybank_id')) {- $table->dropForeign('transactions_piggybank_id_foreign');- $table->dropColumn('piggybank_id');- }+ 'limit_repetitions', function (Blueprint $table) {+ $table->dropForeign('limit_repetitions_limit_id_foreign');+ $table->renameColumn('limit_id', 'budget_limit_id');+ $table->foreign('budget_limit_id')->references('id')->on('budget_limits')->onDelete('cascade');});}- public function dropComponentIdFromBudgetLimits()+ private function renamePiggyBankEvents(){- Schema::table(- 'budget_limits', function (Blueprint $table) {- $table->dropForeign('limits_component_id_foreign');- $table->dropColumn('component_id');- }- );+ Schema::rename('piggy_bank_events', 'piggybank_events');+}- public function expandCurrencyTable()+ private function updateComponentInBudgetLimits(){- Schema::table(- 'transaction_currencies', function (Blueprint $table) {- $table->string('name', 48)->nullable();- $table->string('symbol', 8)->nullable();- }+ BudgetLimit::get()->each(+ function (BudgetLimit $bl) {+ $budgetId = $bl->budget_id;+ $budget = Budget::find($budgetId);+ if ($budget) {+ $component = Component::where('class', 'Budget')->where('user_id', $budget->user_id)->where('name', $budget->name)->first();+ if ($component) {+ $bl->component_id = $component->id;+ $bl->save();+ }+ }+ });- \DB::update('UPDATE `transaction_currencies` SET `symbol` = "€", `name` = "Euro" WHERE `code` = "EUR";');}diff --git a/database/migrations/2015_01_18_082406_changes_for_v325.php b/database/migrations/2015_01_18_082406_changes_for_v325.phpindex 4c189cc840..83e16c0bc6 100644--- a/database/migrations/2015_01_18_082406_changes_for_v325.php+++ b/database/migrations/2015_01_18_082406_changes_for_v325.php@@ -19,7 +19,6 @@ class ChangesForV325 extends Migration*/public function down(){- //}/**@@ -29,8 +28,6 @@ class ChangesForV325 extends Migration*/public function up(){- //-// delete an old index:try {Schema::table(diff --git a/database/migrations/2015_02_27_210653_changes_for_v332.php b/database/migrations/2015_02_27_210653_changes_for_v332.phpindex 379b50a0c6..97a4f38641 100644--- a/database/migrations/2015_02_27_210653_changes_for_v332.php+++ b/database/migrations/2015_02_27_210653_changes_for_v332.php@@ -18,7 +18,6 @@ class ChangesForV332 extends Migration*/public function down(){- //}/**diff --git a/database/migrations/2015_03_27_061038_changes_for_v333.php b/database/migrations/2015_03_27_061038_changes_for_v333.phpindex 88da537984..78027e5e45 100644--- a/database/migrations/2015_03_27_061038_changes_for_v333.php+++ b/database/migrations/2015_03_27_061038_changes_for_v333.php@@ -18,7 +18,6 @@ class ChangesForV333 extends Migration*/public function down(){- //}/**diff --git a/database/migrations/2015_04_28_075215_changes_for_v3310a.php b/database/migrations/2015_04_28_075215_changes_for_v3310a.phpindex 9a599ccb8b..5d31326a58 100644--- a/database/migrations/2015_04_28_075215_changes_for_v3310a.php+++ b/database/migrations/2015_04_28_075215_changes_for_v3310a.php@@ -18,7 +18,6 @@ class ChangesForV3310a extends Migration*/public function down(){- //}/**diff --git a/database/migrations/2015_04_28_075317_changes_for_v3310b.php b/database/migrations/2015_04_28_075317_changes_for_v3310b.phpindex ee2e8d17e7..06d3522d3d 100644--- a/database/migrations/2015_04_28_075317_changes_for_v3310b.php+++ b/database/migrations/2015_04_28_075317_changes_for_v3310b.php@@ -17,7 +17,6 @@ class ChangesForV3310b extends Migration*/public function down(){- //}/**diff --git a/database/migrations/2015_07_14_204645_changes_for_v349.php b/database/migrations/2015_07_14_204645_changes_for_v349.phpindex 48147e6448..b2433f455f 100644--- a/database/migrations/2015_07_14_204645_changes_for_v349.php+++ b/database/migrations/2015_07_14_204645_changes_for_v349.php@@ -17,7 +17,6 @@ class ChangesForV349 extends Migration*/public function down(){- //}/**diff --git a/database/migrations/2016_01_11_193428_changes_for_v370.php b/database/migrations/2016_01_11_193428_changes_for_v370.phpindex 87134f0581..ba11bbaf44 100644--- a/database/migrations/2016_01_11_193428_changes_for_v370.php+++ b/database/migrations/2016_01_11_193428_changes_for_v370.php@@ -18,6 +18,20 @@ use Illuminate\Database\Schema\Blueprint;*/class ChangesForV370 extends Migration{+ /**+ * Reverse the migrations.+ *+ * @return void+ */+ public function down()+ {+ Schema::drop('rule_actions');+ Schema::drop('rule_triggers');+ Schema::drop('rules');+ Schema::drop('rule_groups');++ }+/*** Run the migrations.*@@ -108,18 +122,4 @@ class ChangesForV370 extends Migration);}-- /**- * Reverse the migrations.- *- * @return void- */- public function down()- {- Schema::drop('rule_actions');- Schema::drop('rule_triggers');- Schema::drop('rules');- Schema::drop('rule_groups');-- }}