From b4f18dbe774149b80cd73efa86fc90c92cf9f6e7 Mon Sep 17 00:00:00 2001 From: James Cole Date: Mon, 25 Apr 2016 11:44:41 +0200 Subject: [PATCH] Database stuff. --- app/Support/Migration/TestData.php | 2 +- .../2016_04_25_093451_changes_for_385.php | 39 +++++++++++++++++++ database/seeds/TestDataSeeder.php | 21 ++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2016_04_25_093451_changes_for_385.php diff --git a/app/Support/Migration/TestData.php b/app/Support/Migration/TestData.php index 66f22d01c2..b79ef52e2c 100644 --- a/app/Support/Migration/TestData.php +++ b/app/Support/Migration/TestData.php @@ -225,7 +225,7 @@ class TestData Budget::firstOrCreateEncrypted(['name' => 'Car', 'user_id' => $user->id]); // some empty budgets. - foreach (['A', 'B', 'C', 'D', 'E'] as $letter) { + foreach (['A'] as $letter) { Budget::firstOrCreateEncrypted(['name' => 'Empty budget ' . $letter, 'user_id' => $user->id]); } diff --git a/database/migrations/2016_04_25_093451_changes_for_385.php b/database/migrations/2016_04_25_093451_changes_for_385.php new file mode 100644 index 0000000000..94d87cbd9f --- /dev/null +++ b/database/migrations/2016_04_25_093451_changes_for_385.php @@ -0,0 +1,39 @@ +dropUnique('unique_limit'); + } + ); + + // create it again, correctly. + Schema::table( + 'budget_limits', function (Blueprint $table) { + $table->unique(['budget_id', 'startdate','repeat_freq'], 'unique_limit'); + } + ); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} diff --git a/database/seeds/TestDataSeeder.php b/database/seeds/TestDataSeeder.php index f018ad6b6e..ed6151f9e2 100644 --- a/database/seeds/TestDataSeeder.php +++ b/database/seeds/TestDataSeeder.php @@ -9,6 +9,7 @@ declare(strict_types = 1); */ use Carbon\Carbon; +use FireflyIII\Models\BudgetLimit; use FireflyIII\Support\Migration\TestData; use Illuminate\Database\Seeder; @@ -90,5 +91,25 @@ class TestDataSeeder extends Seeder $current->addMonth(); } + + // create some special budget limits to test stuff with multiple budget limits + // for a range of dates: + $this->end->startOfMonth(); + $budget = TestData::findBudget($user, 'Bills'); + $ranges = ['daily','weekly','monthly','quarterly','half-year','yearly']; + foreach($ranges as $range) { + BudgetLimit::create( + [ + 'budget_id' => $budget->id, + 'startdate' => $this->end->format('Y-m-d'), + 'amount' => rand(100,200), + 'repeats' => 0, + 'repeat_freq' => $range, + ] + ); + $this->end->addDay(); + } + + // b } }