Create database schema and migration configuration.
()
| 373 | |
| 374 | @db_cli.command(name="init") |
| 375 | def 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() |
nothing calls this directly
no test coverage detected