File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -538,7 +538,7 @@ async def migrate(
538538
539539 # build rollback chain
540540 chain : list [Migration ] = []
541- while next_migration and next_migration .id >= target :
541+ while next_migration and next_migration .id > target :
542542 if next_migration .down is None :
543543 raise exceptions .MigrationError (
544544 f"Cannot rollback from version { schema_version } "
@@ -556,7 +556,7 @@ async def migrate(
556556 async with conn .transaction ():
557557 await self .run_sqlfile (migration .down , conn = conn )
558558 await self ._update_schema_version (
559- migration .id ,
559+ migration .id - 1 ,
560560 conn ,
561561 )
562562
Original file line number Diff line number Diff line change @@ -35,10 +35,11 @@ def project(tmp_chdir: Path):
3535 migrations_dir .mkdir ()
3636 migrations_dir .joinpath ("00000_base.down.sql" ).touch ()
3737 migrations_dir .joinpath ("01_migration.up.sql" ).touch ()
38+ migrations_dir .joinpath ("01_migration.down.sql" ).touch ()
39+ migrations_dir .joinpath ("02_migration.up.sql" ).touch ()
3840 db : DB = DB .new_project (tmp_chdir )
3941 db .new_migration ("migration" )
4042 db .new_migration ("migration" )
41- db .new_migration ("migration" )
4243 db .new_fixture ("a_fixture" )
4344 db .fixtures ["a_fixture" ].path .write_text ("select current_database();" )
4445 return db
Original file line number Diff line number Diff line change @@ -123,7 +123,7 @@ async def test_rollback(tmp_db, project):
123123
124124@pytest .mark .asyncio
125125async def test_rollback_bad_file (tmp_db , project ):
126- project .migrations [2 ].down .path .write_text ("not valid sql" )
126+ project .migrations [3 ].down .path .write_text ("not valid sql" )
127127 await project .load_schema (database = tmp_db )
128128 with pytest .raises (asyncpg .PostgresSyntaxError ):
129129 await project .migrate (target = 2 , database = tmp_db )
You can’t perform that action at this time.
0 commit comments