Added migrations
This commit is contained in:
parent
32260e95a7
commit
24a2837f34
17
commands.json
Normal file
17
commands.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"start": {
|
||||||
|
"scopes": [
|
||||||
|
{
|
||||||
|
"name": "BotCommandScopeDefault"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"remove_commands": {
|
||||||
|
"scopes": [
|
||||||
|
{
|
||||||
|
"name": "BotCommandScopeChat",
|
||||||
|
"chat_id": "owner"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
@ -19,22 +19,5 @@
|
|||||||
"reports": {
|
"reports": {
|
||||||
"chat_id": "owner"
|
"chat_id": "owner"
|
||||||
},
|
},
|
||||||
"disabled_plugins": [],
|
"disabled_plugins": []
|
||||||
"commands": {
|
|
||||||
"start": {
|
|
||||||
"scopes": [
|
|
||||||
{
|
|
||||||
"name": "BotCommandScopeDefault"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"remove_commands": {
|
|
||||||
"scopes": [
|
|
||||||
{
|
|
||||||
"name": "BotCommandScopeChat",
|
|
||||||
"chat_id": "owner"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
22
main.py
22
main.py
@ -1,9 +1,13 @@
|
|||||||
import contextlib
|
import contextlib
|
||||||
import logging
|
import logging
|
||||||
|
from argparse import ArgumentParser
|
||||||
from os import getpid
|
from os import getpid
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from libbot import sync
|
||||||
from libbot.pyrogram.classes import PyroClient
|
from libbot.pyrogram.classes import PyroClient
|
||||||
|
|
||||||
|
from modules.migrator import migrate_database
|
||||||
from modules.scheduler import scheduler
|
from modules.scheduler import scheduler
|
||||||
|
|
||||||
# Uncomment this and the line below client declaration
|
# Uncomment this and the line below client declaration
|
||||||
@ -21,6 +25,16 @@ logging.basicConfig(
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
parser = ArgumentParser(
|
||||||
|
prog="__name__",
|
||||||
|
description="__description__",
|
||||||
|
)
|
||||||
|
|
||||||
|
# Remove if no database is being used
|
||||||
|
parser.add_argument("--migrate", action="store_true")
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
with contextlib.suppress(ImportError):
|
with contextlib.suppress(ImportError):
|
||||||
import uvloop
|
import uvloop
|
||||||
|
|
||||||
@ -28,9 +42,15 @@ with contextlib.suppress(ImportError):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
client = PyroClient(scheduler=scheduler)
|
client = PyroClient(
|
||||||
|
scheduler=scheduler, commands_source=sync.json_read(Path("commands.json"))
|
||||||
|
)
|
||||||
# Conversation(client)
|
# Conversation(client)
|
||||||
|
|
||||||
|
# Remove if no database is being used
|
||||||
|
if args.migrate:
|
||||||
|
migrate_database()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
client.run()
|
client.run()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
22
modules/migrator.py
Normal file
22
modules/migrator.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
from typing import Any, Mapping
|
||||||
|
|
||||||
|
from libbot.sync import config_get
|
||||||
|
from mongodb_migrations.cli import MigrationManager
|
||||||
|
from mongodb_migrations.config import Configuration
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_database() -> None:
|
||||||
|
"""Apply migrations from folder `migrations/` to the database"""
|
||||||
|
db_config: Mapping[str, Any] = config_get("database")
|
||||||
|
|
||||||
|
manager_config = Configuration(
|
||||||
|
{
|
||||||
|
"mongo_host": db_config["host"],
|
||||||
|
"mongo_port": db_config["port"],
|
||||||
|
"mongo_database": db_config["name"],
|
||||||
|
"mongo_username": db_config["user"],
|
||||||
|
"mongo_password": db_config["password"],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
manager = MigrationManager(manager_config)
|
||||||
|
manager.run()
|
@ -1,5 +1,6 @@
|
|||||||
apscheduler~=3.10.3
|
apscheduler~=3.10.3
|
||||||
convopyro==0.5
|
convopyro==0.5
|
||||||
|
mongodb-migrations==1.3.0
|
||||||
pykeyboard==0.1.5
|
pykeyboard==0.1.5
|
||||||
tgcrypto==1.2.5
|
tgcrypto==1.2.5
|
||||||
uvloop==0.17.0
|
uvloop==0.17.0
|
||||||
|
Reference in New Issue
Block a user