diff --git a/bot/src/bot_data/service/migration_service.py b/bot/src/bot_data/service/migration_service.py index e9d2e327..76aae60d 100644 --- a/bot/src/bot_data/service/migration_service.py +++ b/bot/src/bot_data/service/migration_service.py @@ -37,6 +37,22 @@ class MigrationService: return applied_migrations + def _migration_migrations_to_old(self, migration: MigrationHistory): + if migration.migration_id.endswith("Migration"): + return + + self._logger.debug(__name__, f"Migrate old migration {migration.migration_id} to new method") + self._cursor.execute(migration.change_id_string(f"{migration.migration_id}Migration")) + self._db.save_changes() + + def _migration_migrations_to_new(self, migration: MigrationHistory): + if not migration.migration_id.endswith("Migration"): + return + + self._logger.debug(__name__, f"Migrate old migration {migration.migration_id} to new method") + self._cursor.execute(migration.change_id_string(migration.migration_id.replace("Migration", ""))) + self._db.save_changes() + def _migrate_from_old_to_new(self): self._cursor.execute("SHOW TABLES LIKE 'MigrationHistory'") result = self._cursor.fetchone() @@ -44,12 +60,10 @@ class MigrationService: return for migration in self._get_migration_history(): - if not migration.migration_id.endswith("Migration"): - continue - - self._logger.debug(__name__, f"Migrate old migration {migration.migration_id} to new method") - self._cursor.execute(migration.change_id_string(migration.migration_id.replace("Migration", ""))) - self._db.save_changes() + if version.Version(bot.__version__) < version.Version("1.2.2"): + self._migration_migrations_to_old(migration) + else: + self._migration_migrations_to_new(migration) def _load_scripts(self, upgrade: bool = True) -> List[Migration]: migrations = List(Migration)