11"""Migration runner coverage: discovery order, registration, idempotency,
2- and failure propagation. Runs the REAL migrations (001-007 ) against an
2+ and failure propagation. Runs the REAL migrations (001-008 ) against an
33in-memory database — the same code path a deployment upgrade takes.
44"""
55import pytest
88from core .database import execute_migrations
99from tests .helpers import MEMORY_DB_CONFIG , close_db
1010
11- EXPECTED = [f"migrations_{ i :03d} .py" for i in range (1 , 8 )]
11+ EXPECTED = [f"migrations_{ i :03d} .py" for i in range (1 , 9 )]
1212
1313
1414@pytest .fixture
@@ -60,15 +60,15 @@ async def test_pre_registered_subset_skips_those(self, fresh_db):
6060 """部分已登记(模拟中途升级):只执行缺口,顺序保持。"""
6161 conn = Tortoise .get_connection ("default" )
6262 await conn .execute_query ("DELETE FROM migrates" )
63- # 预登记 006/007(模拟已执行过全部迁移的库 ),验证 runner 只跑缺口
64- # 001-005 且跳过已登记的 006/007(跳过语义 = 不再执行其 DDL)
65- for name in EXPECTED [- 2 :]:
63+ # 预登记 006/007/008(模拟已执行过末尾迁移的库 ),验证 runner 只跑缺口
64+ # 001-005 且跳过已登记的 006/007/008 (跳过语义 = 不再执行其 DDL)
65+ for name in EXPECTED [- 3 :]:
6666 await conn .execute_query (
6767 "INSERT INTO migrates (migration_file) VALUES (?)" , [name ]
6868 )
6969 await execute_migrations ()
7070 registered = await _registered ()
71- # 预登记的 006/007 占据登记序前列——断言用集合:7 个全登记 、无重复
71+ # 预登记的 006/007/008 占据登记序前列——断言用集合:全部登记 、无重复
7272 assert sorted (registered ) == sorted (EXPECTED )
7373 assert len (registered ) == len (EXPECTED )
7474 tables = {
@@ -107,7 +107,7 @@ async def test_failure_propagates_and_halts(self, fresh_db, monkeypatch):
107107 """迁移执行失败必须向上抛(启动失败可见),不能静默吞掉。"""
108108 import importlib
109109
110- # 构造一个会失败的执行缺口:007 未登记,且其模块 migrate 抛错
110+ # 构造一个会失败的执行缺口:008 未登记,且其模块 migrate 抛错
111111 conn = Tortoise .get_connection ("default" )
112112 await conn .execute_query ("DELETE FROM migrates" )
113113 for name in EXPECTED [:- 1 ]:
@@ -117,7 +117,7 @@ async def test_failure_propagates_and_halts(self, fresh_db, monkeypatch):
117117 real_import = importlib .import_module
118118
119119 def fake_import (name ):
120- if name .endswith ("migrations_007 " ):
120+ if name .endswith ("migrations_008 " ):
121121 class FakeMod :
122122 @staticmethod
123123 async def migrate ():
@@ -130,4 +130,4 @@ async def migrate():
130130 with pytest .raises (RuntimeError , match = "boom" ):
131131 await execute_migrations ()
132132 # 失败的迁移不得登记
133- assert "migrations_007 .py" not in await _registered ()
133+ assert "migrations_008 .py" not in await _registered ()
0 commit comments