fixed create_schema
This commit is contained in:
@@ -23,8 +23,7 @@ APP_STATUS = "init"
|
|||||||
REACT_BUILD_DIR = "../frontend/build/" if not ON_DOCKER else "../frontend/"
|
REACT_BUILD_DIR = "../frontend/build/" if not ON_DOCKER else "../frontend/"
|
||||||
REACT_HTML_PATH = os.path.join(REACT_BUILD_DIR,"index.html")
|
REACT_HTML_PATH = os.path.join(REACT_BUILD_DIR,"index.html")
|
||||||
|
|
||||||
if not conf.get("password") is None:
|
|
||||||
APP_STATUS = "run"
|
|
||||||
|
|
||||||
def is_loggined(request: Request):
|
def is_loggined(request: Request):
|
||||||
return request.session.get("token", "") == SESSION_TOKEN
|
return request.session.get("token", "") == SESSION_TOKEN
|
||||||
@@ -294,7 +293,7 @@ async def catch_all(request: Request, full_path:str):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
db.check_integrity({
|
db.create_schema({
|
||||||
'services': {
|
'services': {
|
||||||
'status': 'VARCHAR(100) NOT NULL',
|
'status': 'VARCHAR(100) NOT NULL',
|
||||||
'service_id': 'VARCHAR(100) PRIMARY KEY',
|
'service_id': 'VARCHAR(100) PRIMARY KEY',
|
||||||
@@ -307,7 +306,7 @@ if __name__ == '__main__':
|
|||||||
'mode': 'VARCHAR(1) NOT NULL',
|
'mode': 'VARCHAR(1) NOT NULL',
|
||||||
'service_id': 'VARCHAR(100) NOT NULL',
|
'service_id': 'VARCHAR(100) NOT NULL',
|
||||||
'is_blacklist': 'BOOLEAN NOT NULL CHECK (is_blacklist IN (0, 1))',
|
'is_blacklist': 'BOOLEAN NOT NULL CHECK (is_blacklist IN (0, 1))',
|
||||||
'blocked_packets': 'INTEGER UNSIGNED NOT NULL async defAULT 0',
|
'blocked_packets': 'INTEGER UNSIGNED NOT NULL DEFAULT 0',
|
||||||
'regex_id': 'INTEGER PRIMARY KEY',
|
'regex_id': 'INTEGER PRIMARY KEY',
|
||||||
'is_case_sensitive' : 'BOOLEAN NOT NULL CHECK (is_case_sensitive IN (0, 1))',
|
'is_case_sensitive' : 'BOOLEAN NOT NULL CHECK (is_case_sensitive IN (0, 1))',
|
||||||
'FOREIGN KEY (service_id)':'REFERENCES services (service_id)',
|
'FOREIGN KEY (service_id)':'REFERENCES services (service_id)',
|
||||||
@@ -319,6 +318,9 @@ if __name__ == '__main__':
|
|||||||
})
|
})
|
||||||
db.query("CREATE UNIQUE INDEX IF NOT EXISTS unique_regex_service ON regexes (regex,service_id,is_blacklist,mode,is_case_sensitive);")
|
db.query("CREATE UNIQUE INDEX IF NOT EXISTS unique_regex_service ON regexes (regex,service_id,is_blacklist,mode,is_case_sensitive);")
|
||||||
|
|
||||||
|
if not conf.get("password") is None:
|
||||||
|
APP_STATUS = "run"
|
||||||
|
|
||||||
firewall.reload()
|
firewall.reload()
|
||||||
# os.environ {PORT = Backend Port (Main Port), F_PORT = Frontend Port}
|
# os.environ {PORT = Backend Port (Main Port), F_PORT = Frontend Port}
|
||||||
uvicorn.run(
|
uvicorn.run(
|
||||||
|
|||||||
@@ -30,15 +30,10 @@ class SQLite():
|
|||||||
def disconnect(self) -> None:
|
def disconnect(self) -> None:
|
||||||
self.conn.close()
|
self.conn.close()
|
||||||
|
|
||||||
def check_integrity(self, tables = {}) -> None:
|
def create_schema(self, tables = {}) -> None:
|
||||||
cur = self.conn.cursor()
|
cur = self.conn.cursor()
|
||||||
for t in tables:
|
for t in tables:
|
||||||
cur.execute('''
|
cur.execute('''CREATE TABLE IF NOT EXISTS main.{}({});'''.format(t, ''.join([(c + ' ' + tables[t][c] + ', ') for c in tables[t]])[:-2]))
|
||||||
SELECT name FROM sqlite_master WHERE type='table' AND name='{}';
|
|
||||||
'''.format(t))
|
|
||||||
|
|
||||||
if len(cur.fetchall()) == 0:
|
|
||||||
cur.execute('''CREATE TABLE main.{}({});'''.format(t, ''.join([(c + ' ' + tables[t][c] + ', ') for c in tables[t]])[:-2]))
|
|
||||||
cur.close()
|
cur.close()
|
||||||
|
|
||||||
def query(self, query, *values):
|
def query(self, query, *values):
|
||||||
|
|||||||
Reference in New Issue
Block a user