diff --git a/.gitignore b/.gitignore index ce24d8ff9..41b9514e8 100644 --- a/.gitignore +++ b/.gitignore @@ -13,9 +13,12 @@ __pycache__ .pytest_cache htmlcov Pipfile.lock + *.swo *.swp *.pyo *.pyc *.env venv + +database.sqlite3 diff --git a/LNbits/__init__.py b/LNbits/__init__.py index fb4279de1..e10acba2d 100644 --- a/LNbits/__init__.py +++ b/LNbits/__init__.py @@ -1,3 +1,4 @@ +import os import lnurl import requests import time @@ -6,7 +7,7 @@ from flask import Flask, jsonify, render_template, request from .db import Database from .helpers import encrypt -from .settings import INVOICE_KEY, ADMIN_KEY, API_ENDPOINT, DATABASE_PATH +from .settings import INVOICE_KEY, ADMIN_KEY, API_ENDPOINT, DATABASE_PATH, LNBITS_PATH app = Flask(__name__) @@ -19,6 +20,14 @@ def db_connect(db_path=DATABASE_PATH): return con +@app.before_first_request +def init(): + with Database() as db: + with open(os.path.join(LNBITS_PATH, "data/schema.sql")) as schemafile: + for stmt in schemafile.read().split("\n\n"): + db.execute(stmt, []) + + @app.route("/") def home(): return render_template("index.html") diff --git a/LNbits/data/database.sqlite3 b/LNbits/data/database.sqlite3 deleted file mode 100644 index f5a37d79c..000000000 Binary files a/LNbits/data/database.sqlite3 and /dev/null differ diff --git a/LNbits/data/schema.sql b/LNbits/data/schema.sql new file mode 100644 index 000000000..fde264885 --- /dev/null +++ b/LNbits/data/schema.sql @@ -0,0 +1,22 @@ +CREATE TABLE IF NOT EXISTS accounts ( + userhash text PRIMARY KEY, + email text, + pass text +); + +CREATE TABLE IF NOT EXISTS wallets ( + hash text PRIMARY KEY, + name text NOT NULL, + user text NOT NULL, + adminkey text NOT NULL, + inkey text +); + +CREATE TABLE IF NOT EXISTS apipayments ( + payhash text PRIMARY KEY, + amount integer NOT NULL, + fee integer NOT NULL, + wallet text NOT NULL, + pending boolean NOT NULL, + memo text +);