From 934df871377429aa7d21deae7a66505176c3c9d7 Mon Sep 17 00:00:00 2001 From: dortal94 Date: Sat, 25 Apr 2020 19:13:15 +0100 Subject: [PATCH] Added db support --- edison/__init__.py | 2 ++ edison/app.py | 6 ++++++ edison/config.py | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/edison/__init__.py b/edison/__init__.py index befb02a..d4ff709 100644 --- a/edison/__init__.py +++ b/edison/__init__.py @@ -1,6 +1,7 @@ import os from flask import Flask +from flask_sqlalchemy import SQLAlchemy from edison.config import get_config_object @@ -8,3 +9,4 @@ app = Flask(__name__) app.config.from_object(get_config_object(app.config["ENV"])) basedir = os.path.abspath(os.path.dirname(__file__)) +db = SQLAlchemy(app) diff --git a/edison/app.py b/edison/app.py index 6ef3f3e..48c3ec3 100644 --- a/edison/app.py +++ b/edison/app.py @@ -6,6 +6,12 @@ # API description in swagger - https://app.swaggerhub.com/apis/DoRTaL94/UserManagment/1.0.0 app = edison.app +db = edison.db + +# Creates all tables defined in the database models and the only ones that are not created yet. +# If there's any change in the database models you should perform a migration to apply this change in the database itself. +# More about database migrations can be found in /edison/migrations/README. +db.create_all() @app.route("/") def index(): diff --git a/edison/config.py b/edison/config.py index 82314f8..442c58d 100644 --- a/edison/config.py +++ b/edison/config.py @@ -19,7 +19,11 @@ def get_config_object(env_keyword: str): class Config: ENV_KEYWORD = "" DEBUG = False + # Turns off the Flask-SQLAlchemy event system + SQLALCHEMY_TRACK_MODIFICATIONS = False + SQLALCHEMY_DATABASE_URI = 'postgresql://postgres:edison@127.0.0.1/edison' +# PostgreSQL connection string should be updated once an actual production environment is established. class ProductionConfig(Config): ENV_KEYWORD = "production"