Skip to content

Commit 5249bcf

Browse files
committed
fix: add base-case CREATE TABLE for balances in _ensure_schema
On a fresh empty SQLite database, _ensure_schema() assumed the balances table already existed. It would immediately fail at PRAGMA table_info(balances) and then attempt ALTER TABLE balances on a non-existent table, causing sqlite3.OperationalError: no such table: balances across all 15 tests in test_tx_handler_limits.py. Add CREATE TABLE IF NOT EXISTS balances as the first step so _ensure_schema() is idempotent on both fresh and migrated databases.
1 parent 8cf462f commit 5249bcf

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

node/rustchain_tx_handler.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ def _ensure_schema(self):
109109
with sqlite3.connect(self.db_path) as conn:
110110
cursor = conn.cursor()
111111

112+
# Base case: create the balances table if it doesn't exist at all.
113+
# The migration steps below assume the table already exists (ALTER TABLE,
114+
# PRAGMA table_info, etc.), so a fresh empty DB would fail without this.
115+
cursor.execute("""
116+
CREATE TABLE IF NOT EXISTS balances (
117+
wallet TEXT PRIMARY KEY,
118+
balance_urtc INTEGER NOT NULL DEFAULT 0,
119+
wallet_nonce INTEGER DEFAULT 0
120+
)
121+
""")
122+
conn.commit()
123+
112124
# Check if wallet_nonce column exists
113125
cursor.execute("PRAGMA table_info(balances)")
114126
columns = [col[1] for col in cursor.fetchall()]

0 commit comments

Comments
 (0)