From 3a5b403ff19658846c3141edaf25798ea5b46cb1 Mon Sep 17 00:00:00 2001 From: Oleg Silkin Date: Thu, 30 May 2019 11:25:42 -0400 Subject: [PATCH] Puts safeguards in place to avoid database deletion --- src/app.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/app.py b/src/app.py index 9101125..7c898cb 100644 --- a/src/app.py +++ b/src/app.py @@ -1,10 +1,11 @@ # cython: language_level=3 import logging +import pathlib +import re import aiojobs.aiohttp import asyncio from aiohttp import web -import re import schema.db_helpers from src.database import obtain_connection @@ -13,7 +14,6 @@ from src.handles import create_comment_scheduler from src.settings import config_path, get_config from src.writes import DatabaseWriter - config = get_config(config_path) logger = logging.getLogger(__name__) @@ -38,8 +38,11 @@ logger.addHandler(stdout_handler) async def setup_db_schema(app): - logger.info('Setting up schema in %s', app['db_path']) - schema.db_helpers.setup_database(app['db_path']) + if not pathlib.Path(app['db_path']).exists(): + logger.info('Setting up schema in %s', app['db_path']) + schema.db_helpers.setup_database(app['db_path']) + else: + logger.info('Database already exists in %s, skipping setup', app['db_path']) async def close_comment_scheduler(app):