-
-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from afadil/portfolio-refactoring
Portfolio refactoring
- Loading branch information
Showing
117 changed files
with
4,208 additions
and
3,260 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
-- This file should undo anything in `up.sql` | ||
|
||
DROP TABLE IF EXISTS goals_allocation; | ||
DROP TABLE IF EXISTS goals; | ||
DROP TABLE IF EXISTS settings; | ||
DROP TABLE IF EXISTS quotes; | ||
DROP TABLE IF EXISTS activities; | ||
DROP TABLE IF EXISTS assets; | ||
DROP TABLE IF EXISTS accounts; | ||
DROP TABLE IF EXISTS platforms; | ||
|
||
DROP INDEX IF EXISTS market_data_data_source_date_symbol_key; | ||
DROP INDEX IF EXISTS market_data_symbol_idx; | ||
DROP INDEX IF EXISTS assets_data_source_symbol_key; |
5 changes: 5 additions & 0 deletions
5
src-core/migrations/2024-09-16-023604_portfolio_history/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
DROP TABLE IF EXISTS portfolio_history; | ||
DROP INDEX IF EXISTS idx_portfolio_history_account_date; | ||
|
||
DROP TABLE IF EXISTS exchange_rates; | ||
DROP INDEX IF EXISTS idx_exchange_rates_currencies; |
44 changes: 44 additions & 0 deletions
44
src-core/migrations/2024-09-16-023604_portfolio_history/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
CREATE TABLE portfolio_history ( | ||
id TEXT NOT NULL PRIMARY KEY, | ||
account_id TEXT NOT NULL, | ||
date DATE NOT NULL, | ||
total_value NUMERIC NOT NULL DEFAULT 0, | ||
market_value NUMERIC NOT NULL DEFAULT 0, | ||
book_cost NUMERIC NOT NULL DEFAULT 0, | ||
available_cash NUMERIC NOT NULL DEFAULT 0, | ||
net_deposit NUMERIC NOT NULL DEFAULT 0, | ||
currency TEXT NOT NULL, | ||
base_currency TEXT NOT NULL, | ||
total_gain_value NUMERIC NOT NULL DEFAULT 0, | ||
total_gain_percentage NUMERIC NOT NULL DEFAULT 0, | ||
day_gain_percentage NUMERIC NOT NULL DEFAULT 0, | ||
day_gain_value NUMERIC NOT NULL DEFAULT 0, | ||
allocation_percentage NUMERIC NOT NULL DEFAULT 0, | ||
exchange_rate NUMERIC NOT NULL DEFAULT 0, | ||
holdings TEXT, | ||
UNIQUE(account_id, date) | ||
); | ||
CREATE INDEX idx_portfolio_history_account_date ON portfolio_history(account_id, date); | ||
|
||
-- change goals table column types | ||
ALTER TABLE "goals" ADD COLUMN "target_amount_new" NUMERIC NOT NULL DEFAULT 0; | ||
UPDATE "goals" SET "target_amount_new" = "target_amount"; | ||
ALTER TABLE "goals" DROP COLUMN "target_amount"; | ||
ALTER TABLE "goals" RENAME COLUMN "target_amount_new" TO "target_amount"; | ||
ALTER TABLE "goals" ADD COLUMN "is_achieved_new" BOOLEAN NOT NULL DEFAULT false; | ||
UPDATE "goals" SET "is_achieved_new" = COALESCE("is_achieved", false); | ||
ALTER TABLE "goals" DROP COLUMN "is_achieved"; | ||
ALTER TABLE "goals" RENAME COLUMN "is_achieved_new" TO "is_achieved"; | ||
|
||
CREATE TABLE exchange_rates ( | ||
id TEXT NOT NULL PRIMARY KEY, | ||
from_currency TEXT NOT NULL, | ||
to_currency TEXT NOT NULL, | ||
rate NUMERIC NOT NULL, | ||
source TEXT NOT NULL, | ||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
UNIQUE(from_currency, to_currency) | ||
); | ||
|
||
CREATE INDEX idx_exchange_rates_currencies ON exchange_rates(from_currency, to_currency); |
17 changes: 17 additions & 0 deletions
17
src-core/migrations/2024-09-21-023605_settings_to_kv/down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-- Create a temporary table with the original structure | ||
CREATE TABLE "settings" ( | ||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
theme TEXT NOT NULL DEFAULT 'light', | ||
font TEXT NOT NULL, | ||
base_currency TEXT NOT NULL | ||
); | ||
|
||
-- Migrate data back from app_settings to settings | ||
INSERT INTO settings (theme, font, base_currency) | ||
SELECT | ||
(SELECT setting_value FROM app_settings WHERE setting_key = 'theme'), | ||
(SELECT setting_value FROM app_settings WHERE setting_key = 'font'), | ||
(SELECT setting_value FROM app_settings WHERE setting_key = 'base_currency'); | ||
|
||
-- Drop the new app_settings table | ||
DROP TABLE "app_settings"; |
16 changes: 16 additions & 0 deletions
16
src-core/migrations/2024-09-21-023605_settings_to_kv/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-- Create the new app_settings table with key-value structure | ||
CREATE TABLE "app_settings" ( | ||
"setting_key" TEXT NOT NULL PRIMARY KEY, | ||
"setting_value" TEXT NOT NULL | ||
); | ||
|
||
-- Migrate existing settings to the new table | ||
INSERT INTO "app_settings" ("setting_key", "setting_value") | ||
SELECT 'theme', theme FROM settings | ||
UNION ALL | ||
SELECT 'font', font FROM settings | ||
UNION ALL | ||
SELECT 'base_currency', base_currency FROM settings; | ||
|
||
-- Drop the old settings table | ||
DROP TABLE "settings"; |
Empty file.
44 changes: 44 additions & 0 deletions
44
src-core/migrations/2024-09-22-012202_init_exchange_rates/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
-- Get the base currency from app_setting | ||
WITH base_currency AS ( | ||
SELECT setting_value AS currency | ||
FROM app_settings | ||
WHERE setting_key = 'base_currency' | ||
) | ||
|
||
-- Insert exchange rates for accounts | ||
INSERT OR IGNORE INTO exchange_rates (id, from_currency, to_currency, rate, source) | ||
SELECT | ||
base_currency.currency || accounts.currency || '=X' AS id, | ||
base_currency.currency, | ||
accounts.currency, | ||
1.0, -- Default rate, to be updated later | ||
'MANUAL' | ||
FROM accounts | ||
CROSS JOIN base_currency | ||
WHERE accounts.currency != base_currency.currency | ||
|
||
UNION | ||
|
||
-- Insert exchange rates for activities | ||
SELECT DISTINCT | ||
accounts.currency || activities.currency || '=X' AS id, | ||
accounts.currency, | ||
activities.currency, | ||
1.0, -- Default rate, to be updated later | ||
'MANUAL' | ||
FROM activities | ||
JOIN accounts ON activities.account_id = accounts.id | ||
WHERE activities.currency != accounts.currency | ||
|
||
UNION | ||
|
||
-- Insert exchange rates from base currency to activity currency | ||
SELECT DISTINCT | ||
base_currency.currency || activities.currency || '=X' AS id, | ||
base_currency.currency, | ||
activities.currency, | ||
1.0, -- Default rate, to be updated later | ||
'MANUAL' | ||
FROM activities | ||
CROSS JOIN base_currency | ||
WHERE activities.currency != base_currency.currency; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.