Made sure the migrations are reversible and updated the test seeder.

This commit is contained in:
James Cole
2014-12-22 20:43:38 +01:00
parent 10b00da874
commit f0babb4be7
2 changed files with 60 additions and 36 deletions

View File

@@ -7,22 +7,24 @@ use Illuminate\Database\Schema\Blueprint;
* Down: * Down:
* 1. Create new Components based on Budgets. * 1. Create new Components based on Budgets.
* 2. Create new Components based on Categories * 2. Create new Components based on Categories
* 3. Update all budget_limits entries (component_id). * 3. Recreate component_id in limits
* 4. Drop column 'budget_id' in budget_limits. * 4. Update all budget_limits entries (component_id).
* 5. Create table journal_components. * 5. Add the foreign key to component_id in budget_limits
* 6. create entries for budgets in journal_components. * 6. Drop column 'budget_id' in budget_limits.
* 7. create entries for categories in journal_components. * 7. Create table journal_components.
* 8. drop table budget_journals * 8. create entries for budgets in journal_components.
* 9. drop table category_journals * 9. create entries for categories in journal_components.
* 10. drop table budgets * 10. drop table budget_journals
* 11. drop table categories. * 11. drop table category_journals
* 12. rename budget_limits to limits. * 12. drop table budgets
* 13. Rename piggy_bank_events to piggybank_events * 13. drop table categories.
* 14. Rename field 'budget_limit_id' to 'limit_id' in 'limit_repetitions' * 14. rename budget_limits to limits.
* 15. Do not recreate component_recurring_transaction * 15. Rename piggy_bank_events to piggybank_events
* 16. Do not recreate component_transaction * 16. Rename field 'budget_limit_id' to 'limit_id' in 'limit_repetitions'
* 17. Do not recreate field 'piggybank_id' in 'transactions' * 17. Do not recreate component_recurring_transaction
* 18. Recreate component_id in limits * 18. Do not recreate component_transaction
* 19. Do not recreate field 'piggybank_id' in 'transactions'
*
* *
* *
* Up: * Up:
@@ -42,7 +44,7 @@ use Illuminate\Database\Schema\Blueprint;
* 13. Drop table component_recurring_transaction * 13. Drop table component_recurring_transaction
* 14. Drop table component_transaction * 14. Drop table component_transaction
* 15. Drop field 'piggybank_id' from 'transactions' * 15. Drop field 'piggybank_id' from 'transactions'
* 16. Drop component_id from budget_limits. * 16. Drop field 'component_id' from 'budget_limits'
* *
* Class ChangesForV321 * Class ChangesForV321
*/ */
@@ -53,21 +55,40 @@ class ChangesForV321 extends Migration
$this->moveBudgetsBack(); // 1. $this->moveBudgetsBack(); // 1.
$this->moveCategoriesBack(); // 2. $this->moveCategoriesBack(); // 2.
$this->updateComponentInBudgetLimits(); // 3. $this->createComponentId(); // 3.
$this->dropBudgetIdColumnInBudgetLimits(); // 4. $this->updateComponentInBudgetLimits(); // 4.
$createComponents = new CreateComponentTransactionJournalTable; // 5. $this->createComponentIdForeignKey(); // 5.
$this->dropBudgetIdColumnInBudgetLimits(); // 6.
$createComponents = new CreateComponentTransactionJournalTable; // 7.
$createComponents->up(); $createComponents->up();
$this->moveBackEntriesForBudgetsInJoinedTable(); // 6. $this->moveBackEntriesForBudgetsInJoinedTable(); // 8.
$this->moveBackEntriesForCategoriesInJoinedTable(); // 7. $this->moveBackEntriesForCategoriesInJoinedTable(); // 9.
$this->dropBudgetJournalTable(); // 8. $this->dropBudgetJournalTable(); // 10.
$this->dropCategoryJournalTable(); // 9. $this->dropCategoryJournalTable(); // 11.
$this->dropBudgetTable(); // 10. $this->dropBudgetTable(); // 12.
$this->dropCategoryTable(); // 11. $this->dropCategoryTable(); // 13.
$this->renameBudgetLimits(); // 12. $this->renameBudgetLimits(); // 14.
$this->renamePiggyBankEvents(); // 13. $this->renamePiggyBankEvents(); // 15.
$this->renameBudgetLimitToBudgetInRepetitions(); // 14. $this->renameBudgetLimitToBudgetInRepetitions(); // 16.
// 15, 16, 17 // 17, 18, 19
}
public function createComponentId() {
Schema::table(
'budget_limits', function (Blueprint $table) {
$table->integer('component_id')->unsigned();
}
);
}
public function createComponentIdForeignKey() {
Schema::table(
'budget_limits', function (Blueprint $table) {
$table->foreign('component_id')->references('id')->on('components')->onDelete('cascade');
}
);
} }
public function moveBudgetsBack() public function moveBudgetsBack()

View File

@@ -38,27 +38,30 @@ class TestContentSeeder extends Seeder
// some limits: // some limits:
$startDate = Carbon::now()->startOfMonth(); $startDate = Carbon::now()->startOfMonth();
$endDate = Carbon::now()->endOfMonth(); $endDate = Carbon::now()->endOfMonth();
$secondStart = Carbon::now()->subMonth()->startOfMonth();
$secondEnd = Carbon::now()->subMonth()->endOfMonth();
$limitOne = BudgetLimit::create( $limitOne = BudgetLimit::create(
['startdate' => $startDate->format('Y-m-d'), 'amount' => 200, 'repeats' => 0, 'repeat_freq' => 'monthly', ['startdate' => $startDate->format('Y-m-d'), 'amount' => 201, 'repeats' => 0, 'repeat_freq' => 'monthly',
'budget_id' => $groceriesBudget->id] 'budget_id' => $groceriesBudget->id]
); );
$limitTwo = BudgetLimit::create( $limitTwo = BudgetLimit::create(
['startdate' => $startDate->format('Y-m-d'), 'amount' => 200, 'repeats' => 0, 'repeat_freq' => 'monthly', ['startdate' => $secondStart->format('Y-m-d'), 'amount' => 202, 'repeats' => 0, 'repeat_freq' => 'monthly',
'budget_id' => $billsBudget->id] 'budget_id' => $billsBudget->id]
); );
$limitThree = BudgetLimit::create( $limitThree = BudgetLimit::create(
['startdate' => '2014-01-01', 'amount' => 200, 'repeats' => 0, 'repeat_freq' => 'monthly', 'budget_id' => $deleteBudget->id] ['startdate' => '2014-01-01', 'amount' => 203, 'repeats' => 0, 'repeat_freq' => 'monthly',
'budget_id' => $deleteBudget->id]
); );
// and because we have no filters, some repetitions: // and because we have no filters, some repetitions:
$repOne = LimitRepetition::create( $repOne = LimitRepetition::create(
['budget_limit_id' => $limitOne->id, 'startdate' => $startDate->format('Y-m-d'), 'enddate' => $endDate->format('Y-m-d'), 'amount' => 200] ['budget_limit_id' => $limitOne->id, 'startdate' => $startDate->format('Y-m-d'), 'enddate' => $endDate->format('Y-m-d'), 'amount' => 201]
); );
$repTwo = LimitRepetition::create( $repTwo = LimitRepetition::create(
['budget_limit_id' => $limitTwo->id, 'startdate' => $startDate->format('Y-m-d'), 'enddate' => $endDate->format('Y-m-d'), 'amount' => 200] ['budget_limit_id' => $limitTwo->id, 'startdate' => $secondStart->format('Y-m-d'), 'enddate' => $secondEnd->format('Y-m-d'), 'amount' => 202]
); );
$repThree = LimitRepetition::create( $repThree = LimitRepetition::create(
['budget_limit_id' => $limitThree->id, 'startdate' => '2014-01-01', 'enddate' => '2014-01-31', 'amount' => 200] ['budget_limit_id' => $limitThree->id, 'startdate' => '2014-01-01', 'enddate' => '2014-01-31', 'amount' => 203]
); );
// create two categories: // create two categories: