migrate.py 614 B

1234567891011121314151617181920212223242526
  1. import sys
  2. import playhouse.migrate
  3. import lc.config as c
  4. import lc.model as m
  5. import lc.migration
  6. c.app.init_db()
  7. m.create_tables()
  8. meta = m.Meta.fetch()
  9. print(f"Current schema version is: {meta.version}")
  10. import migrations # noqa: F401, E402
  11. runnable = filter(lambda m: m.version > meta.version, lc.migration.registered)
  12. for migration in sorted(runnable, key=lambda m: m.version):
  13. print(f"{migration.version} - {migration.name}")
  14. try:
  15. migration.run(playhouse.migrate.SqliteMigrator(c.app.db))
  16. except Exception:
  17. sys.exit(1)
  18. meta.version = migration.version
  19. meta.save()