mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-02 20:15:22 +02:00
Multi-Currency Part 2 (#543)
* Support all currencies, handle outside DB * Remove currencies from seed * Fix account balance namespace * Set default currency on authentication * Cache currency instances * Implement multi-currency syncs with tests * Series fallback, passing tests * Fix conflicts * Make value group concrete class that works with currency values * Fix migration conflict * Update tests to expect multi-currency results * Update account list to use group method * Namespace updates * Fetch unknown exchange rates from API * Fix date range bug * Ensure demo data works without external API * Enforce cascades only at DB level
This commit is contained in:
parent
de0cba9fed
commit
110855d077
55 changed files with 1226 additions and 714 deletions
5
db/migrate/20240308121431_remove_currency_table.rb
Normal file
5
db/migrate/20240308121431_remove_currency_table.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class RemoveCurrencyTable < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
drop_table :currencies
|
||||
end
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
class UpdateUniqueIndexesForAccountBalanceAndExchangeRate < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
rename_index :exchange_rates, 'idx_on_base_currency_converted_currency_date_255be792be', 'index_exchange_rates_on_base_converted_date_unique'
|
||||
remove_index :account_balances, name: "index_account_balances_on_account_id_and_date"
|
||||
add_index :account_balances, [ :account_id, :date, :currency ], unique: true, name: "index_account_balances_on_account_id_date_currency_unique"
|
||||
end
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
class RemoveConvertedBalanceFromAccount < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
remove_column :accounts, :converted_balance, :decimal
|
||||
remove_column :accounts, :converted_currency, :string
|
||||
end
|
||||
end
|
14
db/schema.rb
generated
14
db/schema.rb
generated
|
@ -26,7 +26,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_03_19_154732) do
|
|||
t.string "currency", default: "USD", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["account_id", "date"], name: "index_account_balances_on_account_id_and_date", unique: true
|
||||
t.index ["account_id", "date", "currency"], name: "index_account_balances_on_account_id_date_currency_unique", unique: true
|
||||
t.index ["account_id"], name: "index_account_balances_on_account_id"
|
||||
end
|
||||
|
||||
|
@ -85,8 +85,6 @@ ActiveRecord::Schema[7.2].define(version: 2024_03_19_154732) do
|
|||
t.uuid "accountable_id"
|
||||
t.decimal "balance", precision: 19, scale: 4, default: "0.0"
|
||||
t.string "currency", default: "USD"
|
||||
t.decimal "converted_balance", precision: 19, scale: 4, default: "0.0"
|
||||
t.string "converted_currency", default: "USD"
|
||||
t.virtual "classification", type: :string, as: "\nCASE\n WHEN ((accountable_type)::text = ANY ((ARRAY['Account::Loan'::character varying, 'Account::Credit'::character varying, 'Account::OtherLiability'::character varying])::text[])) THEN 'liability'::text\n ELSE 'asset'::text\nEND", stored: true
|
||||
t.boolean "is_active", default: true, null: false
|
||||
t.enum "status", default: "ok", null: false, enum_type: "account_status"
|
||||
|
@ -96,14 +94,6 @@ ActiveRecord::Schema[7.2].define(version: 2024_03_19_154732) do
|
|||
t.index ["family_id"], name: "index_accounts_on_family_id"
|
||||
end
|
||||
|
||||
create_table "currencies", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "iso_code"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["iso_code"], name: "index_currencies_on_iso_code", unique: true
|
||||
end
|
||||
|
||||
create_table "exchange_rates", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.string "base_currency", null: false
|
||||
t.string "converted_currency", null: false
|
||||
|
@ -111,7 +101,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_03_19_154732) do
|
|||
t.date "date"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["base_currency", "converted_currency", "date"], name: "idx_on_base_currency_converted_currency_date_255be792be", unique: true
|
||||
t.index ["base_currency", "converted_currency", "date"], name: "index_exchange_rates_on_base_converted_date_unique", unique: true
|
||||
t.index ["base_currency"], name: "index_exchange_rates_on_base_currency"
|
||||
t.index ["converted_currency"], name: "index_exchange_rates_on_converted_currency"
|
||||
end
|
||||
|
|
|
@ -2,7 +2,4 @@
|
|||
# development, test). The code here should be idempotent so that it can be executed at any point in every environment.
|
||||
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
|
||||
|
||||
# Create default currency
|
||||
Currency.find_or_create_by(iso_code: "USD", name: "United States Dollar")
|
||||
|
||||
puts 'Run the following command to create demo data: `rake demo_data:reset`' if Rails.env.development?
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue