mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
This commit is contained in:
@@ -25,10 +25,11 @@ declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class () extends Migration {
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
@@ -37,8 +38,9 @@ return new class () extends Migration {
|
||||
// make account_id nullable and the relation also nullable.
|
||||
try {
|
||||
Schema::table('piggy_banks', static function (Blueprint $table): void {
|
||||
// 1. drop index
|
||||
$table->dropForeign('piggy_banks_account_id_foreign');
|
||||
if (self::hasForeign('piggy_banks', 'piggy_banks_account_id_foreign')) {
|
||||
$table->dropForeign('piggy_banks_account_id_foreign');
|
||||
}
|
||||
});
|
||||
} catch (RuntimeException $e) {
|
||||
Log::error('Could not drop foreign key "piggy_banks_account_id_foreign". Probably not an issue.');
|
||||
@@ -105,7 +107,9 @@ return new class () extends Migration {
|
||||
$table->renameColumn('target_date_tz', 'targetdate_tz');
|
||||
|
||||
// 3. drop currency again + index
|
||||
$table->dropForeign('unique_currency');
|
||||
if (self::hasForeign('piggy_banks', 'unique_currency')) {
|
||||
$table->dropForeign('unique_currency');
|
||||
}
|
||||
$table->dropColumn('transaction_currency_id');
|
||||
|
||||
// 2. make column non-nullable.
|
||||
@@ -127,4 +131,15 @@ return new class () extends Migration {
|
||||
|
||||
Schema::dropIfExists('account_piggy_bank');
|
||||
}
|
||||
|
||||
protected static function hasForeign(string $table, string $column) {
|
||||
|
||||
$foreignKeysDefinitions = Schema::getForeignKeys($table);
|
||||
foreach($foreignKeysDefinitions as $foreignKeyDefinition) {
|
||||
if($foreignKeyDefinition['name'] === $column) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user