Skip to content

Commit c93a82d

Browse files
Arta AsadiArta Asadi
Arta Asadi
authored and
Arta Asadi
committed
fix: update demo data export script
1 parent 9eed043 commit c93a82d

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

Diff for: scripts/export_plugin_data.sh

100644100755
+20-22
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
echo "NEEDED ENV Variables are: [PLUGIN_ID, ES_INDEX_PREFIX, DB_PASSWORD, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, ENDPOINT_URL, ELASTICSEARCH_PASSWORD, OPENSSL_PASSWORD, DEMO_DATA_S3_PATH]"
1+
echo "NEEDED ENV Variables are: [INTEGRATION_TYPE, ES_INDEX_PREFIX, DB_PASSWORD, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, ENDPOINT_URL, ELASTICSEARCH_PASSWORD, OPENSSL_PASSWORD, DEMO_DATA_S3_PATH]"
22

3-
mkdir -p /tmp/demo-data
3+
rm -rf /tmp/demo-data
44

5+
mkdir -p /tmp/demo-data
6+
echo "$DB_PASSWORD"
57

68
DB_HOST="${DB_HOST:-localhost}"
79
DB_PORT="${DB_PORT:-5432}"
@@ -15,8 +17,8 @@ if [ -z "$DB_PASSWORD" ]; then
1517
exit 1
1618
fi
1719

18-
if [ -z "$PLUGIN_ID" ]; then
19-
echo "Error: PLUGIN_ID environment variable is not set." >&2
20+
if [ -z "$INTEGRATION_TYPE" ]; then
21+
echo "Error: INTEGRATION_TYPE environment variable is not set." >&2
2022
exit 1
2123
fi
2224

@@ -27,36 +29,36 @@ fi
2729

2830
export PGPASSWORD="$DB_PASSWORD"
2931

30-
SQL_QUERY=$(cat <<-EOF
32+
SQL_QUERY=$(cat <<EOF
3133
SELECT
3234
json_build_object(
33-
'integrationId', integration_id::text, -- Cast UUID to text if needed
35+
'integrationId', integration_id::text,
3436
'providerId', provider_id,
3537
'name', name,
36-
'integrationType', integration_type, -- Assuming it's stored as text compatible with your Go type
37-
'annotations', annotations, -- Assuming annotations is a JSONB column
38-
'labels', labels -- Assuming labels is a JSONB column
38+
'integrationType', integration_type,
39+
'annotations', annotations,
40+
'labels', labels
3941
)
4042
FROM
4143
integrations
4244
WHERE
43-
integration_type = '${PLUGIN_ID}';
45+
integration_type = '${INTEGRATION_TYPE}';
4446
EOF
4547
)
4648

47-
echo "Connecting to database '$DB_NAME' on '$DB_HOST:$DB_PORT' as user '$DB_USER'..."
48-
echo "Executing query and exporting to '$OUTPUT_FILE'..."
49+
echo "Connecting to database $DB_NAME on $DB_HOST:$DB_PORT as user $DB_USER..."
50+
echo "Executing query and exporting to $OUTPUT_FILE..."
4951

5052
psql -X -A -t -q -v ON_ERROR_STOP=1 \
5153
-h "$DB_HOST" \
5254
-p "$DB_PORT" \
5355
-U "$DB_USER" \
5456
-d "$DB_NAME" \
5557
-c "$SQL_QUERY" | \
56-
jq -s '.' > "$OUTPUT_FILE"
58+
jq -s "." > "$OUTPUT_FILE"
5759

5860
if [ -s "$OUTPUT_FILE" ]; then
59-
echo "Successfully exported integrations to '$OUTPUT_FILE'."
61+
echo "Successfully exported integrations to $OUTPUT_FILE."
6062
else
6163
echo "Error: Failed to export data or the table is empty. Output file is empty or not created." >&2
6264
exit 1
@@ -92,20 +94,16 @@ export NODE_TLS_REJECT_UNAUTHORIZED=0
9294
multielasticdump \
9395
--direction=dump \
9496
--input="$NEW_ELASTICSEARCH_ADDRESS" \
95-
--output="/tmp/demo-data/es-demo/" \
97+
--output="/tmp/demo-data/es-demo" \
9698
--parallel=20 \
97-
--match='^'${ES_INDEX_PREFIX}'.*$' \
99+
--match="^${ES_INDEX_PREFIX}.*$" \
98100
--matchType=alias \
99101
--limit=10000 \
100102
--scrollTime=10m \
101-
--searchBody='{"query": {"bool": {"must_not": {"term": {"deleted": true}}}}}' \
103+
--searchBody="{\"query\": {\"bool\": {\"must_not\": {\"term\": {\"deleted\": true}}}}}" \
102104
--ignoreTemplate=true
103105

104106
cd /tmp
105-
tar -cO demo-data | openssl enc -aes-256-cbc -md md5 -pass pass:"$OPENSSL_PASSWORD" -base64 > demo_data.tar.gz.enc
106-
107-
FILE_SIZE_BYTES=$(stat -c %s /tmp/demo_data.tar.gz.enc)
108-
FILE_SIZE_MB=$(echo "scale=2; $FILE_SIZE_BYTES / 1048576" | bc)
109-
echo "File size: ${FILE_SIZE_MB} MB"
107+
tar -cf - demo-data | openssl enc -aes-256-cbc -md md5 -pass pass:"$OPENSSL_PASSWORD" -base64 > demo_data.tar.gz.enc
110108

111109
rclone copy /tmp/demo_data.tar.gz.enc "$DEMO_DATA_S3_PATH"

0 commit comments

Comments
 (0)