From 9478a782d989e0edcc3e888fdc5e2c973478052a Mon Sep 17 00:00:00 2001 From: Vinayak Mehta Date: Wed, 9 Apr 2025 13:02:46 +0200 Subject: [PATCH] Add schema dump command --- src/houseplant/cli.py | 7 +++++++ src/houseplant/houseplant.py | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/houseplant/cli.py b/src/houseplant/cli.py index c9e4d87..2b45595 100644 --- a/src/houseplant/cli.py +++ b/src/houseplant/cli.py @@ -99,6 +99,13 @@ def db_schema_load(): hp.db_schema_load() +@app.command(name="db:schema:dump") +def db_schema_dump(): + """Dump the schema to schema.sql file.""" + hp = get_houseplant() + hp.db_schema_dump() + + @app.command(hidden=True) def main(): """Console script for houseplant.""" diff --git a/src/houseplant/houseplant.py b/src/houseplant/houseplant.py index b41a3bf..0e63404 100644 --- a/src/houseplant/houseplant.py +++ b/src/houseplant/houseplant.py @@ -283,6 +283,18 @@ def db_schema_load(self): self.console.print("✨ Schema migrations loaded successfully!") + def db_schema_dump(self): + """Dump db schema to schema.sql file.""" + migration_files = get_migration_files() + if not migration_files: + self.console.print("[yellow]No migrations found.[/yellow]") + return + + with self.console.status("[bold green]Dumping schema..."): + self.update_schema() + + self.console.print("✨ Schema dumped successfully!") + def update_schema(self): """Update the schema file with the current database schema."""