Skip to content

Commit

Permalink
Merge pull request #47 from Dunedan/print-db-schema
Browse files Browse the repository at this point in the history
Add an option to print the database schemas
  • Loading branch information
Dunedan authored Dec 2, 2024
2 parents 8f5bf22 + b535f80 commit 8755e03
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ packages = ["xpartamupp"]
echelon = "xpartamupp.echelon:main"
echelon-db = "xpartamupp.lobby_ranking:main"
modbot = "xpartamupp.modbot:main"
modbot-db = "xpartamupp.lobby_moderation_db:main"
xpartamupp = "xpartamupp.xpartamupp:main"

[tool.ruff]
Expand Down
11 changes: 10 additions & 1 deletion xpartamupp/lobby_moderation_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ def parse_args():
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description="Helper command for database creation",
)
parser.add_argument("action", help="Action to apply to the database", choices=["create"])
parser.add_argument(
"action", help="Action to apply to the database", choices=["create", "schema"]
)
parser.add_argument(
"--database-url",
help="URL for the moderation database",
Expand All @@ -242,6 +244,13 @@ def main():
engine = create_engine(args.database_url)
if args.action == "create":
Base.metadata.create_all(engine)
elif args.action == "schema":
engine = create_engine(
"sqlite://",
strategy="mock",
executor=lambda sql, _: print(sql.compile(dialect=engine.dialect)), # noqa: T201
)
Base.metadata.create_all(engine, checkfirst=False)


if __name__ == "__main__":
Expand Down
11 changes: 10 additions & 1 deletion xpartamupp/lobby_ranking.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ def parse_args():
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description="Helper command for database creation",
)
parser.add_argument("action", help="Action to apply to the database", choices=["create"])
parser.add_argument(
"action", help="Action to apply to the database", choices=["create", "schema"]
)
parser.add_argument(
"--database-url",
help="URL for the leaderboard database",
Expand All @@ -173,6 +175,13 @@ def main():
engine = create_engine(args.database_url)
if args.action == "create":
Base.metadata.create_all(engine)
elif args.action == "schema":
engine = create_engine(
"sqlite://",
strategy="mock",
executor=lambda sql, _: print(sql.compile(dialect=engine.dialect)), # noqa: T201
)
Base.metadata.create_all(engine, checkfirst=False)


if __name__ == "__main__":
Expand Down

0 comments on commit 8755e03

Please sign in to comment.