migrate to sqlalchemy-aio.

a big refactor that:

- fixes some issues that might have happened (or not) with asynchronous
    reactions to payments;
- paves the way to https://github.com/lnbits/lnbits/issues/121;
- uses more async/await notation which just looks nice; and
- makes it simple(r?) for one extension to modify stuff from other extensions.
This commit is contained in:
fiatjaf
2020-11-21 23:02:14 -03:00
parent f877dde2b0
commit d3fc52cd49
68 changed files with 971 additions and 1075 deletions
+11 -11
View File
@@ -1,11 +1,11 @@
from sqlite3 import OperationalError
from sqlalchemy.exc import OperationalError # type: ignore
def m001_initial(db):
async def m001_initial(db):
"""
Initial paywalls table.
"""
db.execute(
await db.execute(
"""
CREATE TABLE IF NOT EXISTS paywalls (
id TEXT PRIMARY KEY,
@@ -20,16 +20,16 @@ def m001_initial(db):
)
def m002_redux(db):
async def m002_redux(db):
"""
Creates an improved paywalls table and migrates the existing data.
"""
try:
db.execute("SELECT remembers FROM paywalls")
await db.execute("SELECT remembers FROM paywalls")
except OperationalError:
db.execute("ALTER TABLE paywalls RENAME TO paywalls_old")
db.execute(
await db.execute("ALTER TABLE paywalls RENAME TO paywalls_old")
await db.execute(
"""
CREATE TABLE IF NOT EXISTS paywalls (
id TEXT PRIMARY KEY,
@@ -44,10 +44,10 @@ def m002_redux(db):
);
"""
)
db.execute("CREATE INDEX IF NOT EXISTS wallet_idx ON paywalls (wallet)")
await db.execute("CREATE INDEX IF NOT EXISTS wallet_idx ON paywalls (wallet)")
for row in [list(row) for row in db.fetchall("SELECT * FROM paywalls_old")]:
db.execute(
for row in [list(row) for row in await db.fetchall("SELECT * FROM paywalls_old")]:
await db.execute(
"""
INSERT INTO paywalls (
id,
@@ -62,4 +62,4 @@ def m002_redux(db):
(row[0], row[1], row[3], row[4], row[5], row[6]),
)
db.execute("DROP TABLE paywalls_old")
await db.execute("DROP TABLE paywalls_old")