-
Notifications
You must be signed in to change notification settings - Fork 10
Bugfix/data loading #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,8 +6,16 @@ set PORT=3306 | |||||||||||||||||
| set USER=root | ||||||||||||||||||
| set PASSWORD=1234 | ||||||||||||||||||
|
|
||||||||||||||||||
| :: 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'" | ||||||||||||||||||
|
|
||||||||||||||||||
| :: Extract the file using PowerShell's Expand-Archive (equivalent to unzip) | ||||||||||||||||||
| echo Extracting AmritMasterData.zip... | ||||||||||||||||||
| powershell -Command "Expand-Archive -Path 'AmritMasterData.zip' -DestinationPath 'AmritMasterDataFiles'" | ||||||||||||||||||
|
|
||||||||||||||||||
|
Comment on lines
+9
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. External download URL embeds a token; consider treating it as a secret and hardening failure handling. The GitBook URL used in Consider:
🧰 Tools🪛 Gitleaks (8.30.0)[high] 11-11: Detected a Generic API Key, potentially exposing access to various services and sensitive operations. (generic-api-key) 🤖 Prompt for AI Agents |
||||||||||||||||||
| :: Path to the extracted SQL files | ||||||||||||||||||
| set SQL_DIR=<PATH to the extracted files directory> | ||||||||||||||||||
| set SQL_DIR="AmritMasterDataFiles/AmritMasterData" | ||||||||||||||||||
|
Comment on lines
17
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix
A safer pattern is: - set SQL_DIR="AmritMasterDataFiles/AmritMasterData"
+ set "SQL_DIR=AmritMasterDataFiles\AmritMasterData"Then keep the existing usage 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
| :: 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. | ||||||||||||||||||
|
Comment on lines
+42
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Batch comment syntax: use
Change it to something like: -# Clean up the extracted files
+:: Clean up the extracted files
del AmritMasterData.zip
rmdir /s /q AmritMasterDataFiles
echo Cleaned up AmritMasterDataFiles folder.📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,12 @@ PORT="3306" | |
| USER="root" | ||
| PASSWORD="1234" | ||
| # Path to the extracted SQL files | ||
| SQL_DIR=<PATH to the extracted files directory> | ||
|
|
||
| # 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" | ||
|
|
||
|
Comment on lines
+10
to
15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Download URL with embedded token may be sensitive and is a single point of failure. The hard-coded GitBook URL (with Recommendations:
🧰 Tools🪛 Gitleaks (8.30.0)[high] 10-10: Detected a Generic API Key, potentially exposing access to various services and sensitive operations. (generic-api-key) [high] 11-11: Detected a Generic API Key, potentially exposing access to various services and sensitive operations. (generic-api-key) 🤖 Prompt for AI Agents |
||
| # 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." | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My worry is that this DB dump can change in the documentation (with the same file name). Also, I am not sure if the token will expire any time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid Point. I was thinking about it.
File url will change when new data dump is added to the documentation. We need to update the script as well whenever we update the dump file in gitbook. Token doesnt seem to expire as long as the file name is same
Other option is to maintain the dump file in github rather than gitbook. As the file size is large, we need to use git LFS
Do you have any other ideas?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@drtechie - End goal I am trying to achieve in future is to have a single script to start database containers, start schema management service and load dummy data. I believe we can have this single script in schema management service git repository itself. Load dummy data can be integrated with schema management service based one some flag