Fix another place where migrations may fail.

This commit is contained in:
James Cole
2019-09-14 18:17:32 +02:00
parent 657baf283d
commit 8776d47545

View File

@@ -39,14 +39,15 @@ class ChangesForV440 extends Migration
Schema::table( Schema::table(
'transactions', 'transactions',
function (Blueprint $table) { static function (Blueprint $table) {
if (Schema::hasColumn('transactions', 'transaction_currency_id')) {
// cannot drop foreign keys in SQLite: // cannot drop foreign keys in SQLite:
if ('sqlite' !== config('database.default')) { if ('sqlite' !== config('database.default')) {
$table->dropForeign('transactions_transaction_currency_id_foreign'); $table->dropForeign('transactions_transaction_currency_id_foreign');
} }
$table->dropColumn('transaction_currency_id'); $table->dropColumn('transaction_currency_id');
} }
}
); );
} }
@@ -60,7 +61,7 @@ class ChangesForV440 extends Migration
if (!Schema::hasTable('currency_exchange_rates')) { if (!Schema::hasTable('currency_exchange_rates')) {
Schema::create( Schema::create(
'currency_exchange_rates', 'currency_exchange_rates',
function (Blueprint $table) { static function (Blueprint $table) {
$table->increments('id'); $table->increments('id');
$table->timestamps(); $table->timestamps();
$table->softDeletes(); $table->softDeletes();
@@ -80,10 +81,12 @@ class ChangesForV440 extends Migration
Schema::table( Schema::table(
'transactions', 'transactions',
function (Blueprint $table) { static function (Blueprint $table) {
if (!Schema::hasColumn('transactions', 'transaction_currency_id')) {
$table->integer('transaction_currency_id', false, true)->after('description')->nullable(); $table->integer('transaction_currency_id', false, true)->after('description')->nullable();
$table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('set null'); $table->foreign('transaction_currency_id')->references('id')->on('transaction_currencies')->onDelete('set null');
} }
}
); );
} }
} }