mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-27 12:26:19 +02:00
Revert "add UUID as id instead of sequential integer"
This commit is contained in:
@@ -1,18 +1,19 @@
|
|||||||
from typing import List, Optional, Union
|
from typing import List, Optional, Union
|
||||||
|
|
||||||
from lnbits.helpers import urlsafe_short_hash
|
from lnbits.db import SQLITE
|
||||||
|
|
||||||
from . import db
|
from . import db
|
||||||
from .models import CreatePayLinkData, PayLink
|
from .models import CreatePayLinkData, PayLink
|
||||||
|
|
||||||
|
|
||||||
async def create_pay_link(data: CreatePayLinkData, wallet_id: str) -> PayLink:
|
async def create_pay_link(data: CreatePayLinkData, wallet_id: str) -> PayLink:
|
||||||
link_id = urlsafe_short_hash()
|
|
||||||
|
|
||||||
result = await db.execute(
|
returning = "" if db.type == SQLITE else "RETURNING ID"
|
||||||
|
method = db.execute if db.type == SQLITE else db.fetchone
|
||||||
|
|
||||||
|
result = await (method)(
|
||||||
f"""
|
f"""
|
||||||
INSERT INTO lnurlp.pay_links (
|
INSERT INTO lnurlp.pay_links (
|
||||||
id,
|
|
||||||
wallet,
|
wallet,
|
||||||
description,
|
description,
|
||||||
min,
|
min,
|
||||||
@@ -28,11 +29,10 @@ async def create_pay_link(data: CreatePayLinkData, wallet_id: str) -> PayLink:
|
|||||||
currency,
|
currency,
|
||||||
fiat_base_multiplier
|
fiat_base_multiplier
|
||||||
)
|
)
|
||||||
VALUES (?, ?, ?, ?, ?, 0, 0, ?, ?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, 0, 0, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
{returning}
|
{returning}
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
link_id,
|
|
||||||
wallet_id,
|
wallet_id,
|
||||||
data.description,
|
data.description,
|
||||||
data.min,
|
data.min,
|
||||||
@@ -47,6 +47,10 @@ async def create_pay_link(data: CreatePayLinkData, wallet_id: str) -> PayLink:
|
|||||||
data.fiat_base_multiplier,
|
data.fiat_base_multiplier,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
if db.type == SQLITE:
|
||||||
|
link_id = result._result_proxy.lastrowid
|
||||||
|
else:
|
||||||
|
link_id = result[0]
|
||||||
|
|
||||||
link = await get_pay_link(link_id)
|
link = await get_pay_link(link_id)
|
||||||
assert link, "Newly created link couldn't be retrieved"
|
assert link, "Newly created link couldn't be retrieved"
|
||||||
|
@@ -68,76 +68,3 @@ async def m005_webhook_headers_and_body(db):
|
|||||||
"""
|
"""
|
||||||
await db.execute("ALTER TABLE lnurlp.pay_links ADD COLUMN webhook_headers TEXT;")
|
await db.execute("ALTER TABLE lnurlp.pay_links ADD COLUMN webhook_headers TEXT;")
|
||||||
await db.execute("ALTER TABLE lnurlp.pay_links ADD COLUMN webhook_body TEXT;")
|
await db.execute("ALTER TABLE lnurlp.pay_links ADD COLUMN webhook_body TEXT;")
|
||||||
|
|
||||||
|
|
||||||
async def m006_redux(db):
|
|
||||||
"""
|
|
||||||
Add UUID ID's to links and migrates existing data
|
|
||||||
"""
|
|
||||||
await db.execute("ALTER TABLE lnurlp.pay_links RENAME TO pay_links_old")
|
|
||||||
await db.execute(
|
|
||||||
f"""
|
|
||||||
CREATE TABLE lnurlp.pay_links (
|
|
||||||
id TEXT PRIMARY KEY,
|
|
||||||
wallet TEXT NOT NULL,
|
|
||||||
description TEXT NOT NULL,
|
|
||||||
min INTEGER NOT NULL,
|
|
||||||
max INTEGER,
|
|
||||||
currency TEXT,
|
|
||||||
fiat_base_multiplier INTEGER DEFAULT 1,
|
|
||||||
served_meta INTEGER NOT NULL,
|
|
||||||
served_pr INTEGER NOT NULL,
|
|
||||||
webhook_url TEXT,
|
|
||||||
success_text TEXT,
|
|
||||||
success_url TEXT,
|
|
||||||
comment_chars INTEGER DEFAULT 0,
|
|
||||||
webhook_headers TEXT,
|
|
||||||
webhook_body TEXT
|
|
||||||
);
|
|
||||||
"""
|
|
||||||
)
|
|
||||||
|
|
||||||
for row in [
|
|
||||||
list(row) for row in await db.fetchall("SELECT * FROM lnurlp.pay_links_old")
|
|
||||||
]:
|
|
||||||
await db.execute(
|
|
||||||
"""
|
|
||||||
INSERT INTO lnurlp.pay_links (
|
|
||||||
id,
|
|
||||||
wallet,
|
|
||||||
description,
|
|
||||||
min,
|
|
||||||
served_meta,
|
|
||||||
served_pr,
|
|
||||||
webhook_url,
|
|
||||||
success_text,
|
|
||||||
success_url,
|
|
||||||
currency,
|
|
||||||
comment_chars,
|
|
||||||
max,
|
|
||||||
fiat_base_multiplier,
|
|
||||||
webhook_headers,
|
|
||||||
webhook_body
|
|
||||||
)
|
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
||||||
""",
|
|
||||||
(
|
|
||||||
row[0],
|
|
||||||
row[1],
|
|
||||||
row[2],
|
|
||||||
row[3],
|
|
||||||
row[4],
|
|
||||||
row[5],
|
|
||||||
row[6],
|
|
||||||
row[7],
|
|
||||||
row[8],
|
|
||||||
row[9],
|
|
||||||
row[10],
|
|
||||||
row[11],
|
|
||||||
row[12],
|
|
||||||
row[13],
|
|
||||||
row[14],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
await db.execute("DROP TABLE lnurlp.pay_links_old")
|
|
||||||
|
@@ -26,7 +26,7 @@ class CreatePayLinkData(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class PayLink(BaseModel):
|
class PayLink(BaseModel):
|
||||||
id: str
|
id: int
|
||||||
wallet: str
|
wallet: str
|
||||||
description: str
|
description: str
|
||||||
min: float
|
min: float
|
||||||
|
Reference in New Issue
Block a user