Skip to content
This repository has been archived by the owner on Oct 12, 2020. It is now read-only.

Commit

Permalink
delegate migration
Browse files Browse the repository at this point in the history
  • Loading branch information
sakost committed May 1, 2020
1 parent 858b336 commit a2fa6f1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
4 changes: 1 addition & 3 deletions bot/plugins/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
from kutana.update import ReceiverType
from peewee_async import Manager

from bot.db import ChatUser, User, Chat, database
from bot.db import ChatUser, User, Chat
from bot.scheduler import init_scheduler

plugin = Plugin('Configure[system]')


async def init_db(app: Kutana):
app.config['db_manager'] = Manager(app.config['database'], loop=app.get_loop())
with app.config['db_manager'].allow_sync():
database.evolve(interactive=False)


@plugin.on_start()
Expand Down
34 changes: 34 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import os
import sys
import argparse

from dotenv import find_dotenv, load_dotenv

load_dotenv(find_dotenv())


def dbmigrate():
from bot.db import database
username = os.environ['SHUF_DB_HOST']
password = os.environ['SHUF_DB_PASSWORD']
host = os.environ['SHUF_DB_HOST']
db_name = os.environ['SHUF_DB_NAME']

database.init(db_name, user=username, password=password, host=host)
database.evolve()


actions = {
'dbmigrate': dbmigrate
}


def main():
parser = argparse.ArgumentParser()
parser.add_argument('action', choices=list(actions.keys()), required=True, help='action to do')
args = parser.parse_args(sys.argv)
actions[args.action]()


if __name__ == '__main__':
main()

0 comments on commit a2fa6f1

Please sign in to comment.