2
2
from pathlib import Path
3
3
from typing import TYPE_CHECKING , Union
4
4
5
- from sqlalchemy import Engine , MetaData , Table
5
+ from sqlalchemy import Column , Engine , MetaData , String , Table
6
6
from typing_extensions import TypeIs
7
7
8
8
from advanced_alchemy .exceptions import MissingDependencyError
@@ -42,7 +42,15 @@ def _drop_tables_sync(engine: Engine) -> None:
42
42
console .rule ("[bold red]Dropping the db" , align = "left" )
43
43
metadata .drop_all (db )
44
44
console .rule ("[bold red]Dropping the version table" , align = "left" )
45
- Table (version_table_name , metadata ).drop (db , checkfirst = True )
45
+ # Create a properly defined Alembic version table with required column structure
46
+ # Using a temporary metadata instance prevents modifying the shared metadata object
47
+ temp_metadata = MetaData ()
48
+ alembic_version_table = Table (
49
+ version_table_name ,
50
+ temp_metadata ,
51
+ Column ("version_num" , String (32 ), primary_key = True , nullable = False ),
52
+ )
53
+ alembic_version_table .drop (db , checkfirst = True )
46
54
console .rule ("[bold yellow]Successfully dropped all objects" , align = "left" )
47
55
48
56
async def _drop_tables_async (engine : "AsyncEngine" ) -> None :
@@ -51,7 +59,15 @@ async def _drop_tables_async(engine: "AsyncEngine") -> None:
51
59
console .rule ("[bold red]Dropping the db" , align = "left" )
52
60
await db .run_sync (metadata .drop_all )
53
61
console .rule ("[bold red]Dropping the version table" , align = "left" )
54
- await db .run_sync (Table (version_table_name , metadata ).drop , checkfirst = True )
62
+ # Create a properly defined Alembic version table with required column structure
63
+ # Using a temporary metadata instance prevents modifying the shared metadata object
64
+ temp_metadata = MetaData ()
65
+ alembic_version_table = Table (
66
+ version_table_name ,
67
+ temp_metadata ,
68
+ Column ("version_num" , String (32 ), primary_key = True , nullable = False ),
69
+ )
70
+ await db .run_sync (alembic_version_table .drop , checkfirst = True )
55
71
console .rule ("[bold yellow]Successfully dropped all objects" , align = "left" )
56
72
57
73
if _is_sync (engine ):
0 commit comments