Aktualisiere Datenbankkonfiguration und verbessere JSON-Merge-Skript
- Füge neue Felder `host`, `port` und `database` zur Datenbankkonfiguration in `chatconfig.json` hinzu. - Implementiere eine Funktion im `update_config.sh`-Skript, um den `connectstring` zu parsen und die neuen Felder automatisch zu befüllen, falls sie fehlen. - Aktualisiere die `Database`-Klasse, um die neuen Konfigurationsparameter zu verwenden.
This commit is contained in:
@@ -5,7 +5,10 @@
|
||||
"database": {
|
||||
"user": "yourpart",
|
||||
"password": "r3EMWJ5p",
|
||||
"connectstring": "tsschulz.de:1521/yourpart"
|
||||
"connectstring": "tsschulz.de:1521/yourpart",
|
||||
"host": "tsschulz.de",
|
||||
"port": "1521",
|
||||
"database": "yourpart"
|
||||
},
|
||||
"room-types": {
|
||||
"0": "Standard",
|
||||
|
||||
@@ -45,11 +45,32 @@ TEMP_MERGED=$(mktemp)
|
||||
cp "$CONFIG_SOURCE" "$TEMP_SOURCE"
|
||||
cp "$CONFIG_TARGET" "$TEMP_TARGET"
|
||||
|
||||
# Python-Script für JSON-Merge erstellen
|
||||
# Python-Script für JSON-Merge und connectstring-Parsing erstellen
|
||||
cat > /tmp/merge_config.py << 'EOF'
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
import sys
|
||||
import re
|
||||
|
||||
def parse_connectstring(connectstring):
|
||||
"""Parst einen connectstring und extrahiert host, port und database"""
|
||||
# Verschiedene Formate unterstützen:
|
||||
# - localhost:5432/yp3
|
||||
# - tsschulz.de:1521/yourpart
|
||||
# - host:port/database
|
||||
|
||||
if not connectstring:
|
||||
return None, None, None
|
||||
|
||||
# Regex für host:port/database Format
|
||||
match = re.match(r'^([^:]+):(\d+)/(.+)$', connectstring)
|
||||
if match:
|
||||
host = match.group(1)
|
||||
port = match.group(2)
|
||||
database = match.group(3)
|
||||
return host, port, database
|
||||
|
||||
return None, None, None
|
||||
|
||||
def merge_json(source_file, target_file, output_file):
|
||||
"""Führt JSON-Dateien zusammen, ohne bestehende Einträge zu überschreiben"""
|
||||
@@ -93,6 +114,29 @@ def merge_json(source_file, target_file, output_file):
|
||||
|
||||
merged_data = merge_dict(source_data, target_data)
|
||||
|
||||
# Spezielle Behandlung für database-Konfiguration
|
||||
if 'database' in merged_data and isinstance(merged_data['database'], dict):
|
||||
db_config = merged_data['database']
|
||||
|
||||
# Falls connectstring vorhanden ist, aber host/database/port fehlen
|
||||
if 'connectstring' in db_config and ('host' not in db_config or 'database' not in db_config or 'port' not in db_config):
|
||||
connectstring = db_config.get('connectstring', '')
|
||||
host, port, database = parse_connectstring(connectstring)
|
||||
|
||||
if host and port and database:
|
||||
print(f"Parsing connectstring '{connectstring}':")
|
||||
print(f" -> host: {host}")
|
||||
print(f" -> port: {port}")
|
||||
print(f" -> database: {database}")
|
||||
|
||||
# Neue Felder hinzufügen (nur falls nicht vorhanden)
|
||||
if 'host' not in db_config:
|
||||
db_config['host'] = host
|
||||
if 'port' not in db_config:
|
||||
db_config['port'] = port
|
||||
if 'database' not in db_config:
|
||||
db_config['database'] = database
|
||||
|
||||
with open(output_file, 'w') as f:
|
||||
json.dump(merged_data, f, indent=4, ensure_ascii=False)
|
||||
|
||||
|
||||
@@ -8,16 +8,18 @@ namespace Lib {
|
||||
Database::Database(std::shared_ptr<Config> config)
|
||||
{
|
||||
// Hole Verbindungsdaten aus der Config
|
||||
std::string dbname = config->value("database", "database").asString();
|
||||
std::string user = config->value("database", "user").asString();
|
||||
std::string password = config->value("database", "password").asString();
|
||||
std::string host = config->value("database", "host").asString();
|
||||
std::string database = config->value("database", "database").asString();
|
||||
std::string port = config->value("database", "port").asString();
|
||||
|
||||
std::string conninfo =
|
||||
"dbname=" + dbname +
|
||||
"dbname=" + database +
|
||||
" user=" + user +
|
||||
" password=" + password +
|
||||
" host=" + host;
|
||||
" host=" + host +
|
||||
" port=" + port;
|
||||
|
||||
try {
|
||||
_connection = std::make_unique<pqxx::connection>(conninfo);
|
||||
|
||||
Reference in New Issue
Block a user