I integrated Flask-Migrate into my project. When I'm using development mode (FLASK_ENV='development'
) I would normally call flask db migrate
to apply changes to SQLite database. But, in testing mode (FLASK_ENV='testing'
) I'm using internal memory storage (sqlite:///:memory:
) and it has no sense to call db migrate
because it will end up throwing error. Is there some way to create "pre_execute" hook in Flask CLI to check which ENV is used before executing command? So for example if FLASK_ENV is set to testing
than calling flask db init
will result in aborting execution of command. I've tried something like this but it didn't work:
@click.group(cls=FlaskGroup, create_app=create_app)
def cli():
'''
Main entry point.
'''
if app.config.ENV == ENV.TESTING:
print('Running in TESTING mode...Aborting!')
sys.exit(1)
Question: How I can abort execution of cli command under certain FLASK_ENV
setting?
Edit: I'm loading FLASK_ENV
value from .env
file.