diff --git a/lnbits/core/migrations.py b/lnbits/core/migrations.py index 466867164..76f4854c3 100644 --- a/lnbits/core/migrations.py +++ b/lnbits/core/migrations.py @@ -4,7 +4,7 @@ from sqlalchemy.exc import OperationalError # type: ignore async def m000_create_migrations_table(db): await db.execute( """ - CREATE TABLE dbversions ( + CREATE TABLE IF NOT EXISTS dbversions ( db TEXT PRIMARY KEY, version INT NOT NULL ) @@ -18,7 +18,7 @@ async def m001_initial(db): """ await db.execute( """ - CREATE TABLE accounts ( + CREATE TABLE IF NOT EXISTS accounts ( id TEXT PRIMARY KEY, email TEXT, pass TEXT @@ -27,7 +27,7 @@ async def m001_initial(db): ) await db.execute( """ - CREATE TABLE extensions ( + CREATE TABLE IF NOT EXISTS extensions ( "user" TEXT NOT NULL, extension TEXT NOT NULL, active BOOLEAN DEFAULT false, @@ -38,7 +38,7 @@ async def m001_initial(db): ) await db.execute( """ - CREATE TABLE wallets ( + CREATE TABLE IF NOT EXISTS wallets ( id TEXT PRIMARY KEY, name TEXT NOT NULL, "user" TEXT NOT NULL, @@ -49,7 +49,7 @@ async def m001_initial(db): ) await db.execute( f""" - CREATE TABLE apipayments ( + CREATE TABLE IF NOT EXISTS apipayments ( payhash TEXT NOT NULL, amount INTEGER NOT NULL, fee INTEGER NOT NULL DEFAULT 0, @@ -64,7 +64,7 @@ async def m001_initial(db): await db.execute( """ - CREATE VIEW balances AS + CREATE VIEW IF NOT EXISTS balances AS SELECT wallet, COALESCE(SUM(s), 0) AS balance FROM ( SELECT wallet, SUM(amount) AS s -- incoming FROM apipayments @@ -144,7 +144,7 @@ async def m004_ensure_fees_are_always_negative(db): await db.execute("DROP VIEW balances") await db.execute( """ - CREATE VIEW balances AS + CREATE VIEW IF NOT EXISTS balances AS SELECT wallet, COALESCE(SUM(s), 0) AS balance FROM ( SELECT wallet, SUM(amount) AS s -- incoming FROM apipayments @@ -168,7 +168,7 @@ async def m005_balance_check_balance_notify(db): await db.execute( """ - CREATE TABLE balance_check ( + CREATE TABLE IF NOT EXISTS balance_check ( wallet TEXT NOT NULL REFERENCES wallets (id), service TEXT NOT NULL, url TEXT NOT NULL, @@ -180,7 +180,7 @@ async def m005_balance_check_balance_notify(db): await db.execute( """ - CREATE TABLE balance_notify ( + CREATE TABLE IF NOT EXISTS balance_notify ( wallet TEXT NOT NULL REFERENCES wallets (id), url TEXT NOT NULL, diff --git a/lnbits/extensions/lnticket/migrations.py b/lnbits/extensions/lnticket/migrations.py index 37fbdc865..44c2e0f10 100644 --- a/lnbits/extensions/lnticket/migrations.py +++ b/lnbits/extensions/lnticket/migrations.py @@ -88,7 +88,7 @@ async def m003_changed(db): await db.execute( """ - CREATE TABLE lnticket.form ( + CREATE TABLE IF NOT EXISTS lnticket.form ( id TEXT PRIMARY KEY, wallet TEXT NOT NULL, name TEXT NOT NULL,