From dadf521ea3600ac75374ce7c9cd63fb62378a664 Mon Sep 17 00:00:00 2001 From: Ferruccio Balestreri Date: Tue, 19 Nov 2024 20:22:52 -0800 Subject: [PATCH] Add generate command --- .gitignore | 2 ++ src/houseplant/cli.py | 6 ++++++ src/houseplant/houseplant.py | 16 ++++++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 12d6222..a07dff7 100644 --- a/.gitignore +++ b/.gitignore @@ -108,3 +108,5 @@ ENV/ .vscode/ .idea/ +# Houseplant +ch/ diff --git a/src/houseplant/cli.py b/src/houseplant/cli.py index 2ef1803..0cac43f 100644 --- a/src/houseplant/cli.py +++ b/src/houseplant/cli.py @@ -41,6 +41,12 @@ def migrate(version: str | None = None): hp.migrate(version) +@app.command(name="generate") +def generate(name: str): + """Generate a new migration.""" + hp.generate(name) + + @app.command(hidden=True) def main(): """Console script for houseplant.""" diff --git a/src/houseplant/houseplant.py b/src/houseplant/houseplant.py index 6e99a3f..2e1bfc4 100644 --- a/src/houseplant/houseplant.py +++ b/src/houseplant/houseplant.py @@ -1,5 +1,6 @@ """Main module.""" +import os from rich.console import Console @@ -9,9 +10,15 @@ def __init__(self): def init(self): """Initialize a new houseplant project.""" - # TODO: Implement initialization logic self.console.print("Initializing new houseplant project...") - pass + + # Create ch directory and migrations subdirectory + os.makedirs("ch/migrations", exist_ok=True) + + # Create schema.yml file + open("ch/schema.yml", "a").close() + + self.console.print("✨ Project initialized successfully!") def migrate_status(self): """Show status of database migrations.""" @@ -31,3 +38,8 @@ def migrate_down(self, version: str | None = None): def migrate(self, version: str | None = None): """Run migrations up to specified version.""" self.migrate_up(version) + + def generate(self, name: str): + """Generate a new migration.""" + # TODO: Implement migration generation logic + pass