From 2eafd3cc15acfd8c581fb35f6cabcc6cfcad1117 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 14 May 2017 08:57:43 +0200 Subject: [PATCH] Should fix #644 --- app/Console/Commands/UpgradeDatabase.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/Console/Commands/UpgradeDatabase.php b/app/Console/Commands/UpgradeDatabase.php index d313c55ec6..aa2656b712 100644 --- a/app/Console/Commands/UpgradeDatabase.php +++ b/app/Console/Commands/UpgradeDatabase.php @@ -269,9 +269,10 @@ class UpgradeDatabase extends Command $repository = app(CurrencyRepositoryInterface::class); $notification = '%s #%d uses %s but should use %s. It has been updated. Please verify this in Firefly III.'; $transfer = 'Transfer #%d has been updated to use the correct currencies. Please verify this in Firefly III.'; + $driver = DB::connection()->getDriverName(); foreach ($types as $type => $operator) { - $set = TransactionJournal + $query = TransactionJournal ::leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')->leftJoin( 'transactions', function (JoinClause $join) use ($operator) { $join->on('transaction_journals.id', '=', 'transactions.transaction_journal_id')->where('transactions.amount', $operator, '0'); @@ -280,9 +281,15 @@ class UpgradeDatabase extends Command ->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id') ->leftJoin('account_meta', 'account_meta.account_id', '=', 'accounts.id') ->where('transaction_types.type', $type) - ->where('account_meta.name', 'currency_id') - ->where('transaction_journals.transaction_currency_id', '!=', DB::raw('account_meta.data')) - ->get(['transaction_journals.*', 'account_meta.data as expected_currency_id', 'transactions.amount as transaction_amount']); + ->where('account_meta.name', 'currency_id'); + if($driver === 'postgresql') { + $query->where('transaction_journals.transaction_currency_id', '!=', DB::raw('cast(account_meta.data as int)')); + } + if($driver !== 'postgresql') { + $query->where('transaction_journals.transaction_currency_id', '!=', DB::raw('account_meta.data')); + } + + $set = $query->get(['transaction_journals.*', 'account_meta.data as expected_currency_id', 'transactions.amount as transaction_amount']); /** @var TransactionJournal $journal */ foreach ($set as $journal) { $expectedCurrency = $repository->find(intval($journal->expected_currency_id));