feat: update to lnbits 1.0.0 (#27)
* feat: update to lnbits 1.0.0 * fix select wallet * fix splits * fix: types, postgres errors with cache --------- Co-authored-by: Tiago Vasconcelos <talvasconcelos@gmail.com>
This commit is contained in:
parent
32bf4ae1d6
commit
5042d40af6
11 changed files with 1300 additions and 1218 deletions
|
|
@ -1,7 +1,8 @@
|
|||
from lnbits.db import Connection
|
||||
from lnbits.helpers import urlsafe_short_hash
|
||||
|
||||
|
||||
async def m001_initial(db):
|
||||
async def m001_initial(db: Connection):
|
||||
"""
|
||||
Initial split payment table.
|
||||
"""
|
||||
|
|
@ -19,49 +20,24 @@ async def m001_initial(db):
|
|||
)
|
||||
|
||||
|
||||
async def m002_float_percent(db):
|
||||
async def m002_float_percent(db: Connection):
|
||||
"""
|
||||
Add float percent and migrates the existing data.
|
||||
"""
|
||||
await db.execute("ALTER TABLE splitpayments.targets RENAME TO splitpayments_old")
|
||||
await db.execute(
|
||||
"""
|
||||
CREATE TABLE splitpayments.targets (
|
||||
wallet TEXT NOT NULL,
|
||||
source TEXT NOT NULL,
|
||||
percent REAL NOT NULL CHECK (percent >= 0 AND percent <= 100),
|
||||
alias TEXT,
|
||||
|
||||
UNIQUE (source, wallet)
|
||||
);
|
||||
"""
|
||||
ALTER TABLE splitpayments.targets
|
||||
ADD COLUMN percent REAL NOT NULL CHECK (percent >= 0 AND percent <= 100)
|
||||
"""
|
||||
)
|
||||
|
||||
for row in [
|
||||
list(row)
|
||||
for row in await db.fetchall("SELECT * FROM splitpayments.splitpayments_old")
|
||||
]:
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO splitpayments.targets (
|
||||
wallet,
|
||||
source,
|
||||
percent,
|
||||
alias
|
||||
)
|
||||
VALUES (?, ?, ?, ?)
|
||||
""",
|
||||
(row[0], row[1], row[2], row[3]),
|
||||
)
|
||||
|
||||
await db.execute("DROP TABLE splitpayments.splitpayments_old")
|
||||
|
||||
|
||||
async def m003_add_id_and_tag(db):
|
||||
async def m003_add_id_and_tag(db: Connection):
|
||||
"""
|
||||
Add float percent and migrates the existing data.
|
||||
Add id, tag and migrates the existing data.
|
||||
"""
|
||||
await db.execute("ALTER TABLE splitpayments.targets RENAME TO splitpayments_old")
|
||||
await db.execute("ALTER TABLE splitpayments.targets RENAME TO splitpayments_m002")
|
||||
|
||||
await db.execute(
|
||||
"""
|
||||
CREATE TABLE splitpayments.targets (
|
||||
|
|
@ -76,11 +52,9 @@ async def m003_add_id_and_tag(db):
|
|||
);
|
||||
"""
|
||||
)
|
||||
|
||||
for row in [
|
||||
list(row)
|
||||
for row in await db.fetchall("SELECT * FROM splitpayments.splitpayments_old")
|
||||
]:
|
||||
result = await db.execute("SELECT * FROM splitpayments.splitpayments_m002")
|
||||
rows = result.mappings().all()
|
||||
for row in rows:
|
||||
await db.execute(
|
||||
"""
|
||||
INSERT INTO splitpayments.targets (
|
||||
|
|
@ -91,23 +65,31 @@ async def m003_add_id_and_tag(db):
|
|||
tag,
|
||||
alias
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
VALUES (:id, :wallet, :source, :percent, :tag, :alias)
|
||||
""",
|
||||
(urlsafe_short_hash(), row[0], row[1], row[2], "", row[3]),
|
||||
{
|
||||
"id": urlsafe_short_hash(),
|
||||
"wallet": row["wallet"],
|
||||
"source": row["source"],
|
||||
"percent": row["percent"],
|
||||
"tag": row["tag"],
|
||||
"alias": row["alias"],
|
||||
},
|
||||
)
|
||||
|
||||
await db.execute("DROP TABLE splitpayments.splitpayments_old")
|
||||
await db.execute("DROP TABLE splitpayments.splitpayments_m002")
|
||||
|
||||
|
||||
async def m004_remove_tag(db):
|
||||
async def m004_remove_tag(db: Connection):
|
||||
"""
|
||||
This removes tag
|
||||
"""
|
||||
keys = "id,wallet,source,percent,alias"
|
||||
new_db = "splitpayments.targets"
|
||||
old_db = "splitpayments.targets_old"
|
||||
old_db = "splitpayments.targets_m003"
|
||||
|
||||
await db.execute(f"ALTER TABLE {new_db} RENAME TO targets_m003")
|
||||
|
||||
await db.execute(f"ALTER TABLE {new_db} RENAME TO targets_old")
|
||||
await db.execute(
|
||||
f"""
|
||||
CREATE TABLE {new_db} (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue