mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-22 19:34:18 +01:00
Mint: table locks (#566)
* clean up db * db: table lock * db.table_with_schema * fix encrypt.py * postgres nowait * add timeout to lock * melt quote state in db * kinda working * kinda working with postgres * remove dispose * getting there * porperly clean up db for tests * faster tests * configure connection pooling * try github with connection pool * invoice dispatcher does not lock db * fakewallet: pay_if_regtest waits * pay fakewallet invoices * add more * faster * slower * pay_if_regtest async * do not lock the invoice dispatcher * test: do I get disk I/O errors if we disable the invoice_callback_dispatcher? * fix fake so it workss without a callback dispatchert * test on github * readd tasks * refactor * increase time for lock invoice disatcher * try avoiding a race * remove task * github actions: test regtest with postgres * mint per module * no connection pool for testing * enable pool * do not resend paid event * reuse connection * close db connections * sessions * enable debug * dispose engine * disable connection pool for tests * enable connection pool for postgres only * clean up shutdown routine * remove wait for lightning fakewallet lightning invoice * cancel invoice listener tasks on shutdown * fakewallet conftest: decrease outgoing delay * delay payment and set postgres only if needed * disable fail fast for regtest * clean up regtest.yml * change order of tests_db.py * row-specific mint_quote locking * refactor * fix lock statement * refactor swap * refactor * remove psycopg2 * add connection string example to .env.example * remove unnecessary pay * shorter sleep in test_wallet_subscription_swap
This commit is contained in:
@@ -4,7 +4,7 @@ import time
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from ..core.db import COCKROACH, POSTGRES, SQLITE, Database, table_with_schema
|
||||
from ..core.db import COCKROACH, POSTGRES, SQLITE, Database
|
||||
from ..core.settings import settings
|
||||
|
||||
|
||||
@@ -47,10 +47,10 @@ async def migrate_databases(db: Database, migrations_module):
|
||||
async def set_migration_version(conn, db_name, version):
|
||||
await conn.execute(
|
||||
f"""
|
||||
INSERT INTO {table_with_schema(db, 'dbversions')} (db, version) VALUES (?, ?)
|
||||
ON CONFLICT (db) DO UPDATE SET version = ?
|
||||
INSERT INTO {db.table_with_schema('dbversions')} (db, version) VALUES (:db, :version)
|
||||
ON CONFLICT (db) DO UPDATE SET version = :version
|
||||
""",
|
||||
(db_name, version, version),
|
||||
{"db": db_name, "version": version},
|
||||
)
|
||||
|
||||
async def run_migration(db, migrations_module):
|
||||
@@ -89,20 +89,21 @@ async def migrate_databases(db: Database, migrations_module):
|
||||
if conn.type == SQLITE:
|
||||
exists = await conn.fetchone(
|
||||
"SELECT * FROM sqlite_master WHERE type='table' AND"
|
||||
f" name='{table_with_schema(db, 'dbversions')}'"
|
||||
f" name='{db.table_with_schema('dbversions')}'"
|
||||
)
|
||||
elif conn.type in {POSTGRES, COCKROACH}:
|
||||
exists = await conn.fetchone(
|
||||
"SELECT * FROM information_schema.tables WHERE table_name ="
|
||||
f" '{table_with_schema(db, 'dbversions')}'"
|
||||
f" '{db.table_with_schema('dbversions')}'"
|
||||
)
|
||||
|
||||
if not exists:
|
||||
await migrations_module.m000_create_migrations_table(conn)
|
||||
|
||||
rows = await (
|
||||
await conn.execute(f"SELECT * FROM {table_with_schema(db, 'dbversions')}")
|
||||
).fetchall()
|
||||
result = await conn.execute(
|
||||
f"SELECT * FROM {db.table_with_schema('dbversions')}"
|
||||
)
|
||||
rows = result.all()
|
||||
current_versions = {row["db"]: row["version"] for row in rows}
|
||||
matcher = re.compile(r"^m(\d\d\d)_")
|
||||
await run_migration(db, migrations_module)
|
||||
|
||||
Reference in New Issue
Block a user