Changed how migration behaves
This commit is contained in:
43
cli.py
43
cli.py
@@ -1,43 +0,0 @@
|
||||
import logging
|
||||
from argparse import ArgumentParser
|
||||
|
||||
from modules.migrator import migrate_database
|
||||
|
||||
# from modules.migrator import downgrade_database
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format="%(name)s.%(funcName)s | %(levelname)s | %(message)s",
|
||||
datefmt="[%X]",
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
parser: ArgumentParser = ArgumentParser(
|
||||
prog="Javelina",
|
||||
description="Discord bot for community management.",
|
||||
)
|
||||
|
||||
parser.add_argument("--migrate", action="store_true")
|
||||
# parser.add_argument("--downgrade", action="store_true")
|
||||
parser.add_argument("--confirm", action="store_true")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.migrate:
|
||||
logger.info("Migrating...")
|
||||
migrate_database()
|
||||
exit()
|
||||
|
||||
# if args.downgrade:
|
||||
# if not args.confirm:
|
||||
# logger.warning(
|
||||
# "Argument --downgrade has been provided but this operation may include irreversible changes and destroy existing data in both database and configuration. It's not recommended to do this without backing everything up. Retry this command providing an additional argument --confirm to accept the risks and explicitly execute the downgrade."
|
||||
# )
|
||||
# exit(1)
|
||||
#
|
||||
# logger.info("Downgrading...")
|
||||
# downgrade_database()
|
||||
# exit()
|
||||
|
||||
logger.info("No arguments have been provided, not doing anything.")
|
30
main.py
30
main.py
@@ -1,6 +1,7 @@
|
||||
import asyncio
|
||||
import contextlib
|
||||
import logging.config
|
||||
from argparse import ArgumentParser
|
||||
from logging import Logger
|
||||
from os import getpid, makedirs
|
||||
from pathlib import Path
|
||||
@@ -10,6 +11,7 @@ from libbot.utils import config_get
|
||||
|
||||
from classes.pycord_bot import PycordBot
|
||||
from modules.logging_utils import get_logging_config, get_logger
|
||||
from modules.migrator import migrate_database
|
||||
from modules.scheduler import scheduler
|
||||
|
||||
makedirs(Path("logs/"), exist_ok=True)
|
||||
@@ -18,6 +20,19 @@ logging.config.dictConfig(get_logging_config())
|
||||
|
||||
logger: Logger = get_logger(__name__)
|
||||
|
||||
# Declare the parser that retrieves the command line arguments
|
||||
parser: ArgumentParser = ArgumentParser(
|
||||
prog="QuizBot"
|
||||
)
|
||||
|
||||
# Add a switch argument --migrate to be parsed...
|
||||
parser.add_argument("--migrate", action="store_true")
|
||||
# parser.add_argument("--downgrade", action="store_true")
|
||||
# parser.add_argument("--confirm", action="store_true")
|
||||
|
||||
# ...and parse the arguments we added
|
||||
args = parser.parse_args()
|
||||
|
||||
# Try to import the module that improves performance
|
||||
# and ignore errors when module is not installed
|
||||
with contextlib.suppress(ImportError):
|
||||
@@ -27,6 +42,21 @@ with contextlib.suppress(ImportError):
|
||||
|
||||
|
||||
async def main():
|
||||
# Perform migration if command line argument was provided
|
||||
if args.migrate:
|
||||
migrate_database()
|
||||
|
||||
# if args.downgrade:
|
||||
# if not args.confirm:
|
||||
# logger.warning(
|
||||
# "Argument --downgrade has been provided but this operation may include irreversible changes and destroy existing data in both database and configuration. It's not recommended to do this without backing everything up. Retry this command providing an additional argument --confirm to accept the risks and explicitly execute the downgrade."
|
||||
# )
|
||||
# exit(1)
|
||||
#
|
||||
# logger.info("Downgrading...")
|
||||
# downgrade_database()
|
||||
# exit()
|
||||
|
||||
bot = PycordBot(scheduler=scheduler)
|
||||
|
||||
bot.load_extension("cogs")
|
||||
|
@@ -1,3 +0,0 @@
|
||||
from modules.migrator import migrate_database
|
||||
|
||||
migrate_database()
|
Reference in New Issue
Block a user