dev: automated commit - 2025-10-26 10:46:10
This commit is contained in:
parent
211d9e03bd
commit
9462eda5e2
2 changed files with 169 additions and 48 deletions
|
|
@ -149,15 +149,49 @@ def group_connections(connections):
|
|||
|
||||
return folders
|
||||
|
||||
def generate_dbeaver_config(connections):
|
||||
def is_sdm_connection(conn_name):
|
||||
"""Check if connection name matches SDM pattern (oc-*-*-*)"""
|
||||
pattern = r'oc-([^-]+)-([^-]+)-.*'
|
||||
return re.match(pattern, conn_name) is not None
|
||||
|
||||
def load_existing_config(output_file):
|
||||
"""Load existing DBeaver config, return empty if file doesn't exist"""
|
||||
if not os.path.exists(output_file):
|
||||
return {"folders": {}, "connections": {}}
|
||||
|
||||
try:
|
||||
with open(output_file, 'r') as f:
|
||||
return json.load(f)
|
||||
except json.JSONDecodeError:
|
||||
print("⚠️ Existing config file is invalid, starting fresh")
|
||||
return {"folders": {}, "connections": {}}
|
||||
|
||||
def generate_dbeaver_config(connections, existing_config):
|
||||
folders = group_connections(connections)
|
||||
|
||||
folders_config = {}
|
||||
# Start with existing folders
|
||||
folders_config = existing_config.get("folders", {}).copy()
|
||||
|
||||
# Add folders for new SDM connections
|
||||
for folder_name in folders.keys():
|
||||
folders_config[folder_name] = {}
|
||||
if folder_name not in folders_config:
|
||||
folders_config[folder_name] = {}
|
||||
|
||||
# Start with existing connections, filtering out SDM connections
|
||||
connections_config = {}
|
||||
existing_connections = existing_config.get("connections", {})
|
||||
for conn_id, conn in existing_connections.items():
|
||||
# Keep non-SDM connections (those that don't start with oc- in their display name)
|
||||
display_name = conn.get("name", "")
|
||||
# Also check configuration host/type for SDM patterns
|
||||
config = conn.get("configuration", {})
|
||||
conn_type = config.get("type", "")
|
||||
|
||||
# Only keep connections that don't match SDM pattern
|
||||
if not is_sdm_connection(display_name) and not is_sdm_connection(conn_type):
|
||||
connections_config[conn_id] = conn
|
||||
|
||||
# Add new SDM connections
|
||||
for conn in connections:
|
||||
connection_id = f"postgres-jdbc-{uuid.uuid4().hex[:8]}-{uuid.uuid4().hex[:8]}"
|
||||
conn_config = create_dbeaver_connection(conn, connection_id)
|
||||
|
|
@ -171,21 +205,32 @@ def generate_dbeaver_config(connections):
|
|||
def main():
|
||||
print("Generating DBeaver data-sources.json from sdm status --json...")
|
||||
|
||||
output_file = os.path.expanduser('~/.local/share/DBeaverData/workspace6/Stuzo/.dbeaver/data-sources.json')
|
||||
|
||||
# Load existing config to preserve non-SDM connections
|
||||
existing_config = load_existing_config(output_file)
|
||||
existing_count = len(existing_config.get("connections", {}))
|
||||
print(f"📁 Found {existing_count} existing connections")
|
||||
|
||||
sdm_data = run_sdm_status()
|
||||
if not sdm_data:
|
||||
return
|
||||
|
||||
connections = parse_postgres_connections(sdm_data)
|
||||
print(f"Found {len(connections)} PostgreSQL connections")
|
||||
print(f"🔍 Found {len(connections)} PostgreSQL connections from SDM")
|
||||
|
||||
folders = group_connections(connections)
|
||||
|
||||
for folder_name, conns in folders.items():
|
||||
print(f" {folder_name}: {len(conns)} connections")
|
||||
|
||||
dbeaver_config = generate_dbeaver_config(connections)
|
||||
dbeaver_config = generate_dbeaver_config(connections, existing_config)
|
||||
|
||||
final_count = len(dbeaver_config["connections"])
|
||||
preserved_count = final_count - len(connections)
|
||||
print(f"💾 Preserved {preserved_count} non-SDM connections")
|
||||
print(f"📊 Total connections: {final_count} ({preserved_count} preserved + {len(connections)} SDM)")
|
||||
|
||||
output_file = os.path.expanduser('~/.local/share/DBeaverData/workspace6/Stuzo/.dbeaver/data-sources.json')
|
||||
try:
|
||||
with open(output_file, 'w') as f:
|
||||
json.dump(dbeaver_config, f, indent='\t')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue