Sometimes, you only need to add TRANDATA to a set of tables, and it’s really easy to automate that with REST calls in a simple script.
Here is an example for the table EMPLOYEE and COUNTRY in the HR sample schema:
Create a .netrc file (or another named file, e.g., .ogg_netrc.sh) with the following contents:
machine localhost login oggadmin password <password>
Make sure the file is readable only by you:
chmod 600 ~/.ogg_netrc.sh
#!/bin/bash
# Configuration
HOST="localhost"
PORT="9012"
CONNECTION_NAME="WEST"
NETRC_FILE="$HOME/.ogg_netrc.sh"
# Tables to configure
SCHEMA="HR"
TABLES=("EMPLOYEE" "COUNTRY")
# Loop through each table and add TRANDATA
for TABLE in "${TABLES[@]}"; do
echo "Adding TRANDATA for $SCHEMA.$TABLE..."
curl -s --netrc-file "$NETRC_FILE" \
-X POST "http://$HOST:$PORT/services/v2/connections/$CONNECTION_NAME/trandata/table" \
-H "Content-Type: application/json" \
-d "{
\"\$schema\": \"ogg:trandataTable\",
\"operation\": \"add\",
\"schemaName\": \"$SCHEMA\",
\"tableName\": \"$TABLE\",
\"allColumns\": false,
\"schedulingColumns\": true
}" | jq .
done
Run It:
chmod +x add_trandata_tables.sh
./add_trandata_tables.sh
Here is just the curl example:
curl -i -X POST "http://<hostname>:<port>/services/v2/connections/<connection>/trandata/table" \
-u <username>:<password> \
-H "Content-Type: application/json" \
-d '{
"$schema": "ogg:trandataTable",
"operation": "add",
"schemaName": "HR",
"tableName": "EMPLOYEES",
"allColumns": false,
"schedulingColumns": true
}'
Leave a comment