Migrate interest positions and deactivate obsolete assets

This commit is contained in:
kai
2026-09-09 11:56:24 +02:00
parent ad452045be
commit 1db3b008ec
3 changed files with 77 additions and 2 deletions
+21 -1
View File
@@ -71,10 +71,30 @@ def initialize(path=None):
entry_id INTEGER REFERENCES income_entries(id) ON DELETE SET NULL,
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
);
PRAGMA user_version = 1;
CREATE TABLE IF NOT EXISTS data_migrations (
name TEXT PRIMARY KEY,
applied_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
);
''')
db.execute('BEGIN IMMEDIATE')
if first_setup:
for name, kind in [('AGNC','stock'), ('Main Street Capital','stock'), ('Capital Southwest','stock'),
('Ares Capital','stock'), ('Realty Income','stock'), ('Enbridge','stock'),
('Bayer','stock'), ('STOXX Global Select Dividend 100','etf'), ('airBaltic','bond')]:
ensure_asset(db, name, kind)
_update_interest_positions(db)
if db.execute('PRAGMA user_version').fetchone()[0] < 2:
db.execute('PRAGMA user_version = 2')
def _update_interest_positions(db):
"""Apply the requested position changes once, preserving all income history."""
migration = '2026-09-09-interest-positions'
if db.execute('SELECT 1 FROM data_migrations WHERE name=?', (migration,)).fetchone():
return
for name, kind in [('Anleihezinsen', 'bond'), ('Zinsen NG', 'interest')]:
asset_id = ensure_asset(db, name, kind)
db.execute('UPDATE assets SET active=1 WHERE id=?', (asset_id,))
db.execute('UPDATE assets SET active=0 WHERE normalized_name IN (?,?)',
(name_key('Zinsen'), name_key('Steuerrückzahlung')))
db.execute('INSERT INTO data_migrations (name) VALUES (?)', (migration,))