feat: Update CORS origins to allow Chrome extensions and improve logging in migration tool
Some checks failed
Backend CI / lint (push) Failing after 10s
Backend CI / test (push) Failing after 1m37s

This commit is contained in:
JSC
2025-09-19 16:41:11 +02:00
parent 1bef694f38
commit bccfcafe0e
9 changed files with 72 additions and 32 deletions

View File

@@ -2,25 +2,33 @@
"""Database migration CLI tool."""
import argparse
import logging
import sys
from pathlib import Path
from alembic import command
from alembic.config import Config
from alembic import command
# Set up logging
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO, format="%(message)s")
def main() -> None:
"""Main CLI function for database migrations."""
"""Run database migration CLI tool."""
parser = argparse.ArgumentParser(description="Database migration tool")
subparsers = parser.add_subparsers(dest="command", help="Migration commands")
# Upgrade command
upgrade_parser = subparsers.add_parser("upgrade", help="Upgrade database to latest revision")
upgrade_parser = subparsers.add_parser(
"upgrade", help="Upgrade database to latest revision",
)
upgrade_parser.add_argument(
"revision",
nargs="?",
default="head",
help="Target revision (default: head)"
help="Target revision (default: head)",
)
# Downgrade command
@@ -35,8 +43,12 @@ def main() -> None:
# Generate migration command
revision_parser = subparsers.add_parser("revision", help="Create new migration")
revision_parser.add_argument("-m", "--message", required=True, help="Migration message")
revision_parser.add_argument("--autogenerate", action="store_true", help="Auto-generate migration")
revision_parser.add_argument(
"-m", "--message", required=True, help="Migration message",
)
revision_parser.add_argument(
"--autogenerate", action="store_true", help="Auto-generate migration",
)
args = parser.parse_args()
@@ -47,7 +59,7 @@ def main() -> None:
# Get the alembic config
config_path = Path("alembic.ini")
if not config_path.exists():
print("Error: alembic.ini not found. Run from the backend directory.")
logger.error("Error: alembic.ini not found. Run from the backend directory.")
sys.exit(1)
alembic_cfg = Config(str(config_path))
@@ -55,11 +67,15 @@ def main() -> None:
try:
if args.command == "upgrade":
command.upgrade(alembic_cfg, args.revision)
print(f"Successfully upgraded database to revision: {args.revision}")
logger.info(
"Successfully upgraded database to revision: %s", args.revision,
)
elif args.command == "downgrade":
command.downgrade(alembic_cfg, args.revision)
print(f"Successfully downgraded database to revision: {args.revision}")
logger.info(
"Successfully downgraded database to revision: %s", args.revision,
)
elif args.command == "current":
command.current(alembic_cfg)
@@ -70,15 +86,15 @@ def main() -> None:
elif args.command == "revision":
if args.autogenerate:
command.revision(alembic_cfg, message=args.message, autogenerate=True)
print(f"Created new auto-generated migration: {args.message}")
logger.info("Created new auto-generated migration: %s", args.message)
else:
command.revision(alembic_cfg, message=args.message)
print(f"Created new empty migration: {args.message}")
logger.info("Created new empty migration: %s", args.message)
except Exception as e:
print(f"Error: {e}")
except (OSError, RuntimeError):
logger.exception("Error occurred during migration")
sys.exit(1)
if __name__ == "__main__":
main()
main()