mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Clean up some code.
This commit is contained in:
@@ -1,31 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
return new class () extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
// make account_id nullable and the relation also nullable.
|
||||
Schema::table('piggy_banks', static function (Blueprint $table) {
|
||||
Schema::table('piggy_banks', static function (Blueprint $table): void {
|
||||
// 1. drop index
|
||||
$table->dropForeign('piggy_banks_account_id_foreign');
|
||||
});
|
||||
Schema::table('piggy_banks', static function (Blueprint $table) {
|
||||
Schema::table('piggy_banks', static function (Blueprint $table): void {
|
||||
// 2. make column nullable.
|
||||
$table->unsignedInteger('account_id')->nullable()->change();
|
||||
});
|
||||
Schema::table('piggy_banks', static function (Blueprint $table) {
|
||||
Schema::table('piggy_banks', static function (Blueprint $table): void {
|
||||
// 3. add currency
|
||||
$table->integer('transaction_currency_id', false, true)->after('account_id');
|
||||
$table->foreign('transaction_currency_id','unique_currency')->references('id')->on('transaction_currencies')->onDelete('cascade');
|
||||
$table->foreign('transaction_currency_id', 'unique_currency')->references('id')->on('transaction_currencies')->onDelete('cascade');
|
||||
});
|
||||
Schema::table('piggy_banks', static function (Blueprint $table) {
|
||||
Schema::table('piggy_banks', static function (Blueprint $table): void {
|
||||
// 4. rename columns
|
||||
$table->renameColumn('targetamount', 'target_amount');
|
||||
$table->renameColumn('startdate', 'start_date');
|
||||
@@ -33,13 +34,13 @@ return new class extends Migration
|
||||
$table->renameColumn('startdate_tz', 'start_date_tz');
|
||||
$table->renameColumn('targetdate_tz', 'target_date_tz');
|
||||
});
|
||||
Schema::table('piggy_banks', static function (Blueprint $table) {
|
||||
Schema::table('piggy_banks', static function (Blueprint $table): void {
|
||||
// 5. add new index
|
||||
$table->foreign('account_id')->references('id')->on('accounts')->onDelete('set null');
|
||||
});
|
||||
|
||||
// rename some fields in piggy bank reps.
|
||||
Schema::table('piggy_bank_repetitions', static function (Blueprint $table) {
|
||||
Schema::table('piggy_bank_repetitions', static function (Blueprint $table): void {
|
||||
// 6. rename columns
|
||||
$table->renameColumn('currentamount', 'current_amount');
|
||||
$table->renameColumn('startdate', 'start_date');
|
||||
@@ -49,14 +50,14 @@ return new class extends Migration
|
||||
});
|
||||
|
||||
// create table account_piggy_bank
|
||||
Schema::create('account_piggy_bank', static function (Blueprint $table) {
|
||||
Schema::create('account_piggy_bank', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->integer('account_id', false, true);
|
||||
$table->integer('piggy_bank_id',false, true);
|
||||
$table->integer('piggy_bank_id', false, true);
|
||||
$table->decimal('current_amount', 32, 12)->default('0');
|
||||
$table->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade');
|
||||
$table->foreign('piggy_bank_id')->references('id')->on('piggy_banks')->onDelete('cascade');
|
||||
$table->unique(['account_id', 'piggy_bank_id'],'unique_piggy_save');
|
||||
$table->unique(['account_id', 'piggy_bank_id'], 'unique_piggy_save');
|
||||
});
|
||||
|
||||
}
|
||||
@@ -66,7 +67,7 @@ return new class extends Migration
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('piggy_banks', static function (Blueprint $table) {
|
||||
Schema::table('piggy_banks', static function (Blueprint $table): void {
|
||||
// 1. drop account index again.
|
||||
$table->dropForeign('piggy_banks_account_id_foreign');
|
||||
|
||||
@@ -89,7 +90,7 @@ return new class extends Migration
|
||||
});
|
||||
|
||||
// rename some fields in piggy bank reps.
|
||||
Schema::table('piggy_bank_repetitions', static function (Blueprint $table) {
|
||||
Schema::table('piggy_bank_repetitions', static function (Blueprint $table): void {
|
||||
// 6. rename columns
|
||||
$table->renameColumn('current_amount', 'currentamount');
|
||||
$table->renameColumn('start_date', 'startdate');
|
||||
|
Reference in New Issue
Block a user