Skip to content

Commit 00247c6

Browse files
committed
🐛 fix: allow rewrite all argument
1 parent 0212d1e commit 00247c6

File tree

5 files changed

+54
-28
lines changed

5 files changed

+54
-28
lines changed

nonebot_plugin_orm/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ def _init_orm():
100100
_init_engines()
101101
_init_table()
102102
_session_factory = sa_async.async_sessionmaker(
103-
_engines[""], binds=_binds, **plugin_config.sqlalchemy_session_options
103+
**{
104+
**dict(bind=_engines[""], binds=_binds),
105+
**plugin_config.sqlalchemy_session_options,
106+
}
104107
)
105108

106109

nonebot_plugin_orm/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Config(BaseModel, arbitrary_types_allowed=True):
2626
alembic_version_locations: Union[
2727
str, os.PathLike, Dict[str, os.PathLike], None
2828
] = None
29-
alembic_context: Dict[str, Any] = {"render_as_batch": True}
29+
alembic_context: Dict[str, Any] = {}
3030
alembic_startup_check: bool = True
3131

3232

nonebot_plugin_orm/migrate.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,19 @@ def __init__(
107107
stdout,
108108
cmd_opts,
109109
{
110-
"script_location": script_location,
111-
"prepend_sys_path": ".",
112-
"revision_environment": "true",
113-
"version_path_separator": "os",
110+
**{
111+
"script_location": script_location,
112+
"prepend_sys_path": ".",
113+
"revision_environment": "true",
114+
"version_path_separator": "os",
115+
},
114116
**config_args,
115117
},
116118
{
117-
"engines": _engines,
118-
"metadatas": _metadatas,
119+
**{
120+
"engines": _engines,
121+
"metadatas": _metadatas,
122+
},
119123
**attributes,
120124
},
121125
)

nonebot_plugin_orm/templates/generic/env.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,15 @@ def run_migrations_offline() -> None:
3535
"""
3636

3737
context.configure(
38-
url=engine.url,
39-
target_metadata=target_metadata,
40-
literal_binds=True,
41-
dialect_opts={"paramstyle": "named"},
42-
**plugin_config.alembic_context,
38+
**{
39+
**dict(
40+
url=engine.url,
41+
dialect_opts={"paramstyle": "named"},
42+
target_metadata=target_metadata,
43+
literal_binds=True,
44+
),
45+
**plugin_config.alembic_context,
46+
}
4347
)
4448

4549
with context.begin_transaction():
@@ -48,9 +52,15 @@ def run_migrations_offline() -> None:
4852

4953
def do_run_migrations(connection: Connection) -> None:
5054
context.configure(
51-
connection=connection,
52-
target_metadata=target_metadata,
53-
**plugin_config.alembic_context,
55+
**{
56+
**dict(
57+
connection=connection,
58+
render_as_batch=True,
59+
target_metadata=target_metadata,
60+
include_object=no_drop_table,
61+
),
62+
**plugin_config.alembic_context,
63+
}
5464
)
5565

5666
with context.begin_transaction():

nonebot_plugin_orm/templates/multidb/env.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,16 @@ def run_migrations_offline() -> None:
5353
file_ = f"{name}.sql"
5454
with open(file_, "w") as buffer:
5555
context.configure(
56-
url=engine.url,
57-
output_buffer=buffer,
58-
target_metadata=target_metadatas["name"],
59-
literal_binds=True,
60-
dialect_opts={"paramstyle": "named"},
61-
**plugin_config.alembic_context,
56+
**{
57+
**dict(
58+
url=engine.url,
59+
dialect_opts={"paramstyle": "named"},
60+
output_buffer=buffer,
61+
target_metadata=target_metadatas["name"],
62+
literal_binds=True,
63+
),
64+
**plugin_config.alembic_context,
65+
}
6266
)
6367
with context.begin_transaction():
6468
context.run_migrations(name=name)
@@ -78,12 +82,17 @@ def process_revision_directives(_, __, directives: list[MigrationScript]) -> Non
7882

7983
def do_run_migrations(conn: Connection, name: str, metadata: MetaData) -> None:
8084
context.configure(
81-
connection=conn,
82-
upgrade_token=f"{name}_upgrades",
83-
downgrade_token=f"{name}_downgrades",
84-
target_metadata=metadata,
85-
process_revision_directives=process_revision_directives,
86-
**plugin_config.alembic_context,
85+
**{
86+
**dict(
87+
connection=conn,
88+
render_as_batch=True,
89+
target_metadata=metadata,
90+
include_object=no_drop_table,
91+
upgrade_token=f"{name}_upgrades",
92+
downgrade_token=f"{name}_downgrades",
93+
),
94+
**plugin_config.alembic_context,
95+
}
8796
)
8897
context.run_migrations(name=name)
8998

0 commit comments

Comments
 (0)