From 1dc1025820b96e36296f6b0fc186dbfc6350d9e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Tue, 12 Jun 2018 14:23:26 +0200 Subject: [PATCH] Rename api to quotes-api and switch sqlite DB to WAL mode --- {api => quotes-api}/.gitignore | 0 {api => quotes-api}/Dockerfile | 0 {api => quotes-api}/README.md | 0 {api => quotes-api}/app.py | 9 +++++++++ {api => quotes-api}/db.py | 0 {api => quotes-api}/generate_api_key.py | 0 {api => quotes-api}/requirements.txt | 0 7 files changed, 9 insertions(+) rename {api => quotes-api}/.gitignore (100%) rename {api => quotes-api}/Dockerfile (100%) rename {api => quotes-api}/README.md (100%) rename {api => quotes-api}/app.py (92%) rename {api => quotes-api}/db.py (100%) rename {api => quotes-api}/generate_api_key.py (100%) rename {api => quotes-api}/requirements.txt (100%) diff --git a/api/.gitignore b/quotes-api/.gitignore similarity index 100% rename from api/.gitignore rename to quotes-api/.gitignore diff --git a/api/Dockerfile b/quotes-api/Dockerfile similarity index 100% rename from api/Dockerfile rename to quotes-api/Dockerfile diff --git a/api/README.md b/quotes-api/README.md similarity index 100% rename from api/README.md rename to quotes-api/README.md diff --git a/api/app.py b/quotes-api/app.py similarity index 92% rename from api/app.py rename to quotes-api/app.py index afe4465..1ed3190 100644 --- a/api/app.py +++ b/quotes-api/app.py @@ -1,3 +1,4 @@ +import logging import os import flask @@ -7,17 +8,25 @@ import flask_restful.fields import flask_restful.reqparse import itsdangerous import sqlalchemy +import sqlalchemy.engine from db import db, Quote app = flask.Flask(__name__) +app.logger.setLevel(logging.INFO) app.config.update( ERROR_404_HELP=False, SQLALCHEMY_TRACK_MODIFICATIONS=False, SQLALCHEMY_DATABASE_URI=os.getenv('SQLALCHEMY_DATABASE_URI'), SECRET_KEY=os.getenv('SECRET_KEY')) +if app.config.get('SQLALCHEMY_DATABASE_URI', '').startswith('sqlite://'): + @sqlalchemy.event.listens_for(sqlalchemy.engine.Engine, 'connect') + def set_sqlite_pragma(dbapi_connection, connection_record): + dbapi_connection.execute('PRAGMA journal_mode=WAL') + dbapi_connection.execute('PRAGMA synchronous=NORMAL') + db.init_app(app) db.create_all(app=app) diff --git a/api/db.py b/quotes-api/db.py similarity index 100% rename from api/db.py rename to quotes-api/db.py diff --git a/api/generate_api_key.py b/quotes-api/generate_api_key.py similarity index 100% rename from api/generate_api_key.py rename to quotes-api/generate_api_key.py diff --git a/api/requirements.txt b/quotes-api/requirements.txt similarity index 100% rename from api/requirements.txt rename to quotes-api/requirements.txt