From 60d12582faf9eb7807d80468096bd95b0e50bc58 Mon Sep 17 00:00:00 2001 From: JamesGibo Date: Tue, 2 Mar 2021 15:14:57 +0000 Subject: [PATCH] Add manager script to initialise database tables Change-Id: I9f31ad216da2e3517dbaade34b1c9bb530893904 --- atmosphere/manage.py | 47 ++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 3 ++- setup.cfg | 2 ++ 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 atmosphere/manage.py diff --git a/atmosphere/manage.py b/atmosphere/manage.py new file mode 100644 index 0000000..6ffbadd --- /dev/null +++ b/atmosphere/manage.py @@ -0,0 +1,47 @@ +# Copyright 2021 BBC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Manage + +""" + +import os +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +from flask_script import Manager +from flask_migrate import Migrate, MigrateCommand + + +app = Flask(__name__) +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False +if app.config.get('SQLALCHEMY_DATABASE_URI') is None: + app.config['SQLALCHEMY_DATABASE_URI'] = \ + os.environ.get('DATABASE_URI', 'sqlite:///:memory:') + +MIGRATION_DIR = os.path.join(os.path.dirname(__file__), 'migrations') + +db = SQLAlchemy(app) +migrate = Migrate(app, db, directory=MIGRATION_DIR) + +manager = Manager(app) +manager.add_command('db', MigrateCommand) + + +def main(): + """main""" + manager.run() + + +if __name__ == '__main__': + main() diff --git a/requirements.txt b/requirements.txt index 048873f..72e2a41 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,5 @@ Flask-SQLAlchemy keystonemiddleware python-dateutil PyMySQL -sentry-sdk[flask] \ No newline at end of file +sentry-sdk[flask] +Flask-Script diff --git a/setup.cfg b/setup.cfg index 8c9a1d1..74863de 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,6 +6,8 @@ packages = atmosphere [entry_points] +console_scripts = + atmosphere-manage = atmosphere.manage:main wsgi_scripts = atmosphere-ingress-wsgi = atmosphere.api.ingress:init_application atmosphere-usage-wsgi = atmosphere.api.usage:init_application