From 87f0c9f56127d6ba7568df10f8be85d0131513a4 Mon Sep 17 00:00:00 2001 From: Abdul-Microsoft Date: Fri, 24 Apr 2026 15:28:05 +0530 Subject: [PATCH] chore: remove unused deployment scripts and update AVM post-deployment guide --- docs/AVMPostDeploymentGuide.md | 17 +++- docs/postgreSQL.md | 6 +- .../data_scripts/azure_credential_utils.py | 48 ---------- .../data_scripts/create_postgres_tables.py | 91 ------------------- scripts/run_create_table_script.sh | 35 ------- 5 files changed, 17 insertions(+), 180 deletions(-) delete mode 100644 scripts/data_scripts/azure_credential_utils.py delete mode 100644 scripts/data_scripts/create_postgres_tables.py delete mode 100644 scripts/run_create_table_script.sh diff --git a/docs/AVMPostDeploymentGuide.md b/docs/AVMPostDeploymentGuide.md index 5084a1bc9..d1ce20447 100644 --- a/docs/AVMPostDeploymentGuide.md +++ b/docs/AVMPostDeploymentGuide.md @@ -12,13 +12,24 @@ Ensure you have a **Deployed Infrastructure** - A successful Chat with your data ## Post Deployment Steps -### Step 1: Configure App Authentication +### Step 1: Run the Post-Deployment Setup Script + +Run the post-deployment setup script to configure the Function App client key and create PostgreSQL tables (if applicable). Open [Azure Cloud Shell](https://shell.azure.com) (Bash) and run: + +```bash +az login +git clone https://github.com/Azure-Samples/chat-with-your-data-solution-accelerator.git +cd chat-with-your-data-solution-accelerator +bash scripts/post_deployment_setup.sh "" +``` + +### Step 2: Configure App Authentication 1. After deployment is complete, navigate to your Azure App Service in the Azure portal 2. Follow the detailed instructions in [Set Up Authentication in Azure App Service](./azure_app_service_auth_setup.md) to add authentication to your web app 3. This will ensure only authorized users can access your application -### Step 2: Access and Configure the Admin Site +### Step 3: Access and Configure the Admin Site 1. **Navigate to the admin site** using the following URL pattern: ``` @@ -36,7 +47,7 @@ Ensure you have a **Deployed Infrastructure** - A successful Chat with your data - Wait for the documents to be processed and indexed - Verify successful ingestion through the admin interface -### Step 3: Access the Chat Application +### Step 4: Access the Chat Application 1. **Navigate to the main chat application** using this URL pattern: ``` diff --git a/docs/postgreSQL.md b/docs/postgreSQL.md index 5e982f57c..4079b88dc 100644 --- a/docs/postgreSQL.md +++ b/docs/postgreSQL.md @@ -57,8 +57,8 @@ LIMIT $2; --- -### 4. **Automated Table Creation** -The PostgreSQL deployment process automatically creates the necessary tables for chat history and vector storage, including table indexes. The script `create_postgres_tables.py` is executed as part of the infrastructure deployment, ensuring the database is ready for use immediately after setup. +### 4. **Table Creation** +The necessary PostgreSQL tables for chat history and vector storage, including table indexes, are created as part of the post-deployment steps. The `setup_postgres_tables.py` script is executed during post-deployment, and once complete, the database will be ready for use. --- @@ -78,7 +78,7 @@ All PostgreSQL connections use secure configurations: ## Benefits of PostgreSQL Integration 1. **Scalability**: PostgreSQL offers robust data storage and table indexing capabilities suitable for large-scale deployments 2. **Flexibility**: Dynamic database switching allows users to choose between PostgreSQL and CosmosDB based on their requirements. -3. **Ease of Use**: Automated table creation and environment configuration simplify deployment and management. +3. **Ease of Use**: A single post-deployment script handles table creation and environment configuration, simplifying deployment and management. 4. **Security**: SSL-enabled connections and secure credential handling ensure data protection. diff --git a/scripts/data_scripts/azure_credential_utils.py b/scripts/data_scripts/azure_credential_utils.py deleted file mode 100644 index e8d9d7051..000000000 --- a/scripts/data_scripts/azure_credential_utils.py +++ /dev/null @@ -1,48 +0,0 @@ -import os -from azure.identity import ManagedIdentityCredential, DefaultAzureCredential -from azure.identity.aio import ( - ManagedIdentityCredential as AioManagedIdentityCredential, - DefaultAzureCredential as AioDefaultAzureCredential, -) - - -async def get_azure_credential_async(client_id=None): - """ - Returns an Azure credential asynchronously based on the application environment. - - If the environment is 'dev', it uses AioDefaultAzureCredential. - Otherwise, it uses AioManagedIdentityCredential. - - Args: - client_id (str, optional): The client ID for the Managed Identity Credential. - - Returns: - Credential object: Either AioDefaultAzureCredential or AioManagedIdentityCredential. - """ - if os.getenv("APP_ENV", "prod").lower() == "dev": - return ( - AioDefaultAzureCredential() - ) # CodeQL [SM05139] Okay use of DefaultAzureCredential as it is only used in development - else: - return AioManagedIdentityCredential(client_id=client_id) - - -def get_azure_credential(client_id=None): - """ - Returns an Azure credential based on the application environment. - - If the environment is 'dev', it uses DefaultAzureCredential. - Otherwise, it uses ManagedIdentityCredential. - - Args: - client_id (str, optional): The client ID for the Managed Identity Credential. - - Returns: - Credential object: Either DefaultAzureCredential or ManagedIdentityCredential. - """ - if os.getenv("APP_ENV", "prod").lower() == "dev": - return ( - DefaultAzureCredential() - ) # CodeQL [SM05139] Okay use of DefaultAzureCredential as it is only used in development - else: - return ManagedIdentityCredential(client_id=client_id) diff --git a/scripts/data_scripts/create_postgres_tables.py b/scripts/data_scripts/create_postgres_tables.py deleted file mode 100644 index 198058900..000000000 --- a/scripts/data_scripts/create_postgres_tables.py +++ /dev/null @@ -1,91 +0,0 @@ -from azure_credential_utils import get_azure_credential -import psycopg2 - -user = "managedIdentityName" -host = "serverName" -dbname = "postgres" - - -# Acquire the access token -cred = get_azure_credential() -access_token = cred.get_token("https://ossrdbms-aad.database.windows.net/.default") - -# Combine the token with the connection string to establish the connection. -conn_string = "host={0} user={1} dbname={2} password={3} sslmode=require".format( - host, user, dbname, access_token.token -) -conn = psycopg2.connect(conn_string) -cursor = conn.cursor() - -# Drop and recreate the conversations table -cursor.execute("DROP TABLE IF EXISTS conversations") -conn.commit() - -create_cs_sql = """CREATE TABLE conversations ( - id TEXT PRIMARY KEY, - conversation_id TEXT NOT NULL, - type TEXT NOT NULL, - "createdAt" TEXT, - "updatedAt" TEXT, - user_id TEXT NOT NULL, - title TEXT - );""" -cursor.execute(create_cs_sql) -conn.commit() - -# Drop and recreate the messages table -cursor.execute("DROP TABLE IF EXISTS messages") -conn.commit() - -create_ms_sql = """CREATE TABLE messages ( - id TEXT PRIMARY KEY, - type VARCHAR(50) NOT NULL, - "createdAt" TEXT, - "updatedAt" TEXT, - user_id TEXT NOT NULL, - conversation_id TEXT NOT NULL, - role VARCHAR(50), - content TEXT NOT NULL, - feedback TEXT - );""" -cursor.execute(create_ms_sql) -conn.commit() - - -# Add Vector extension -cursor.execute("CREATE EXTENSION IF NOT EXISTS vector CASCADE;") -conn.commit() - -cursor.execute("DROP TABLE IF EXISTS vector_store;") -conn.commit() - -table_create_command = """CREATE TABLE IF NOT EXISTS vector_store( - id text, - title text, - chunk integer, - chunk_id text, - "offset" integer, - page_number integer, - content text, - source text, - metadata text, - content_vector public.vector(1536) -);""" - -cursor.execute(table_create_command) -conn.commit() - - -cursor.execute( - "CREATE INDEX vector_store_content_vector_idx ON vector_store USING hnsw (content_vector vector_cosine_ops);" -) -conn.commit() - - -cursor.execute("ALTER TABLE public.conversations OWNER TO azure_pg_admin;") -cursor.execute("ALTER TABLE public.messages OWNER TO azure_pg_admin;") -cursor.execute("ALTER TABLE public.vector_store OWNER TO azure_pg_admin;") -conn.commit() - -cursor.close() -conn.close() diff --git a/scripts/run_create_table_script.sh b/scripts/run_create_table_script.sh deleted file mode 100644 index adcec4d73..000000000 --- a/scripts/run_create_table_script.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -echo "started the script" - -# Variables -baseUrl="$1" -requirementFile="requirements.txt" -requirementFileUrl=${baseUrl}"scripts/data_scripts/requirements.txt" -resourceGroup="$2" -serverName="$3" -managedIdentityName="$4" - -echo "Script Started" - -# Get the public IP address of the machine running the script -publicIp=$(curl -s https://api.ipify.org) - -# Use Azure CLI to add the public IP to the PostgreSQL firewall rule -az postgres flexible-server firewall-rule create --resource-group $resourceGroup --name $serverName --rule-name "AllowScriptIp" --start-ip-address "$publicIp" --end-ip-address "$publicIp" - -# Download the create table python file -curl --output "create_postgres_tables.py" ${baseUrl}"scripts/data_scripts/create_postgres_tables.py" -curl --output "azure_credential_utils.py" ${baseUrl}"scripts/data_scripts/azure_credential_utils.py" - -# Download the requirement file -curl --output "$requirementFile" "$requirementFileUrl" - -echo "Download completed" - -# Replace placeholders in the python script with actual values -sed -i "s/managedIdentityName/${managedIdentityName}/g" "create_postgres_tables.py" -sed -i "s/serverName/${serverName}/g" "create_postgres_tables.py" - -pip install -r requirements.txt - -python create_postgres_tables.py