# Path: botlistbot/models/revision.py
# class Revision(BaseModel):
#     nr = IntegerField(default=1)
#     _instance = None
# 
#     @property
#     def next(self):
#         return self.nr + 1
# 
#     @staticmethod
#     def get_instance() -> 'Revision':
#         if not Revision._instance:
#             selection = list(Revision.select())
#             assert len(selection) == 1
#             Revision._instance = selection[0]
#         return Revision._instance


import os
from decouple import config
from playhouse.migrate import SqliteMigrator, IntegerField, migrate
from playhouse.sqlite_ext import SqliteExtDatabase
from botlistbot.models.revision import Revision



db_path = config('DATABASE_URL', default=os.path.expanduser('~/botlistbot.sqlite3'))
db = SqliteExtDatabase(db_path)

migrator = SqliteMigrator(db)

revision = IntegerField(default=100)

with db.transaction():
    migrate(
        migrator.add_column('bot', 'revision', revision),
    )

Revision.create_table(fail_silently=True)

# Path: botlistbot/models/revision.py
# class Revision(BaseModel):
#     nr = IntegerField(default=1)
#     _instance = None
# 
#     @property
#     def next(self):
#         return self.nr + 1
# 
#     @staticmethod
#     def get_instance() -> 'Revision':
#         if not Revision._instance:
#             selection = list(Revision.select())
#             assert len(selection) == 1
#             Revision._instance = selection[0]
#         return Revision._instance


# Path: botlistbot/migration/revision.py
import os
from decouple import config
from playhouse.migrate import SqliteMigrator, IntegerField, migrate
from playhouse.sqlite_ext import SqliteExtDatabase
from botlistbot.models.revision import Revision




db_path = config('DATABASE_URL', default=os.path.expanduser('~/botlistbot.sqlite3'))
db = SqliteExtDatabase(db_path)

migrator = SqliteMigrator(db)

revision = IntegerField(default=100)

with db.transaction():
    migrate(
        migrator.add_column('bot', 'revision', revision),
    )

Revision.create_table(fail_silently=True)

Revision.insert({'nr': 101}).execute()