mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 15:49:39 +02:00
Account namespace updates: part 1 (#893)
* Rename accountable types * Merge conflicts * Fix broken tests * Add back sidebar changes
This commit is contained in:
parent
778098ebb0
commit
a947db92b2
54 changed files with 349 additions and 184 deletions
87
db/migrate/20240619125949_rename_accountable_tables.rb
Normal file
87
db/migrate/20240619125949_rename_accountable_tables.rb
Normal file
|
@ -0,0 +1,87 @@
|
|||
class RenameAccountableTables < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
rename_table :account_depositories, :depositories
|
||||
rename_table :account_investments, :investments
|
||||
rename_table :account_credits, :credit_cards
|
||||
rename_table :account_properties, :properties
|
||||
rename_table :account_vehicles, :vehicles
|
||||
rename_table :account_loans, :loans
|
||||
rename_table :account_cryptos, :cryptos
|
||||
rename_table :account_other_assets, :other_assets
|
||||
rename_table :account_other_liabilities, :other_liabilities
|
||||
|
||||
reversible do |dir|
|
||||
dir.up do
|
||||
update_accountable_types(
|
||||
'Account::Depository' => 'Depository',
|
||||
'Account::Investment' => 'Investment',
|
||||
'Account::Credit' => 'CreditCard',
|
||||
'Account::Property' => 'Property',
|
||||
'Account::Vehicle' => 'Vehicle',
|
||||
'Account::Loan' => 'Loan',
|
||||
'Account::Crypto' => 'Crypto',
|
||||
'Account::OtherAsset' => 'OtherAsset',
|
||||
'Account::OtherLiability' => 'OtherLiability'
|
||||
)
|
||||
|
||||
remove_column :accounts, :classification, :virtual
|
||||
|
||||
change_table :accounts do |t|
|
||||
t.virtual(
|
||||
:classification,
|
||||
type: :string,
|
||||
stored: true,
|
||||
as: <<-SQL
|
||||
CASE
|
||||
WHEN accountable_type IN ('Loan', 'CreditCard', 'OtherLiability')
|
||||
THEN 'liability'
|
||||
ELSE 'asset'
|
||||
END
|
||||
SQL
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
dir.down do
|
||||
update_accountable_types(
|
||||
'Depository' => 'Account::Depository',
|
||||
'Investment' => 'Account::Investment',
|
||||
'CreditCard' => 'Account::Credit',
|
||||
'Property' => 'Account::Property',
|
||||
'Vehicle' => 'Account::Vehicle',
|
||||
'Loan' => 'Account::Loan',
|
||||
'Crypto' => 'Account::Crypto',
|
||||
'OtherAsset' => 'Account::OtherAsset',
|
||||
'OtherLiability' => 'Account::OtherLiability'
|
||||
)
|
||||
|
||||
remove_column :accounts, :classification, :virtual
|
||||
|
||||
change_table :accounts do |t|
|
||||
t.virtual(
|
||||
:classification,
|
||||
type: :string,
|
||||
stored: true,
|
||||
as: <<-SQL
|
||||
CASE
|
||||
WHEN accountable_type IN ('Account::Loan', 'Account::Credit', 'Account::OtherLiability')
|
||||
THEN 'liability'
|
||||
ELSE 'asset'
|
||||
END
|
||||
SQL
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_accountable_types(mapping)
|
||||
Account.reset_column_information
|
||||
|
||||
mapping.each do |old_type, new_type|
|
||||
Account.where(accountable_type: old_type).update_all(accountable_type: new_type)
|
||||
end
|
||||
end
|
||||
end
|
94
db/schema.rb
generated
94
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_06_14_121110) do
|
||||
ActiveRecord::Schema[7.2].define(version: 2024_06_19_125949) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pgcrypto"
|
||||
enable_extension "plpgsql"
|
||||
|
@ -32,51 +32,6 @@ ActiveRecord::Schema[7.2].define(version: 2024_06_14_121110) do
|
|||
t.index ["account_id"], name: "index_account_balances_on_account_id"
|
||||
end
|
||||
|
||||
create_table "account_credits", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "account_cryptos", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "account_depositories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "account_investments", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "account_loans", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "account_other_assets", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "account_other_liabilities", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "account_properties", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "account_vehicles", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "accounts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.string "subtype"
|
||||
t.uuid "family_id", null: false
|
||||
|
@ -87,13 +42,13 @@ ActiveRecord::Schema[7.2].define(version: 2024_06_14_121110) do
|
|||
t.uuid "accountable_id"
|
||||
t.decimal "balance", precision: 19, scale: 4, default: "0.0"
|
||||
t.string "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"
|
||||
t.jsonb "sync_warnings", default: [], null: false
|
||||
t.jsonb "sync_errors", default: [], null: false
|
||||
t.date "last_sync_date"
|
||||
t.uuid "institution_id"
|
||||
t.virtual "classification", type: :string, as: "\nCASE\n WHEN ((accountable_type)::text = ANY ((ARRAY['Loan'::character varying, 'CreditCard'::character varying, 'OtherLiability'::character varying])::text[])) THEN 'liability'::text\n ELSE 'asset'::text\nEND", stored: true
|
||||
t.index ["accountable_type"], name: "index_accounts_on_accountable_type"
|
||||
t.index ["family_id"], name: "index_accounts_on_family_id"
|
||||
t.index ["institution_id"], name: "index_accounts_on_institution_id"
|
||||
|
@ -127,6 +82,21 @@ ActiveRecord::Schema[7.2].define(version: 2024_06_14_121110) do
|
|||
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
|
||||
end
|
||||
|
||||
create_table "credit_cards", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "cryptos", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "depositories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
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
|
||||
|
@ -245,6 +215,11 @@ ActiveRecord::Schema[7.2].define(version: 2024_06_14_121110) do
|
|||
t.index ["family_id"], name: "index_institutions_on_family_id"
|
||||
end
|
||||
|
||||
create_table "investments", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "invite_codes", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.string "token", null: false
|
||||
t.datetime "created_at", null: false
|
||||
|
@ -252,6 +227,26 @@ ActiveRecord::Schema[7.2].define(version: 2024_06_14_121110) do
|
|||
t.index ["token"], name: "index_invite_codes_on_token", unique: true
|
||||
end
|
||||
|
||||
create_table "loans", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "other_assets", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "other_liabilities", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "properties", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "settings", force: :cascade do |t|
|
||||
t.string "var", null: false
|
||||
t.text "value"
|
||||
|
@ -351,6 +346,11 @@ ActiveRecord::Schema[7.2].define(version: 2024_06_14_121110) do
|
|||
t.index ["account_id"], name: "index_valuations_on_account_id"
|
||||
end
|
||||
|
||||
create_table "vehicles", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
add_foreign_key "account_balances", "accounts", on_delete: :cascade
|
||||
add_foreign_key "accounts", "families"
|
||||
add_foreign_key "accounts", "institutions"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue