Added logic to handle down and upgrades #428
This commit is contained in:
parent
1f2fbc362f
commit
4628f31993
@ -27,10 +27,17 @@ class MigrationService:
|
|||||||
migration_id = migration.__name__
|
migration_id = migration.__name__
|
||||||
try:
|
try:
|
||||||
migration_as_service: MigrationABC = self._services.get_service(migration)
|
migration_as_service: MigrationABC = self._services.get_service(migration)
|
||||||
self._db.set_migration(migration_as_service.name)
|
# save upgrade scripts
|
||||||
|
self._db.set_migration(migration_as_service.name, True)
|
||||||
migration_as_service.upgrade()
|
migration_as_service.upgrade()
|
||||||
self._cursor.execute(MigrationHistory(migration_id).insert_string)
|
self._cursor.execute(MigrationHistory(migration_id).insert_string)
|
||||||
self._db.save_changes()
|
self._db.save_changes()
|
||||||
|
|
||||||
|
# save downgrade scripts
|
||||||
|
self._db.set_migration(migration_as_service.name)
|
||||||
|
migration_as_service.downgrade()
|
||||||
|
self._cursor.execute(MigrationHistory(migration_id).insert_string)
|
||||||
|
self._db.save_changes()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
Console.error(e)
|
Console.error(e)
|
||||||
|
@ -21,8 +21,8 @@ class MockDBContext(DatabaseContextABC):
|
|||||||
cursor.execute = self.execute
|
cursor.execute = self.execute
|
||||||
return cursor
|
return cursor
|
||||||
|
|
||||||
def set_migration(self, name: str):
|
def set_migration(self, name: str, upgrade: bool = False):
|
||||||
self._migration_name = name.split("_")[1].replace("Migration", "")
|
self._migration_name = f'{name.split("_")[1].replace("Migration", "")}_{"up" if upgrade else "down"}'
|
||||||
self._migration_version = name.split("_")[0]
|
self._migration_version = name.split("_")[0]
|
||||||
self._migration_script = ""
|
self._migration_script = ""
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user