From 2e44d01c71fdb26e97f56c8668a95938e7e43200 Mon Sep 17 00:00:00 2001
From: Ivan Procaccini <ivanprocaccini905@gmail.com>
Date: Mon, 22 Aug 2022 14:49:15 +0100
Subject: [PATCH] Feat: Add CLI command to populate db with dev data

---
 app/__init__.py | 4 ++--
 app/cli.py      | 7 ++++---
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/app/__init__.py b/app/__init__.py
index 512f3de..aa1b384 100644
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -58,10 +58,10 @@ def create_app(test_configuration=None):
         )
 
     # Register CLI commands ####################################
-    from .cli import create_all, drop_all
+    from .cli import populate_dev, drop_all
 
     with app.app_context():
-        app.cli.add_command(create_all)
+        app.cli.add_command(populate_dev)
         app.cli.add_command(drop_all)
 
     # Register blueprints ####################################
diff --git a/app/cli.py b/app/cli.py
index 251295f..0a48bd6 100644
--- a/app/cli.py
+++ b/app/cli.py
@@ -2,12 +2,13 @@ import click
 from flask.cli import with_appcontext
 
 from .database import db
+from .factories import ProjectFactory
 
 
-@click.command("create_all", help="Create all tables in the app's database.")
+@click.command("populate_dev", help="Create a few projects in the database.")
 @with_appcontext
-def create_all():
-    db.create_all()
+def populate_dev():
+    ProjectFactory.create_batch(size=4, proposer="adumble")
 
 
 @click.command("drop_all", help="Drop all tables in the specified database.")
-- 
GitLab