Add manager script to initialise database tables

Change-Id: I9f31ad216da2e3517dbaade34b1c9bb530893904
This commit is contained in:
JamesGibo 2021-03-02 15:14:57 +00:00
parent 29b73d2d50
commit 60d12582fa
3 changed files with 51 additions and 1 deletions

47
atmosphere/manage.py Normal file
View File

@ -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()

View File

@ -5,4 +5,5 @@ Flask-SQLAlchemy
keystonemiddleware
python-dateutil
PyMySQL
sentry-sdk[flask]
sentry-sdk[flask]
Flask-Script

View File

@ -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