From f1d56ea8f1984f2845fdaf74f93c36ecd34c7c35 Mon Sep 17 00:00:00 2001 From: Kyle Deal Date: Thu, 21 Sep 2023 19:22:32 +0000 Subject: [PATCH] Make creating dev data be a command Currently you need to set an environment variable and then run the normal flask run command. It can be difficult to remember the environment variable and if you forget to remove it then we recreate the data. Making it a command means it is shown in flask --help and you can run it directly and it will only create the dev data and exit. --- api/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/api/main.py b/api/main.py index 31408ae8..9cb0e93b 100644 --- a/api/main.py +++ b/api/main.py @@ -1,5 +1,3 @@ -import os - from factory import create_app app = create_app() @@ -16,11 +14,14 @@ def teardown_request(*args, **kwargs): db.session.remove() -if "Development" in os.environ.get("SERVER_SOFTWARE", ""): +@app.cli.command("create-dev-data") +def create_dev_data_entrypoint(): + """Add development data to the configured database""" from database import db from tests.conftest import create_dev_data create_dev_data(db.session) + if __name__ == "__main__": app.run()