#428 #436
@ -27,10 +27,17 @@ class MigrationService:
|
||||
migration_id = migration.__name__
|
||||
try:
|
||||
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()
|
||||
self._cursor.execute(MigrationHistory(migration_id).insert_string)
|
||||
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:
|
||||
Console.error(e)
|
||||
|
@ -21,8 +21,8 @@ class MockDBContext(DatabaseContextABC):
|
||||
cursor.execute = self.execute
|
||||
return cursor
|
||||
|
||||
def set_migration(self, name: str):
|
||||
self._migration_name = name.split("_")[1].replace("Migration", "")
|
||||
def set_migration(self, name: str, upgrade: bool = False):
|
||||
self._migration_name = f'{name.split("_")[1].replace("Migration", "")}_{"up" if upgrade else "down"}'
|
||||
self._migration_version = name.split("_")[0]
|
||||
self._migration_script = ""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user