From 992358d2b7a45754c936b958614da519e2205a12 Mon Sep 17 00:00:00 2001 From: ramnar Date: Sat, 29 Nov 2025 18:08:23 +0530 Subject: [PATCH 1/5] automating data loader --- amrit-local-setup/loaddummydata.sh | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/amrit-local-setup/loaddummydata.sh b/amrit-local-setup/loaddummydata.sh index 6eeffc0..829fd94 100755 --- a/amrit-local-setup/loaddummydata.sh +++ b/amrit-local-setup/loaddummydata.sh @@ -6,7 +6,12 @@ PORT="3306" USER="root" PASSWORD="1234" # Path to the extracted SQL files -SQL_DIR= + +# download and extract the SQL files from the given url https://1865391384-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYfDZFIsUuulWkRHaq4c1%2Fuploads%2F1WdSAf0fQBeJOea70EXE%2FAmritMasterData.zip?alt=media&token=18e0b6d6-487c-4c0c-967a-02cdd94d61ad +wget -O AmritMasterData.zip "https://1865391384-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYfDZFIsUuulWkRHaq4c1%2Fuploads%2F1WdSAf0fQBeJOea70EXE%2FAmritMasterData.zip?alt=media&token=18e0b6d6-487c-4c0c-967a-02cdd94d61ad" +unzip AmritMasterData.zip -d AmritMasterDataFiles +rm AmritMasterData.zip +SQL_DIR="AmritMasterDataFiles/AmritMasterData" # Files and their respective databases FILES="AmritMasterData.sql m_beneficiaryregidmapping_dump_1097.sql m_beneficiaryregidmapping_dump.sql" @@ -22,12 +27,21 @@ for FILE in $FILES_ARRAY; do DATABASE=$(echo $DATABASES_ARRAY | cut -d ' ' -f $(($i+1))) # get corresponding database echo "Running $FILE on $DATABASE..." - mysql -h "$HOST" -P "$PORT" -u "$USER" -p"$PASSWORD" "$DATABASE" < "$SQL_DIR/$FILE" + # Execute SQL and capture output, filtering out duplicate key errors + OUTPUT=$(mysql -h "$HOST" -P "$PORT" -u "$USER" -p"$PASSWORD" "$DATABASE" < "$SQL_DIR/$FILE" 2>&1) + EXIT_CODE=$? - if [ $? -eq 0 ]; then + # Check if error is only due to duplicate entries (error code 1062) + if [ $EXIT_CODE -eq 0 ]; then echo "Successfully executed $FILE on $DATABASE." + elif echo "$OUTPUT" | grep -q "ERROR 1062"; then + echo "Completed $FILE on $DATABASE (duplicate entries skipped)." else - echo "Error executing $FILE on $DATABASE." + echo "Error executing $FILE on $DATABASE: $OUTPUT" fi i=$(($i+1)) # Increment index for the next database done + +# Clean up the extracted files +rm -rf AmritMasterDataFiles +echo "Cleaned up AmritMasterDataFiles folder." From 84e609afb882a61b4447dc179e75083d12722fb0 Mon Sep 17 00:00:00 2001 From: ramnar Date: Sun, 7 Dec 2025 14:23:36 +0530 Subject: [PATCH 2/5] updated windows script --- amrit-local-setup/loaddummydata.bat | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/amrit-local-setup/loaddummydata.bat b/amrit-local-setup/loaddummydata.bat index f265841..80ba8b3 100644 --- a/amrit-local-setup/loaddummydata.bat +++ b/amrit-local-setup/loaddummydata.bat @@ -6,8 +6,16 @@ set PORT=3306 set USER=root set PASSWORD=1234 +:: 1. Download the file using PowerShell's Invoke-WebRequest (equivalent to wget) +echo Downloading AmritMasterData.zip... +powershell -Command "Invoke-WebRequest -Uri 'https://1865391384-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYfDZFIsUuulWkRHaq4c1%2Fuploads%2F1WdSAf0fQBeJOea70EXE%2FAmritMasterData.zip?alt=media&token=18e0b6d6-487c-4c0c-967a-02cdd94d61ad' -OutFile 'AmritMasterData.zip'" + +:: 2. Extract the file using PowerShell's Expand-Archive (equivalent to unzip) +echo Extracting AmritMasterData.zip... +powershell -Command "Expand-Archive -Path 'AmritMasterData.zip' -DestinationPath 'AmritMasterDataFiles'" + :: Path to the extracted SQL files -set SQL_DIR= +set SQL_DIR="AmritMasterDataFiles/AmritMasterData" :: Associating files with databases set DATABASES="AmritMasterData.sql=db_iemr" "m_beneficiaryregidmapping_dump_1097.sql=db_1097_identity" "m_beneficiaryregidmapping_dump.sql=db_identity" @@ -30,3 +38,8 @@ for %%F in (%DATABASES%) do ( ) pause + +# Clean up the extracted files +del AmritMasterData.zip +rmdir /s /q AmritMasterDataFiles +echo Cleaned up AmritMasterDataFiles folder. From d83f24d9c68fd47fac5414b419d321299eed0be3 Mon Sep 17 00:00:00 2001 From: ramnar Date: Sun, 7 Dec 2025 14:50:44 +0530 Subject: [PATCH 3/5] udpated readme file --- amrit-local-setup/README.md | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/amrit-local-setup/README.md b/amrit-local-setup/README.md index 73cf722..b4d096c 100644 --- a/amrit-local-setup/README.md +++ b/amrit-local-setup/README.md @@ -8,6 +8,7 @@ - Maven 3.6+ - Git version control - OpenJDK 17+ +- MySQL Client ## Architecture Overview @@ -15,7 +16,7 @@ The setup leverages containerization for consistent development environments acr ## Deployment Steps -First, clone the DevOps repository and navigate to the local setup directory: +First, clone the DevOps repository, navigate to the local setup directory and initialize the container services: ```bash git clone https://github.com/PSMRI/AMRIT-DevOps.git @@ -38,9 +39,8 @@ docker-compose up **Important:** If these services are already running on your host machine, stop the local MySQL, Mongo and Redis instances before proceeding. -**Note:** Before proceeding: +**Note:** Before proceeding, Verify that the Docker containers are running for mysql, redis and mongo -- Verify that the Docker container is running ### 2. Database Schema Management Service Deployment #### Repository Configuration @@ -48,34 +48,14 @@ docker-compose up ```bash git clone https://github.com/PSMRI/AMRIT-DB.git cd AMRIT-DB +cp `src/main/environment/common_example.properties` to `src/main/environment/common_local.properties` +mvn clean install -DENV_VAR=local ``` -1. **Setup Local Properties**: - - Copy `common_example.properties` to `common_local.properties`. - - File location: `src/main/environment` - -2. **Create Build Configuration through CLI**: - ``` - mvn clean install -DENV_VAR=local - ``` ---- - -## Run Configuration - -1. **Setup Spring Boot through CLI**: - ``` - mvn spring-boot:run -DENV_VAR=local - ``` --- ### 3. Load Sample Data -#### Data Package Setup - -1. Download the Data zip folder (`Amrit_MastersData.zip`) from the [official documentation](https://piramal-swasthya.gitbook.io/amrit/data-management/database-schema) -2. Extract the archive contents -3. Update the data path in the appropriate script: - - Line 10 in `loaddummydata.sh` (Linux/MacOS) - - Line 10 in `loaddummydata.bat` (Windows) +Run the below script to load sample Data into the database tables created in the previous step #### Execute Data Load From c54a12b43d695dd3b6e3b36d3e0210846c67981f Mon Sep 17 00:00:00 2001 From: ramnar Date: Sun, 7 Dec 2025 15:00:15 +0530 Subject: [PATCH 4/5] updated batch script --- amrit-local-setup/loaddummydata.bat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/amrit-local-setup/loaddummydata.bat b/amrit-local-setup/loaddummydata.bat index 80ba8b3..e7b7b30 100644 --- a/amrit-local-setup/loaddummydata.bat +++ b/amrit-local-setup/loaddummydata.bat @@ -6,11 +6,11 @@ set PORT=3306 set USER=root set PASSWORD=1234 -:: 1. Download the file using PowerShell's Invoke-WebRequest (equivalent to wget) +:: Download the file using PowerShell's Invoke-WebRequest (equivalent to wget) echo Downloading AmritMasterData.zip... powershell -Command "Invoke-WebRequest -Uri 'https://1865391384-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FYfDZFIsUuulWkRHaq4c1%2Fuploads%2F1WdSAf0fQBeJOea70EXE%2FAmritMasterData.zip?alt=media&token=18e0b6d6-487c-4c0c-967a-02cdd94d61ad' -OutFile 'AmritMasterData.zip'" -:: 2. Extract the file using PowerShell's Expand-Archive (equivalent to unzip) +:: Extract the file using PowerShell's Expand-Archive (equivalent to unzip) echo Extracting AmritMasterData.zip... powershell -Command "Expand-Archive -Path 'AmritMasterData.zip' -DestinationPath 'AmritMasterDataFiles'" From 219d86e8d56cea7e495d942daaf6a9f98fbcbee7 Mon Sep 17 00:00:00 2001 From: ramnar Date: Sat, 3 Jan 2026 14:12:27 +0530 Subject: [PATCH 5/5] updated readme based on feedback --- amrit-local-setup/README.md | 44 +++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/amrit-local-setup/README.md b/amrit-local-setup/README.md index b4d096c..25e85df 100644 --- a/amrit-local-setup/README.md +++ b/amrit-local-setup/README.md @@ -1,6 +1,12 @@ # AMRIT Local Environment Setup Guide -## System Requirements +## Overview + +AMRIT Local Database Environment Setup activity involves three activities + +1) Start the MySQL, MongoDB and Redis databases as Docker Containers +2) Create the Database Schema for AMRIT +3) Load the Database with Sample Data ### Mandatory Dependencies @@ -10,24 +16,16 @@ - OpenJDK 17+ - MySQL Client -## Architecture Overview - -The setup leverages containerization for consistent development environments across the team. Core services are orchestrated via Docker, with MySQL, Mongo and Redis instances running in isolated containers. ## Deployment Steps -First, clone the DevOps repository, navigate to the local setup directory and initialize the container services: +### 1. Start the Databases + +First, run the below commands to clone the DevOps repository, navigate to the local setup directory and initialize the container services: ```bash git clone https://github.com/PSMRI/AMRIT-DevOps.git cd AMRIT-DevOps/amrit-local-setup -``` - -### 1. Container Orchestration - -Initialize the containerized services: - -```bash docker-compose up ``` @@ -39,25 +37,25 @@ docker-compose up **Important:** If these services are already running on your host machine, stop the local MySQL, Mongo and Redis instances before proceeding. -**Note:** Before proceeding, Verify that the Docker containers are running for mysql, redis and mongo +**Note:** Before proceeding, Verify that the Docker containers are running for MySQL, Mongo and Redis. -### 2. Database Schema Management Service Deployment +### 2. Create the Database Schema + +Use the below commands to Run the Database Schema Management Service. This is a Java Service which is used to create the database schema in MySQL Instance -#### Repository Configuration ```bash git clone https://github.com/PSMRI/AMRIT-DB.git cd AMRIT-DB cp `src/main/environment/common_example.properties` to `src/main/environment/common_local.properties` mvn clean install -DENV_VAR=local +mvn spring-boot:run -DENV_VAR=local ``` --- -### 3. Load Sample Data - -Run the below script to load sample Data into the database tables created in the previous step +### 3. Load Sample Data in the Database Tables -#### Execute Data Load +Run the below script to load sample Data into the database tables.The data will be loaded and persistently stored in the MySQL instance. For Linux/Unix systems: @@ -71,10 +69,8 @@ For Windows (PowerShell): .\loaddummydata.bat ``` -The data will be loaded and persistently stored in the containerized MySQL instance. +## Troubleshooting Tips -## Troubleshooting - -- Ensure all ports (3306, 6379, 27017) are available before starting the containers - Verify Docker daemon is running before executing docker-compose -- Check container logs if services fail to start +- Ensure all ports (3306, 6379, 27017) are available before starting the containers +- Check the container logs to see if services failed to start