mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-25 08:09:38 +02:00
Preserve original transaction names when enriching (#1556)
* Preserve original transaction name * Remove stale method * Fix tests
This commit is contained in:
parent
68617514b0
commit
7be6a372bf
22 changed files with 100 additions and 76 deletions
37
db/migrate/20241218132503_add_enriched_name_field.rb
Normal file
37
db/migrate/20241218132503_add_enriched_name_field.rb
Normal 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
|
5
db/schema.rb
generated
5
db/schema.rb
generated
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.2].define(version: 2024_12_17_141716) do
|
||||
ActiveRecord::Schema[7.2].define(version: 2024_12_18_132503) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pgcrypto"
|
||||
enable_extension "plpgsql"
|
||||
|
@ -39,7 +39,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_12_17_141716) do
|
|||
t.decimal "amount", precision: 19, scale: 4
|
||||
t.string "currency"
|
||||
t.date "date"
|
||||
t.string "name"
|
||||
t.string "name", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.uuid "transfer_id"
|
||||
|
@ -49,6 +49,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_12_17_141716) do
|
|||
t.boolean "excluded", default: false
|
||||
t.string "plaid_id"
|
||||
t.datetime "enriched_at"
|
||||
t.string "enriched_name"
|
||||
t.index ["account_id"], name: "index_account_entries_on_account_id"
|
||||
t.index ["import_id"], name: "index_account_entries_on_import_id"
|
||||
t.index ["transfer_id"], name: "index_account_entries_on_transfer_id"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue