1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-02 20:15:22 +02:00

Preserve original transaction names when enriching (#1556)
Some checks are pending
Publish Docker image / ci (push) Waiting to run
Publish Docker image / Build docker image (push) Blocked by required conditions

* Preserve original transaction name

* Remove stale method

* Fix tests
This commit is contained in:
Zach Gollwitzer 2024-12-19 10:16:09 -05:00 committed by GitHub
parent 68617514b0
commit 7be6a372bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 100 additions and 76 deletions

View file

@ -0,0 +1,37 @@
class AddEnrichedNameField < ActiveRecord::Migration[7.2]
def change
add_column :account_entries, :enriched_name, :string
reversible do |dir|
dir.up do
execute <<-SQL
UPDATE account_entries ae
SET name = CASE ae.entryable_type
WHEN 'Account::Trade' THEN
CASE
WHEN EXISTS (
SELECT 1 FROM account_trades t
WHERE t.id = ae.entryable_id AND t.qty < 0
) THEN 'Sell trade'
ELSE 'Buy trade'
END
WHEN 'Account::Transaction' THEN
CASE
WHEN ae.amount > 0 THEN 'Expense'
ELSE 'Income'
END
WHEN 'Account::Valuation' THEN 'Balance update'
ELSE 'Unknown entry'
END
WHERE name IS NULL
SQL
change_column_null :account_entries, :name, false
end
dir.down do
change_column_null :account_entries, :name, true
end
end
end
end