From 4c6a9bc8c95d29f0e03ad455f0c79ec7b082320f Mon Sep 17 00:00:00 2001 From: Davor Date: Tue, 21 Jun 2022 14:54:01 +0200 Subject: [PATCH] add check if the app exists in DB before creating it --- cliapp/cliapp/cli.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cliapp/cliapp/cli.py b/cliapp/cliapp/cli.py index d39b70e..cd24595 100644 --- a/cliapp/cliapp/cli.py +++ b/cliapp/cliapp/cli.py @@ -57,8 +57,14 @@ def create_app(slug, name): obj.name = name obj.slug = slug - db.session.add(obj) - db.session.commit() + app = db.session.query(App).filter_by(slug=slug).first() + + if app is not None: + db.session.add(obj) + db.session.commit() + else: + current_app.logger.info(f"App definition: {name} ({slug}) already exists in database") + @app_cli.command("list")