|
18 | 18 | from .. import load_config |
19 | 19 | from .._app_db import ApplicationDatabase |
20 | 20 | from .._dbos_config import _is_valid_app_name |
21 | | -from .._schemas.system_database import SystemSchema |
22 | | -from .._sys_db import SystemDatabase |
| 21 | +from .._sys_db import SystemDatabase, reset_system_database |
23 | 22 | from .._workflow_commands import _cancel_workflow, _get_workflow, _list_workflows |
24 | 23 | from ..cli._github_init import create_template_from_github |
25 | 24 | from ._template_init import copy_template, get_project_name, get_templates_directory |
@@ -224,56 +223,12 @@ def reset( |
224 | 223 | typer.echo("Operation cancelled.") |
225 | 224 | raise typer.Exit() |
226 | 225 | config = load_config() |
227 | | - sysdb_name = ( |
228 | | - config["database"]["sys_db_name"] |
229 | | - if "sys_db_name" in config["database"] and config["database"]["sys_db_name"] |
230 | | - else config["database"]["app_db_name"] + SystemSchema.sysdb_suffix |
231 | | - ) |
232 | | - postgres_db_url = sa.URL.create( |
233 | | - "postgresql+psycopg", |
234 | | - username=config["database"]["username"], |
235 | | - password=config["database"]["password"], |
236 | | - host=config["database"]["hostname"], |
237 | | - port=config["database"]["port"], |
238 | | - database="postgres", |
239 | | - ) |
240 | 226 | try: |
241 | | - # Connect to postgres default database |
242 | | - engine = sa.create_engine(postgres_db_url) |
243 | | - |
244 | | - with engine.connect() as conn: |
245 | | - # Set autocommit required for database dropping |
246 | | - conn.execution_options(isolation_level="AUTOCOMMIT") |
247 | | - |
248 | | - # Terminate existing connections |
249 | | - conn.execute( |
250 | | - sa.text( |
251 | | - """ |
252 | | - SELECT pg_terminate_backend(pg_stat_activity.pid) |
253 | | - FROM pg_stat_activity |
254 | | - WHERE pg_stat_activity.datname = :db_name |
255 | | - AND pid <> pg_backend_pid() |
256 | | - """ |
257 | | - ), |
258 | | - {"db_name": sysdb_name}, |
259 | | - ) |
260 | | - |
261 | | - # Drop the database |
262 | | - conn.execute(sa.text(f"DROP DATABASE IF EXISTS {sysdb_name}")) |
263 | | - |
| 227 | + reset_system_database(config) |
264 | 228 | except sa.exc.SQLAlchemyError as e: |
265 | | - typer.echo(f"Error dropping database: {str(e)}") |
| 229 | + typer.echo(f"Error resetting system database: {str(e)}") |
266 | 230 | return |
267 | 231 |
|
268 | | - sys_db = None |
269 | | - try: |
270 | | - sys_db = SystemDatabase(config) |
271 | | - except Exception as e: |
272 | | - typer.echo(f"DBOS system schema migration failed: {e}") |
273 | | - finally: |
274 | | - if sys_db: |
275 | | - sys_db.destroy() |
276 | | - |
277 | 232 |
|
278 | 233 | @workflow.command(help="List workflows for your application") |
279 | 234 | def list( |
|
0 commit comments