Started with db development

This commit is contained in:
Jonas Linter
2025-09-27 17:35:05 +02:00
parent 7b539ea42f
commit ff00edf35d
8 changed files with 136 additions and 27 deletions

View File

@@ -18,20 +18,38 @@ from .simplified_access import (
)
# DB and config
from .db import Customer as DBCustomer, Reservation as DBReservation, HashedCustomer, SessionLocal, init_db
from .db import Customer as DBCustomer, Reservation as DBReservation, HashedCustomer, get_session_local, init_db
from .config_loader import load_config
import hashlib
import json
import os
def main():
import json
import os
print("🚀 Starting AlpineBits XML generation script...")
# Load config (yaml, annotatedyaml)
config = load_config()
# print config for debugging
print("Loaded configuration:")
print(json.dumps(config, indent=2))
# Ensure SQLite DB file exists if using SQLite
db_url = config.get('database', {}).get('url', '')
if db_url.startswith('sqlite:///'):
db_path = db_url.replace('sqlite:///', '')
db_path = os.path.abspath(db_path)
db_dir = os.path.dirname(db_path)
if not os.path.exists(db_dir):
os.makedirs(db_dir, exist_ok=True)
# The DB file will be created by SQLAlchemy if it doesn't exist, but ensure directory exists
# Init DB
init_db()
init_db(config)
print("📦 Database initialized/ready.")
SessionLocal = get_session_local(config)
db = SessionLocal()
# Load data from JSON file