Fixed config loading in migration script

This commit is contained in:
Jonas Linter
2025-10-17 19:25:20 +02:00
parent e479381374
commit 75f32234e0

View File

@@ -42,6 +42,7 @@ from pathlib import Path
# Add parent directory to path so we can import alpine_bits_python
sys.path.insert(0, str(Path(__file__).parent.parent.parent))
import yaml
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
@@ -418,14 +419,19 @@ async def main():
if args.target:
target_url = args.target
elif args.target_config:
# Load target config file
# Load target config file manually (simpler YAML without secrets)
_LOGGER.info("Loading target database config from: %s", args.target_config)
try:
target_config = load_config(args.target_config)
target_url = get_database_url(target_config)
config_path = Path(args.target_config)
with config_path.open() as f:
target_config = yaml.safe_load(f)
target_url = target_config["database"]["url"]
_LOGGER.info("Successfully loaded target config")
except (FileNotFoundError, ValueError, KeyError):
_LOGGER.exception("Failed to load target config")
_LOGGER.info(
"Config file should contain: database.url with PostgreSQL connection"
)
sys.exit(1)
else:
import os