Use factory strategy.
This commit is contained in:
parent
49197e61ef
commit
666ef171d8
@ -24,25 +24,35 @@ from flask_alembic import alembic_click
|
||||
from .models import db
|
||||
from .views import api, cors
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
alembic = Alembic()
|
||||
|
||||
|
||||
def create_app(config_path):
|
||||
"""Create the app using specific config file."""
|
||||
# The app
|
||||
app = Flask(__name__, static_folder=None, template_folder=None)
|
||||
|
||||
# Configure it from config.cfg.
|
||||
app.config.from_pyfile('config.cfg')
|
||||
# Configure it from configuration file.
|
||||
app.config.from_pyfile(config_path)
|
||||
|
||||
# Database related stuff.
|
||||
app.config['SQLALCHEMY_ECHO'] = app.debug
|
||||
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
|
||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
|
||||
|
||||
db.init_app(app)
|
||||
|
||||
# Database migrations.
|
||||
alembic = Alembic(app)
|
||||
|
||||
|
||||
|
||||
app.config['ALEMBIC'] = {
|
||||
'script_location': 'migrations'
|
||||
}
|
||||
alembic.init_app(app)
|
||||
|
||||
# API views related stuff.
|
||||
cors.init_app(app)
|
||||
api.init_app(app)
|
||||
|
||||
return app
|
||||
|
||||
|
||||
# Database initialization.
|
||||
@ -62,7 +72,3 @@ def dropdb():
|
||||
click.echo("Clearing database.")
|
||||
db.metadata.drop_all(bind=db.engine)
|
||||
click.echo("Database cleared.")
|
||||
|
||||
|
||||
api.init_app(app)
|
||||
cors.init_app(app)
|
||||
|
9
accountant/run.py
Normal file
9
accountant/run.py
Normal file
@ -0,0 +1,9 @@
|
||||
"""Accountant runner."""
|
||||
|
||||
from os import path, getcwd
|
||||
|
||||
from . import create_app
|
||||
|
||||
|
||||
config_path = path.join(getcwd(), 'config.cfg') # pylint: disable=invalid-name
|
||||
app = create_app(config_path) # pylint: disable=invalid-name
|
Loading…
Reference in New Issue
Block a user