fix schemas for admin
This commit is contained in:
parent
3f38a9094b
commit
0a29fb7360
|
@ -55,8 +55,12 @@ def bundle_vendored():
|
||||||
async def get_admin_settings():
|
async def get_admin_settings():
|
||||||
from lnbits.extensions.admin.models import Admin
|
from lnbits.extensions.admin.models import Admin
|
||||||
|
|
||||||
async with core_db.connect() as conn:
|
try:
|
||||||
|
ext_db = importlib.import_module(f"lnbits.extensions.admin").db
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
|
async with ext_db.connect() as conn:
|
||||||
if conn.type == SQLITE:
|
if conn.type == SQLITE:
|
||||||
exists = await conn.fetchone(
|
exists = await conn.fetchone(
|
||||||
"SELECT * FROM sqlite_master WHERE type='table' AND name='admin'"
|
"SELECT * FROM sqlite_master WHERE type='table' AND name='admin'"
|
||||||
|
@ -65,10 +69,11 @@ async def get_admin_settings():
|
||||||
exists = await conn.fetchone(
|
exists = await conn.fetchone(
|
||||||
"SELECT * FROM information_schema.tables WHERE table_name = 'admin'"
|
"SELECT * FROM information_schema.tables WHERE table_name = 'admin'"
|
||||||
)
|
)
|
||||||
|
print("EXISTS", exists)
|
||||||
if not exists:
|
if not exists:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
row = await conn.fetchone("SELECT * from admin")
|
row = await conn.fetchone("SELECT * from admin.admin")
|
||||||
|
|
||||||
return Admin(**row) if row else None
|
return Admin(**row) if row else None
|
||||||
|
|
||||||
|
|
|
@ -29,30 +29,30 @@ async def update_admin(user: str, **kwargs) -> Admin:
|
||||||
q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()])
|
q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()])
|
||||||
# print("UPDATE", q)
|
# print("UPDATE", q)
|
||||||
await db.execute(
|
await db.execute(
|
||||||
f'UPDATE admin SET {q} WHERE "user" = ?', (*kwargs.values(), user)
|
f'UPDATE admin.admin SET {q} WHERE "user" = ?', (*kwargs.values(), user)
|
||||||
)
|
)
|
||||||
row = await db.fetchone('SELECT * FROM admin WHERE "user" = ?', (user,))
|
row = await db.fetchone('SELECT * FROM admin.admin WHERE "user" = ?', (user,))
|
||||||
assert row, "Newly updated settings couldn't be retrieved"
|
assert row, "Newly updated settings couldn't be retrieved"
|
||||||
return Admin(**row) if row else None
|
return Admin(**row) if row else None
|
||||||
|
|
||||||
async def get_admin() -> Admin:
|
async def get_admin() -> Admin:
|
||||||
row = await db.fetchone("SELECT * FROM admin")
|
row = await db.fetchone("SELECT * FROM admin.admin")
|
||||||
return Admin(**row) if row else None
|
return Admin(**row) if row else None
|
||||||
|
|
||||||
async def update_funding(data: Funding) -> Funding:
|
async def update_funding(data: Funding) -> Funding:
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
UPDATE funding
|
UPDATE admin.funding
|
||||||
SET backend_wallet = ?, endpoint = ?, port = ?, read_key = ?, invoice_key = ?, admin_key = ?, cert = ?, balance = ?, selected = ?
|
SET backend_wallet = ?, endpoint = ?, port = ?, read_key = ?, invoice_key = ?, admin_key = ?, cert = ?, balance = ?, selected = ?
|
||||||
WHERE id = ?
|
WHERE id = ?
|
||||||
""",
|
""",
|
||||||
(data.backend_wallet, data.endpoint, data.port, data.read_key, data.invoice_key, data.admin_key, data.cert, data.balance, data.selected, data.id,),
|
(data.backend_wallet, data.endpoint, data.port, data.read_key, data.invoice_key, data.admin_key, data.cert, data.balance, data.selected, data.id,),
|
||||||
)
|
)
|
||||||
row = await db.fetchone('SELECT * FROM funding WHERE "id" = ?', (data.id,))
|
row = await db.fetchone('SELECT * FROM admin.funding WHERE "id" = ?', (data.id,))
|
||||||
assert row, "Newly updated settings couldn't be retrieved"
|
assert row, "Newly updated settings couldn't be retrieved"
|
||||||
return Funding(**row) if row else None
|
return Funding(**row) if row else None
|
||||||
|
|
||||||
async def get_funding() -> List[Funding]:
|
async def get_funding() -> List[Funding]:
|
||||||
rows = await db.fetchall("SELECT * FROM funding")
|
rows = await db.fetchall("SELECT * FROM admin.funding")
|
||||||
|
|
||||||
return [Funding(**row) for row in rows]
|
return [Funding(**row) for row in rows]
|
||||||
|
|
|
@ -96,7 +96,7 @@ async def m001_create_admin_table(db):
|
||||||
|
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
CREATE TABLE IF NOT EXISTS admin (
|
CREATE TABLE IF NOT EXISTS admin.admin (
|
||||||
"user" TEXT PRIMARY KEY,
|
"user" TEXT PRIMARY KEY,
|
||||||
admin_users TEXT,
|
admin_users TEXT,
|
||||||
allowed_users TEXT,
|
allowed_users TEXT,
|
||||||
|
@ -120,7 +120,7 @@ async def m001_create_admin_table(db):
|
||||||
)
|
)
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO admin (
|
INSERT INTO admin.admin (
|
||||||
"user",
|
"user",
|
||||||
admin_users,
|
admin_users,
|
||||||
allowed_users,
|
allowed_users,
|
||||||
|
@ -171,7 +171,7 @@ async def m001_create_funding_table(db):
|
||||||
# Make the funding table, if it does not already exist
|
# Make the funding table, if it does not already exist
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
CREATE TABLE IF NOT EXISTS funding (
|
CREATE TABLE IF NOT EXISTS admin.funding (
|
||||||
id TEXT PRIMARY KEY,
|
id TEXT PRIMARY KEY,
|
||||||
backend_wallet TEXT,
|
backend_wallet TEXT,
|
||||||
endpoint TEXT,
|
endpoint TEXT,
|
||||||
|
@ -188,7 +188,7 @@ async def m001_create_funding_table(db):
|
||||||
|
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO funding (id, backend_wallet, endpoint, selected)
|
INSERT INTO admin.funding (id, backend_wallet, endpoint, selected)
|
||||||
VALUES (?, ?, ?, ?)
|
VALUES (?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
|
@ -200,7 +200,7 @@ async def m001_create_funding_table(db):
|
||||||
)
|
)
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO funding (id, backend_wallet, endpoint, admin_key, selected)
|
INSERT INTO admin.funding (id, backend_wallet, endpoint, admin_key, selected)
|
||||||
VALUES (?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
|
@ -214,7 +214,7 @@ async def m001_create_funding_table(db):
|
||||||
|
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO funding (id, backend_wallet, endpoint, admin_key, selected)
|
INSERT INTO admin.funding (id, backend_wallet, endpoint, admin_key, selected)
|
||||||
VALUES (?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
|
@ -228,7 +228,7 @@ async def m001_create_funding_table(db):
|
||||||
|
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO funding (id, backend_wallet, endpoint, port, admin_key, cert, selected)
|
INSERT INTO admin.funding (id, backend_wallet, endpoint, port, admin_key, cert, selected)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
|
@ -244,7 +244,7 @@ async def m001_create_funding_table(db):
|
||||||
|
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO funding (id, backend_wallet, endpoint, admin_key, cert, selected)
|
INSERT INTO admin.funding (id, backend_wallet, endpoint, admin_key, cert, selected)
|
||||||
VALUES (?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
|
@ -259,7 +259,7 @@ async def m001_create_funding_table(db):
|
||||||
|
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO funding (id, backend_wallet, endpoint, admin_key, cert, selected)
|
INSERT INTO admin.funding (id, backend_wallet, endpoint, admin_key, cert, selected)
|
||||||
VALUES (?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
|
@ -274,7 +274,7 @@ async def m001_create_funding_table(db):
|
||||||
|
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO funding (id, backend_wallet, endpoint, admin_key, selected)
|
INSERT INTO admin.funding (id, backend_wallet, endpoint, admin_key, selected)
|
||||||
VALUES (?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
|
@ -288,7 +288,7 @@ async def m001_create_funding_table(db):
|
||||||
|
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO funding (id, backend_wallet, endpoint, admin_key, selected)
|
INSERT INTO admin.funding (id, backend_wallet, endpoint, admin_key, selected)
|
||||||
VALUES (?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
|
@ -302,7 +302,7 @@ async def m001_create_funding_table(db):
|
||||||
|
|
||||||
await db.execute(
|
await db.execute(
|
||||||
"""
|
"""
|
||||||
INSERT INTO funding (id, backend_wallet, endpoint, admin_key, selected)
|
INSERT INTO admin.funding (id, backend_wallet, endpoint, admin_key, selected)
|
||||||
VALUES (?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?)
|
||||||
""",
|
""",
|
||||||
(
|
(
|
||||||
|
@ -317,7 +317,7 @@ async def m001_create_funding_table(db):
|
||||||
## PLACEHOLDER FOR ECLAIR WALLET
|
## PLACEHOLDER FOR ECLAIR WALLET
|
||||||
# await db.execute(
|
# await db.execute(
|
||||||
# """
|
# """
|
||||||
# INSERT INTO funding (id, backend_wallet, endpoint, admin_key, selected)
|
# INSERT INTO admin.funding (id, backend_wallet, endpoint, admin_key, selected)
|
||||||
# VALUES (?, ?, ?, ?, ?)
|
# VALUES (?, ?, ?, ?, ?)
|
||||||
# """,
|
# """,
|
||||||
# (
|
# (
|
||||||
|
|
Loading…
Reference in New Issue
Block a user