From e759b69b86be60fe07cf3fc7c3662af3d592af1e Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Thu, 11 Aug 2022 23:31:36 +0300 Subject: [PATCH] Added check if database is not created. --- db/__init__.py | 5 +++-- db/create.py | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/db/__init__.py b/db/__init__.py index f3c89e6..7d33838 100644 --- a/db/__init__.py +++ b/db/__init__.py @@ -1,3 +1,4 @@ +from os import path import aiosqlite from .create import create_tables_if_not_exists @@ -6,5 +7,5 @@ from .create import create_tables_if_not_exists DB_PATH = 'res/db/' DB_FILENAME = 'database.db' - -create_tables_if_not_exists(f'{DB_PATH}{DB_FILENAME}') +if not path.exists('res/db/database.db'): + create_tables_if_not_exists(f'{DB_PATH}{DB_FILENAME}') diff --git a/db/create.py b/db/create.py index b4a1aea..b3b6ec6 100644 --- a/db/create.py +++ b/db/create.py @@ -39,6 +39,7 @@ Create database file and tables if not exists. *(text, not null)*. """ import sqlite3 +import logging CREATE_SERVICES_TABLE = '''CREATE TABLE IF NOT EXISTS services ( @@ -75,3 +76,4 @@ def create_tables_if_not_exists(dbfile: str) -> None: connection.commit() cursor.close() connection.close() + logging.warning('Database created!') \ No newline at end of file