Fixing Migrations Issues

This commit is contained in:
Silversthorn 2021-08-23 21:41:27 +02:00
parent e776afc6d2
commit 6a29f1063b
2 changed files with 10 additions and 9 deletions

View File

@ -419,7 +419,7 @@ class MigrationManager(object):
"""
migrator = Migrator(self.database)
for name in self.done:
self.up_one(name, migrator)
self.up_one(name, migrator, True)
return migrator
def compile(self, name, migrate='', rollback=''):
@ -468,7 +468,7 @@ class MigrationManager(object):
migrator = self.migrator
for mname in diff:
done.append(self.up_one(mname, migrator))
done.append(self.up_one(mname, self.migrator))
if name and name == mname:
break
@ -490,12 +490,16 @@ class MigrationManager(object):
return scope.get('migrate', VOID), scope.get('rollback', VOID)
def up_one(self, name: str, migrator: Migrator,
rollback: bool = False) -> str:
fake: bool = False, rollback: bool = False) -> str:
"""
Runs a migration with a given name.
"""
try:
migrate_fn, rollback_fn = self.read(name)
if fake:
migrate_fn(migrator, self.database)
migrator.clean()
return name
with self.database.transaction():
if rollback:
logger.info('Rolling back "{}"'.format(name))
@ -528,5 +532,5 @@ class MigrationManager(object):
name = self.done[-1]
migrator = self.migrator
self.up_one(name, migrator, True)
self.up_one(name, migrator, False, True)
logger.warning('Rolled back migration: {}'.format(name))

View File

@ -2,11 +2,8 @@
import peewee
def migrate(migrator, database, **kwargs):
try:
migrator.add_columns('user_servers', permissions=peewee.CharField(default="00000000")) # First argument can be model class OR table name
migrator.add_columns('role_servers', permissions=peewee.CharField(default="00000000")) # First argument can be model class OR table name
except Exception as e:
print("Error in migrations:", e)
migrator.add_columns('user_servers', permissions=peewee.CharField(default='00000000')) # First argument can be model class OR table name
migrator.add_columns('role_servers', permissions=peewee.CharField(default='00000000')) # First argument can be model class OR table name
"""
Write your migrations here.
"""