Created
February 7, 2025 02:47
-
-
Save nickva/08469fd72500031d96b2a0265f8f5ec4 to your computer and use it in GitHub Desktop.
CouchDB replicate attachment twice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Create test DBs | |
echo "***** SETTING UP DBS *****" | |
curl -s -XDELETE 'http://adm:pass@localhost:15984/source' | |
curl -s -XDELETE 'http://adm:pass@localhost:15984/target' | |
curl -s -XPUT 'http://adm:pass@localhost:15984/source' | |
echo '{ | |
"_id": "c2561fa83ffe5658a60b6ee757000e49", | |
"count": 1, | |
"_attachments": { | |
"1mb_of_text.txt": { | |
"data": "'"$(base64 -i 1mb_of_text.txt)"'", | |
"content_type": "plain/text" | |
} | |
} | |
}' > payload.json | |
echo "**** CREATING DOC + ATTACHMENT **** " | |
curl -s -XPOST 'http://adm:pass@localhost:15984/source' -H'Content-Type:application/json' --data-binary @payload.json | |
curl -XGET 'http://adm:pass@localhost:15984/source/c2561fa83ffe5658a60b6ee757000e49' | |
# Replicate to target | |
echo "*** REPLICATE 1st TIME ****" | |
curl -XPOST 'http://adm:pass@localhost:15984/_replicate' -H'Content-Type: application/json' --data-raw '{"source": "http://adm:pass@localhost:15984/source", "target": "http://adm:pass@localhost:15984/target", "create_target": true}' | |
echo " ***** UPDATE DOC *****" | |
# Update 'count' in doc | |
curl -XPOST 'http://adm:pass@localhost:15984/source' -H'Content-Type: application/json' --data-raw '{ | |
"_id": "c2561fa83ffe5658a60b6ee757000e49", | |
"_rev": "1-3ddeb6f3d3d3f03f88586e6ebd4c018d", | |
"count": 2, | |
"_attachments": { | |
"1mb_of_text.txt": { | |
"content_type": "plain/text", | |
"revpos": 1, | |
"digest": "md5-1QgRMiOm8E99aKuoi3cKPw==", | |
"length": 1024000, | |
"stub": true | |
}}}' | |
echo "***** REPLICATE 2nd TIME ****" | |
# Replicate again to target | |
curl -XPOST 'http://adm:pass@localhost:15984/_replicate' -H'Content-Type: application/json' --data-raw '{"source": "http://adm:pass@localhost:15984/source", "target": "http://adm:pass@localhost:15984/target", "create_target": true}' | |
echo "**** SLEEP 10 sec wait for compaction ****" | |
sleep 10 | |
echo | |
echo | |
echo "******* CHECKING SOURCE AND TARGET ******" | |
echo | |
curl -s -XGET 'http://adm:pass@localhost:15984/source' | jq '.sizes.file' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On main:
On 3.4.2