Skip to content

Commit

Permalink
Remove step-by-step execution
Browse files Browse the repository at this point in the history
  • Loading branch information
drew2a committed Oct 16, 2023
1 parent 423515f commit 1916c0a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 23 deletions.
13 changes: 4 additions & 9 deletions src/tribler/core/upgrade/tribler_db/migration_chain.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Callable, Iterator, List, Optional
from typing import Callable, List, Optional

from tribler.core.components.database.db.tribler_database import TriblerDatabase
from tribler.core.upgrade.tribler_db.decorator import has_migration_metadata
Expand Down Expand Up @@ -40,14 +40,9 @@ def execute(self) -> bool:
if not self.db:
return False

for _ in self.steps():
...

return True

def steps(self) -> Iterator:
""" Execute migrations step by step."""
for m in self.migrations:
if not has_migration_metadata(m):
raise NotImplementedError(f'The migration {m} should have `migration` decorator')
yield m(self.db, state_dir=self.state_dir)
m(self.db, state_dir=self.state_dir)

return True
14 changes: 0 additions & 14 deletions src/tribler/core/upgrade/tribler_db/tests/test_migration_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,6 @@ def migration99(*_, **__): # this migration should be skipped
assert migration_chain.execute()
assert migration_chain.db.version == 2

# test the same execution step by step
migration_chain.db.version = 0
steps = migration_chain.steps()
assert migration_chain.db.version == 0

next(steps) # migration1 completed
assert migration_chain.db.version == 1

next(steps) # migration2 completed
assert migration_chain.db.version == 2

next(steps) # migration99 skipped
assert migration_chain.db.version == 2


@db_session
def test_db_execute_no_annotation(migration_chain: TriblerDatabaseMigrationChain):
Expand Down

0 comments on commit 1916c0a

Please sign in to comment.