migration.py 441 B

123456789101112131415161718
  1. import re
  2. registered = []
  3. module_name_regex = re.compile('^.*m_([0-9]+)_([a-z_]+)')
  4. class Migration:
  5. def __init__(self, version, name, method):
  6. self.version = int(version)
  7. self.name = name
  8. self.method = method
  9. def run(self, db):
  10. self.method(db)
  11. def migration(method):
  12. version, name = module_name_regex.match(method.__module__).groups()
  13. registered.append(Migration(version, name, method))