From 511f3c7df5f39162e947e3e7c6c68c9e28a48aa7 Mon Sep 17 00:00:00 2001 From: hopeyen Date: Fri, 3 May 2024 09:36:14 -0700 Subject: [PATCH] refactor: normalize schemaNNN and db owner before publishing snapshot --- scripts/load_snapshot.sh | 2 +- scripts/take_snapshot.sh | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/load_snapshot.sh b/scripts/load_snapshot.sh index 62a2d71..0a2d989 100755 --- a/scripts/load_snapshot.sh +++ b/scripts/load_snapshot.sh @@ -36,7 +36,7 @@ echo "ID: ${schema_id}" echo "sgdNNN: ${sgdNNN}" # Customize the snapshot file to use the identifier assigned locally; and modifies the owner -sed -i "s/sgd[0-9]*/${sgdNNN}/g" ${SNAPSHOT_FILE} +sed -i "s/sgd\([0-9]\+\|NNN\)/${sgdNNN}/g" ${SNAPSHOT_FILE} sed -i "s/OWNER TO [^;]*;/OWNER TO ${DB_USER};/g" ${SNAPSHOT_FILE} # Drop local schema and load in remote diff --git a/scripts/take_snapshot.sh b/scripts/take_snapshot.sh index 62196d0..4c3c5d9 100755 --- a/scripts/take_snapshot.sh +++ b/scripts/take_snapshot.sh @@ -42,6 +42,9 @@ FILE_NAME="snapshot_${IPFS_HASH}.sql" SNAPSHOT_ACTION=$(PGPASSWORD=$DB_PSWD pg_dump -h $DB_HOST -U $DB_USER -d $DB_NAME -n $sgdNNN > ${SERVER_STORE}/${FILE_NAME}) echo "Action result: ${SNAPSHOT_ACTION}" echo "Snapshot created: ${FILE_NAME}" +# Normalize the snapshot file to use placeholder identifier and owner +sed -i -E "s/sgd[0-9]+/sgdNNN/g" ${SERVER_STORE}/${FILE_NAME} +sed -i "s/OWNER TO [^;]*;/OWNER TO graphuser;/g" ${SERVER_STORE}/${FILE_NAME} # Query metadata data METADATA_QUERY="SELECT deployment, failed, synced, latest_ethereum_block_hash, latest_ethereum_block_number, entity_count, graft_base, graft_block_hash, graft_block_number, fatal_error, non_fatal_errors, health, reorg_count, current_reorg_depth, max_reorg_depth, last_healthy_ethereum_block_hash, last_healthy_ethereum_block_number, id, firehose_cursor, debug_fork, earliest_block_number FROM subgraphs.subgraph_deployment WHERE deployment = '${IPFS_HASH}';"