|
2 | 2 |
|
3 | 3 | from typing import TYPE_CHECKING, cast |
4 | 4 |
|
| 5 | +from click import argument, group, option |
5 | 6 | from litestar.cli._utils import LitestarGroup, console |
6 | 7 | from rich.prompt import Confirm, Prompt |
7 | 8 |
|
8 | | -from advanced_alchemy.extensions.litestar.plugin import AlembicCommands, _get_advanced_alchemy_plugin |
| 9 | +from advanced_alchemy.extensions.litestar.alembic import AlembicCommands, get_database_migration_plugin |
9 | 10 |
|
10 | 11 | if TYPE_CHECKING: |
11 | 12 | from litestar import Litestar |
|
14 | 15 | from alembic.operations.ops import MigrationScript, UpgradeOps |
15 | 16 |
|
16 | 17 |
|
17 | | -from click import argument, group, option |
18 | | - |
19 | | - |
20 | 18 | @group(cls=LitestarGroup, name="database") |
21 | 19 | def database_group() -> None: |
22 | 20 | """Manage SQLAlchemy database components.""" |
@@ -130,16 +128,16 @@ def upgrade_database(app: Litestar, revision: str, sql: bool, tag: str | None, n |
130 | 128 | def init_alembic(app: Litestar, directory: str | None, multidb: bool, package: bool, no_prompt: bool) -> None: |
131 | 129 | """Upgrade the database to the latest revision.""" |
132 | 130 | console.rule("[yellow]Initializing database migrations.", align="left") |
133 | | - plugin = _get_advanced_alchemy_plugin(app) |
| 131 | + plugin = get_database_migration_plugin(app) |
134 | 132 | if directory is None: |
135 | | - directory = plugin._config.script_location # noqa: SLF001 |
| 133 | + directory = plugin._alembic_config.script_location # noqa: SLF001 |
136 | 134 | input_confirmed = ( |
137 | 135 | True |
138 | 136 | if no_prompt |
139 | 137 | else Confirm.ask("[bold]Are you sure you you want initialize the project in `{directory}`?[/]") |
140 | 138 | ) |
141 | 139 | if input_confirmed: |
142 | | - alembic_commands = AlembicCommands(app=app) |
| 140 | + alembic_commands = AlembicCommands(app) |
143 | 141 | alembic_commands.init(directory=directory, multidb=multidb, package=package) |
144 | 142 |
|
145 | 143 |
|
@@ -207,6 +205,7 @@ def process_revision_directives( |
207 | 205 | console.rule("[yellow]Starting database upgrade process[/]", align="left") |
208 | 206 | if message is None: |
209 | 207 | message = "autogenerated" if no_prompt else Prompt.ask("Please enter a message describing this revision") |
| 208 | + |
210 | 209 | alembic_commands = AlembicCommands(app=app) |
211 | 210 | alembic_commands.revision( |
212 | 211 | message=message, |
|
0 commit comments