2023-02-17 07:02:21 +01:00
|
|
|
import yaml
|
2023-02-16 06:06:42 +01:00
|
|
|
import argparse
|
2023-02-17 07:02:21 +01:00
|
|
|
from core.config import CoreConfig
|
|
|
|
from core.data import Data
|
2023-02-16 06:06:42 +01:00
|
|
|
|
2023-02-17 07:02:21 +01:00
|
|
|
if __name__=='__main__':
|
|
|
|
parser = argparse.ArgumentParser(description="Database utilities")
|
|
|
|
parser.add_argument("--config", "-c", type=str, help="Config folder to use", default="config")
|
|
|
|
parser.add_argument("--version", "-v", type=str, help="Version of the database to upgrade/rollback to")
|
|
|
|
parser.add_argument("--game", "-g", type=str, help="Game code of the game who's schema will be updated/rolled back. Ex. SDFE")
|
|
|
|
parser.add_argument("action", type=str, help="DB Action, create, recreate, upgrade, or rollback")
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
cfg = CoreConfig()
|
|
|
|
cfg.update(yaml.safe_load(open(f"{args.config}/core.yaml")))
|
|
|
|
data = Data(cfg)
|
|
|
|
|
|
|
|
if args.action == "create":
|
|
|
|
data.create_database()
|
|
|
|
|
|
|
|
elif args.action == "recreate":
|
|
|
|
data.recreate_database()
|
|
|
|
|
|
|
|
elif args.action == "upgrade" or args.action == "rollback":
|
|
|
|
if args.version is None:
|
2023-02-24 20:13:31 +01:00
|
|
|
data.logger.error("Must set game and version to migrate to")
|
2023-02-17 07:02:21 +01:00
|
|
|
exit(0)
|
|
|
|
|
|
|
|
if args.game is None:
|
2023-02-24 20:13:31 +01:00
|
|
|
data.logger.info("No game set, upgrading core schema")
|
2023-02-17 07:02:21 +01:00
|
|
|
data.migrate_database("CORE", int(args.version))
|
|
|
|
|
|
|
|
else:
|
|
|
|
data.migrate_database(args.game, int(args.version), args.action)
|
|
|
|
|
|
|
|
elif args.action == "migrate":
|
2023-02-24 20:13:31 +01:00
|
|
|
data.logger.info("Migrating from old schema to new schema")
|
2023-02-17 07:02:21 +01:00
|
|
|
data.restore_from_old_schema()
|
|
|
|
|
|
|
|
elif args.action == "dump":
|
2023-02-24 20:13:31 +01:00
|
|
|
data.logger.info("Dumping old schema to migrate to new schema")
|
2023-02-17 07:02:21 +01:00
|
|
|
data.dump_db()
|
|
|
|
|
|
|
|
elif args.action == "generate":
|
|
|
|
pass
|
|
|
|
|
|
|
|
data.logger.info("Done")
|