@@ -239,6 +239,77 @@ def wait_for_lro(operation_url, operation_name="Operation", timeout=300):
239239 print (" Waiting for tables to be indexed..." )
240240 time .sleep (30 )
241241
242+ # ============================================================================
243+ # Step 4: Get Fabric SQL Endpoint and Update App Service
244+ # ============================================================================
245+
246+ print (f"\n [4/4] Getting Fabric SQL endpoint..." )
247+
248+ def get_fabric_sql_endpoint ():
249+ """Get the SQL analytics endpoint for the Fabric Lakehouse"""
250+ try :
251+ url = f"{ FABRIC_API } /workspaces/{ WORKSPACE_ID } /lakehouses/{ LAKEHOUSE_ID } "
252+ resp = make_request ("GET" , url )
253+ if resp .status_code == 200 :
254+ data = resp .json ()
255+ props = data .get ("properties" , {})
256+ sql_props = props .get ("sqlEndpointProperties" , {})
257+ return sql_props .get ("connectionString" )
258+ except Exception as e :
259+ print (f" [WARN] Could not get Fabric SQL endpoint: { e } " )
260+ return None
261+
262+ FABRIC_SQL_ENDPOINT = get_fabric_sql_endpoint ()
263+
264+ if FABRIC_SQL_ENDPOINT :
265+ print (f" [OK] SQL Endpoint: { FABRIC_SQL_ENDPOINT } " )
266+
267+ # Save to fabric_ids.json
268+ fabric_ids ["sql_endpoint" ] = FABRIC_SQL_ENDPOINT
269+ with open (fabric_ids_path , "w" ) as f :
270+ json .dump (fabric_ids , f , indent = 2 )
271+
272+ # Update App Service env vars
273+ subscription_id = os .getenv ("AZURE_SUBSCRIPTION_ID" )
274+ resource_group = os .getenv ("RESOURCE_GROUP_NAME" )
275+ app_name = os .getenv ("API_APP_NAME" )
276+
277+ if subscription_id and resource_group and app_name :
278+ try :
279+ from azure .mgmt .web import WebSiteManagementClient
280+ from azure .identity import DefaultAzureCredential
281+
282+ web_credential = DefaultAzureCredential ()
283+ web_client = WebSiteManagementClient (web_credential , subscription_id )
284+
285+ current = web_client .web_apps .list_application_settings (resource_group , app_name )
286+ props = dict (current .properties or {})
287+
288+ # Build full ODBC connection string
289+ if FABRIC_SQL_ENDPOINT :
290+ fabric_conn_string = f"DRIVER={{ODBC Driver 18 for SQL Server}};SERVER={ FABRIC_SQL_ENDPOINT } ;DATABASE={ LAKEHOUSE_NAME } ;Encrypt=yes;TrustServerCertificate=no"
291+ else :
292+ fabric_conn_string = ""
293+
294+ new_settings = {
295+ "FABRIC_SQL_CONNECTION_STRING" : fabric_conn_string
296+ }
297+ props .update (new_settings )
298+
299+ web_client .web_apps .update_application_settings (
300+ resource_group ,
301+ app_name ,
302+ {"properties" : props }
303+ )
304+
305+ print (f" [OK] App Service settings updated" )
306+ except Exception as e :
307+ print (f" [WARN] Failed to update App Service: { e } " )
308+ else :
309+ if FABRIC_SQL_ENDPOINT :
310+ fabric_conn_string = f"DRIVER={{ODBC Driver 18 for SQL Server}};SERVER={ FABRIC_SQL_ENDPOINT } ;DATABASE={ LAKEHOUSE_NAME } ;Encrypt=yes;TrustServerCertificate=no"
311+ print (f" NOTE: Set FABRIC_SQL_CONNECTION_STRING={ fabric_conn_string } in App Service" )
312+
242313# ============================================================================
243314# Summary
244315# ============================================================================
@@ -249,13 +320,10 @@ def wait_for_lro(operation_url, operation_name="Operation", timeout=300):
249320print (f"""
250321Uploaded { len (uploaded_files )} files: { ', ' .join (uploaded_files )}
251322Tables loaded: { ', ' .join (ontology_config ['tables' ].keys ())}
323+ SQL Endpoint: { FABRIC_SQL_ENDPOINT or 'Not available yet' }
252324
253325Next step - Generate schema prompt:
254326 python scripts/04_generate_agent_prompt.py
255-
256- To reload data later (e.g., with new/larger dataset):
257- python scripts/01_generate_sample_data.py --scenario <SCENARIO> --size medium
258- python scripts/03_load_fabric_data.py
259327""" )
260328
261329
0 commit comments