diff --git a/database.py b/database.py index 3f0c6bc..db22e35 100644 --- a/database.py +++ b/database.py @@ -86,7 +86,7 @@ def apply_schema(conn=None): def seed_defaults(conn=None): - """Insert the default settings and the seeded rates. Idempotent.""" + """Insert the default settings, the seeded rates and the bank. Idempotent.""" own = conn is None if own: conn = connect() @@ -101,6 +101,20 @@ def seed_defaults(conn=None): " VALUES ('BTC', ?, ?, ?)", (date, nok_per_btc_ore, SETTING_DEFAULTS["year_end_price_source"]), ) + # The bank holds no sats and is nobody's holding (section 3.11). + conn.execute( + "INSERT OR IGNORE INTO markets (name, kind, taxable, archived)" + " VALUES (?, ?, 0, 1)", + (BANK_NAME, BANK_KIND), + ) + row = conn.execute( + "SELECT id FROM markets WHERE name = ?", (BANK_NAME,) + ).fetchone() + if row is not None: + conn.execute( + "INSERT OR IGNORE INTO settings (key, value) VALUES ('bank_market_id', ?)", + (str(row["id"]),), + ) conn.commit() finally: if own: