move schema to sqlfile, create on init.
This commit is contained in:
+10
-1
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user