From 4336613028e05dae5b6adf3b543903f6fc365a44 Mon Sep 17 00:00:00 2001 From: Tiago vasconcelos Date: Sat, 12 Mar 2022 14:23:16 +0000 Subject: [PATCH] add db config at startup --- lnbits/commands.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lnbits/commands.py b/lnbits/commands.py index 0f7454f23..8c39c338f 100644 --- a/lnbits/commands.py +++ b/lnbits/commands.py @@ -52,6 +52,25 @@ def bundle_vendored(): with open(outputpath, "w") as f: f.write(output) +async def get_admin_settings(): + from lnbits.extensions.admin.models import Admin + + async with core_db.connect() as conn: + + if conn.type == SQLITE: + exists = await conn.fetchone( + "SELECT * FROM sqlite_master WHERE type='table' AND name='admin'" + ) + elif conn.type in {POSTGRES, COCKROACH}: + exists = await conn.fetchone( + "SELECT * FROM information_schema.tables WHERE table_name = 'admin'" + ) + if not exists: + return False + + row = await conn.fetchone("SELECT * from admin") + + return Admin(**row) if row else None async def migrate_databases(): """Creates the necessary databases if they don't exist already; or migrates them."""