#428 #436

Merged
edraft merged 19 commits from #428 into dev 2023-11-15 16:56:32 +01:00
2 changed files with 10 additions and 3 deletions
Showing only changes of commit 4628f31993 - Show all commits

View File

@ -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)

View File

@ -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 = ""