Notable Changes
* [🐛 fix(alembic): env.py open multi transcations](https://github.com/nonebot/plugin-orm/commit/5907585edd64e832b95f2e873f590ad178038756)
此修复改动了模板中的 env.py. 对于初始化脚本目录后使用的用户, 需要对 env.py 应用如下更改:
**单数据库模板 (generic)**
diff
--- a/migrations/env.py
+++ b/migrations/env.py
-59,7 +59,7 async def run_migrations_online() -> None:
这种情况下,我们需要为 context 创建一个连接。
"""
- async with engine.begin() as connection:
+ async with engine.connect() as connection:
await connection.run_sync(do_run_migrations)
**多数据库模板 (multidb)**
diff
--- a/migrations/env.py
+++ b/migrations/env.py
-52,6 +52,7 def run_migrations_offline() -> None:
使用 --sql 选项的情况下,将每个引擎的迁移写入到单独的 .sql 文件中。
for name, engine in engines.items():
+ config.print_stdout(f"迁移数据库 {name or '<default>'} 中 ...")
file_ = f"{name}.sql"
with open(file_, "w") as buffer:
context.configure(
-62,9 +63,7 def run_migrations_offline() -> None:
dialect_opts={"paramstyle": "named"},
**plugin_config.alembic_context,
)
- with context.begin_transaction(), config.status(
- f"迁移数据库 {name or '<default>'} 中"
- ):
+ with context.begin_transaction():
context.run_migrations(name=name)
config.print_stdout(f"将输出写入到 {file_}")
* [💥 refactor(alembic)!: AlembicConfig initialization and version locati…](https://github.com/nonebot/plugin-orm/commit/c1f08e1e7bd7d50fb2f66958fb92221cc6b9ec89)
此重构改动了读取插件内的迁移脚本目录的方式. 现在要求 `orm_version_location` 必须是一个常规包 (regular package) 而非命名空间包 (namespace package), 所以需要在插件内的迁移脚本目录中添加 \_\_init\_\_.py 文件:
diff
--- a/a.tree
+++ b/b.tree
-1,8 +1,9
.
└── nonebot_plugin
├── config.py
├── __init__.py
└── migrations
├── 21e03401e435_.py
├── 595fd3d5f5b4_.py
- └── e04c11aa30b7_.py
+ ├── e04c11aa30b7_.py
+ └── __init__.py
What's Changed
* [🐛 fix: logger echo](https://github.com/nonebot/plugin-orm/commit/d46f5ce7803d4a7a32477cdafe8c1c04c2a61c2b)
* [✨ feat(sqla): Model support dependency injection](https://github.com/nonebot/plugin-orm/commit/10c8df6a993fc3f54a901a26cfcc99d2da4c2f09)
**Full Changelog**: https://github.com/nonebot/plugin-orm/compare/v0.1.2...v0.2.0