Execute alembic migrations for all model classes. If alembic is not installed or has not been initialized for the project, then no action is performed. If there are no revisions currently tracked by alembic, then an initial revision will be created based on sqlmodel
(autogenerate: bool = False)
| 468 | env.run_migrations() |
| 469 | |
| 470 | def migrate(autogenerate: bool = False) -> bool | None: |
| 471 | """Execute alembic migrations for all model classes. |
| 472 | |
| 473 | If alembic is not installed or has not been initialized for the project, |
| 474 | then no action is performed. |
| 475 | |
| 476 | If there are no revisions currently tracked by alembic, then |
| 477 | an initial revision will be created based on sqlmodel metadata. |
| 478 | |
| 479 | If models in the app have changed in incompatible ways that alembic |
| 480 | cannot automatically generate revisions for, the app may not be able to |
| 481 | start up until migration scripts have been corrected by hand. |
| 482 | |
| 483 | Args: |
| 484 | autogenerate: If True, generate migration script and use it to upgrade schema |
| 485 | (otherwise, just bring the schema to current "head" revision). |
| 486 | |
| 487 | Returns: |
| 488 | True - indicating the process was successful. |
| 489 | None - indicating the process was skipped. |
| 490 | """ |
| 491 | if not environment.ALEMBIC_CONFIG.get().exists(): |
| 492 | return None |
| 493 | |
| 494 | with get_engine().connect() as connection: |
| 495 | _alembic_upgrade(connection=connection) |
| 496 | if autogenerate: |
| 497 | changes_detected = alembic_autogenerate(connection=connection) |
| 498 | if changes_detected: |
| 499 | _alembic_upgrade(connection=connection) |
| 500 | connection.commit() |
| 501 | return True |
| 502 | |
| 503 | else: |
| 504 | alembic_init = _print_db_not_available |