From 710794b16e6c91409ca098f607600dec4d66b9f6 Mon Sep 17 00:00:00 2001 From: laghee Date: Tue, 19 Nov 2019 10:54:10 +0000 Subject: [PATCH 1/2] Issue #69 - Create migration scripts for DB --- ochazuke/__init__.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/ochazuke/__init__.py b/ochazuke/__init__.py index b80eba5..53d4ca9 100644 --- a/ochazuke/__init__.py +++ b/ochazuke/__init__.py @@ -10,21 +10,25 @@ from flask import Flask from flask_sqlalchemy import SQLAlchemy +from flask_migrate import Migrate from config import config db = SQLAlchemy() +migrate = Migrate() def create_app(config_name): """Create the main webcompat metrics server app.""" - # create and configure the app + # Create and configure the app app = Flask(__name__) app.config.from_object(config[config_name]) config[config_name].init_app(app) # DB init db.init_app(app) + # Migration setup + migrate.init_app(app, db) # Blueprint configure_blueprints(app) return app @@ -34,10 +38,12 @@ def configure_blueprints(app): """Define the blueprints for the project.""" # Web views for humans from ochazuke.web import web_blueprint + app.register_blueprint(web_blueprint) # Views for API clients from ochazuke.api import api_blueprint - app.register_blueprint(api_blueprint, url_prefix='/data') + + app.register_blueprint(api_blueprint, url_prefix="/data") # Logging Capabilities @@ -45,5 +51,13 @@ def configure_blueprints(app): # app.logger.info(Thing_To_Log) # it will create a line with the following format # (2015-09-14 20:50:19) INFO: Thing_To_Log -logging.basicConfig(format='(%(asctime)s) %(levelname)s: %(message)s', - datefmt='%Y-%m-%d %H:%M:%S %z', level=logging.INFO) +logging.basicConfig( + format="(%(asctime)s) %(levelname)s: %(message)s", + datefmt="%Y-%m-%d %H:%M:%S %z", + level=logging.INFO, +) + +application = create_app("development") + +if __name__ == "__main__": + application.run() From 47971b079ccedf08434af219b4e9a1b4c8c16d19 Mon Sep 17 00:00:00 2001 From: laghee Date: Tue, 19 Nov 2019 11:38:15 +0000 Subject: [PATCH 2/2] Issue #69 - Add flask-migrate to requirements --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 534b8d0..64b3c4a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,4 @@ flake8==3.7.7 nose2==0.9.1 psycopg2-binary==2.8.2 Flask-SQLAlchemy==2.4.0 +Flask-Migrate==2.5.2