4
4
from typing import TYPE_CHECKING , Optional , Union , cast
5
5
6
6
if TYPE_CHECKING :
7
+ from alembic .migration import MigrationContext
8
+ from alembic .operations .ops import MigrationScript , UpgradeOps
7
9
from click import Group
8
10
9
11
from advanced_alchemy .config import SQLAlchemyAsyncConfig , SQLAlchemySyncConfig
10
- from alembic .migration import MigrationContext
11
- from alembic .operations .ops import MigrationScript , UpgradeOps
12
12
13
13
__all__ = ("add_migration_commands" , "get_alchemy_group" )
14
14
@@ -157,7 +157,7 @@ def show_database_revision(bind_key: Optional[str], verbose: bool) -> None: # p
157
157
"""Show current database revision."""
158
158
from advanced_alchemy .alembic .commands import AlembicCommands
159
159
160
- ctx = click .get_current_context ()
160
+ ctx = cast ( " click.Context" , click . get_current_context () )
161
161
console .rule ("[yellow]Listing current revision[/]" , align = "left" )
162
162
sqlalchemy_config = get_config_by_bind_key (ctx , bind_key )
163
163
alembic_commands = AlembicCommands (sqlalchemy_config = sqlalchemy_config )
@@ -189,7 +189,7 @@ def downgrade_database( # pyright: ignore[reportUnusedFunction]
189
189
190
190
from advanced_alchemy .alembic .commands import AlembicCommands
191
191
192
- ctx = click .get_current_context ()
192
+ ctx = cast ( " click.Context" , click . get_current_context () )
193
193
console .rule ("[yellow]Starting database downgrade process[/]" , align = "left" )
194
194
input_confirmed = (
195
195
True
@@ -227,7 +227,7 @@ def upgrade_database( # pyright: ignore[reportUnusedFunction]
227
227
228
228
from advanced_alchemy .alembic .commands import AlembicCommands
229
229
230
- ctx = click .get_current_context ()
230
+ ctx = cast ( " click.Context" , click . get_current_context () )
231
231
console .rule ("[yellow]Starting database upgrade process[/]" , align = "left" )
232
232
input_confirmed = (
233
233
True
@@ -248,7 +248,7 @@ def stamp(bind_key: Optional[str], revision: str) -> None: # pyright: ignore[re
248
248
"""Stamp the revision table with the given revision."""
249
249
from advanced_alchemy .alembic .commands import AlembicCommands
250
250
251
- ctx = click .get_current_context ()
251
+ ctx = cast ( " click.Context" , click . get_current_context () )
252
252
sqlalchemy_config = get_config_by_bind_key (ctx , bind_key )
253
253
alembic_commands = AlembicCommands (sqlalchemy_config = sqlalchemy_config )
254
254
alembic_commands .stamp (revision = revision )
@@ -274,7 +274,7 @@ def init_alembic( # pyright: ignore[reportUnusedFunction]
274
274
275
275
from advanced_alchemy .alembic .commands import AlembicCommands
276
276
277
- ctx = click .get_current_context ()
277
+ ctx = cast ( " click.Context" , click . get_current_context () )
278
278
console .rule ("[yellow]Initializing database migrations." , align = "left" )
279
279
input_confirmed = (
280
280
True if no_prompt else Confirm .ask ("[bold]Are you sure you want initialize migrations for the project?[/]" )
@@ -345,7 +345,7 @@ def process_revision_directives(
345
345
)
346
346
directives .clear ()
347
347
348
- ctx = click .get_current_context ()
348
+ ctx = cast ( " click.Context" , click . get_current_context () )
349
349
console .rule ("[yellow]Starting database upgrade process[/]" , align = "left" )
350
350
if message is None :
351
351
message = "autogenerated" if no_prompt else Prompt .ask ("Please enter a message describing this revision" )
@@ -375,7 +375,7 @@ def drop_all(bind_key: Optional[str], no_prompt: bool) -> None: # pyright: igno
375
375
from advanced_alchemy .alembic .utils import drop_all
376
376
from advanced_alchemy .base import metadata_registry
377
377
378
- ctx = click .get_current_context ()
378
+ ctx = cast ( " click.Context" , click . get_current_context () )
379
379
console .rule ("[yellow]Dropping all tables from the database[/]" , align = "left" )
380
380
input_confirmed = no_prompt or Confirm .ask (
381
381
"[bold red]Are you sure you want to drop all tables from the database?"
@@ -418,7 +418,7 @@ def dump_table_data(bind_key: Optional[str], table_names: tuple[str, ...], dump_
418
418
from advanced_alchemy .alembic .utils import dump_tables
419
419
from advanced_alchemy .base import metadata_registry , orm_registry
420
420
421
- ctx = click .get_current_context ()
421
+ ctx = cast ( " click.Context" , click . get_current_context () )
422
422
all_tables = "*" in table_names
423
423
424
424
if all_tables and not Confirm .ask (
0 commit comments