mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Universal database stuff.
This commit is contained in:
parent
73bc5372c0
commit
e7d3716549
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
|
||||
/**
|
||||
* SuppressWarnings(PHPMD.ShortMethodName)
|
||||
@ -17,13 +18,27 @@ class ChangesForV321 extends Migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
// rename tables back to original name.
|
||||
Schema::rename('budget_limits', 'limits');
|
||||
Schema::rename('piggy_bank_events', 'piggybank_events');
|
||||
DB::update(DB::raw('ALTER TABLE `limit_repetitions` ALGORITHM=INPLACE, CHANGE `budget_limit_id` `limit_id` INT UNSIGNED NOT NULL'));
|
||||
DB::update(DB::Raw('ALTER TABLE `transactions` ADD `piggybank_id` INT(10) UNSIGNED DEFAULT NULL AFTER `account_id`;'));
|
||||
DB::update(DB::Raw('CREATE INDEX `transactions_piggybank_id_foreign` ON `transactions` (`piggybank_id`)'));
|
||||
DB::update(DB::Raw('ALTER TABLE `transactions` ADD FOREIGN KEY (`piggybank_id`) REFERENCES `piggybanks`(`id`);'));
|
||||
|
||||
// rename column in "limit_repetitions" back to the original name
|
||||
Schema::table(
|
||||
'limit_repetitions', function (Blueprint $table) {
|
||||
$table->renameColumn('budget_limit_id', 'limit_id');
|
||||
}
|
||||
);
|
||||
|
||||
// create column in "transactions"
|
||||
// create foreign key in "transactions"
|
||||
Schema::table(
|
||||
'transactions', function (Blueprint $table) {
|
||||
$table->integer('piggybank_id')->nullable()->unsigned();
|
||||
$table->foreign('piggybank_id')->references('id')->on('piggybanks')->onDelete('set null');
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
@ -31,12 +46,28 @@ class ChangesForV321 extends Migration
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
// rename tables.
|
||||
Schema::rename('limits', 'budget_limits');
|
||||
DB::update(DB::raw('ALTER TABLE `limit_repetitions` ALGORITHM = INPLACE, CHANGE `limit_id` `budget_limit_id` INT UNSIGNED NOT null'));
|
||||
DB::update(DB::Raw('ALTER TABLE `transactions` DROP FOREIGN KEY `transactions_piggybank_id_foreign`'));
|
||||
DB::update(DB::Raw('ALTER TABLE `transactions` DROP `piggybank_id`'));
|
||||
Schema::rename('piggybank_events', 'piggy_bank_events');
|
||||
|
||||
// rename column in "limit_repetitions"
|
||||
Schema::table(
|
||||
'limit_repetitions', function (Blueprint $table) {
|
||||
$table->renameColumn('limit_id', 'budget_limit_id');
|
||||
}
|
||||
);
|
||||
|
||||
// drop foreign key in "transactions"
|
||||
// drop column in "transactions"
|
||||
Schema::table(
|
||||
'transactions', function (Blueprint $table) {
|
||||
$table->dropForeign('transactions_piggybank_id_foreign');
|
||||
$table->dropIndex('transactions_piggybank_id_foreign');
|
||||
$table->dropColumn('piggybank_id');
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user