MCPcopy Create free account
hub / github.com/dot-agent/nextpy / db_init

Function db_init

nextpy/cli.py:375–399  ·  view source on GitHub ↗

Create database schema and migration configuration.

()

Source from the content-addressed store, hash-verified

373
374@db_cli.command(name="init")
375def db_init():
376 """Create database schema and migration configuration."""
377 from nextpy.build import prerequisites
378 from nextpy.data import model
379
380 # Check the database url.
381 if config.db_url is None:
382 console.error("db_url is not configured, cannot initialize.")
383 return
384
385 # Check the alembic config.
386 if Path(constants.ALEMBIC_CONFIG).exists():
387 console.error(
388 "Database is already initialized. Use "
389 "[bold]nextpy db makemigrations[/bold] to create schema change "
390 "scripts and [bold]nextpy db migrate[/bold] to apply migrations "
391 "to a new or existing database.",
392 )
393 return
394
395 # Initialize the database.
396 _skip_compile()
397 prerequisites.get_compiled_app()
398 model.Model.alembic_init()
399 model.Model.migrate(autogenerate=True)
400
401
402@db_cli.command()

Callers

nothing calls this directly

Calls 4

PathClass · 0.85
_skip_compileFunction · 0.85
alembic_initMethod · 0.80
migrateMethod · 0.80

Tested by

no test coverage detected