Skip to content

Commit

Permalink
fix: use COPY for large binary files
Browse files Browse the repository at this point in the history
  • Loading branch information
0xawaz committed Nov 25, 2024
1 parent 3aadd4d commit 44bd8eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
2 changes: 1 addition & 1 deletion fhevm-engine/coprocessor/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ services:

migration:
container_name: migration
image: ghcr.io/zama-ai/fhevm-db-migration:v1
image: ghcr.io/zama-ai/fhevm-db-migration:v1.1
environment:
DATABASE_URL: postgresql://postgres:postgres@db:5432/coprocessor
depends_on:
Expand Down
37 changes: 14 additions & 23 deletions fhevm-engine/fhevm-db/initialize_db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,23 @@ echo "Running migrations..."
sqlx migrate run --source /migrations || { echo "Failed to run migrations."; exit 1; }

# 3. Insert test tenant with keys
echo "Running Insert test tenant..."
echo "Start preparing tenant query..."
TENANT_API_KEY=a1503fb6-d79b-4e9e-826d-44cf262f3e05
CHAIN_ID=12345
ACL_CONTRACT_ADDRESS=0x339EcE85B9E11a3A3AA557582784a15d7F82AAf2
INPUT_VERIFIER_ADDRESS=0x69dE3158643e738a0724418b21a35FAA20CBb1c5
PKS_FILE="/fhevm-keys/pks"
SKS_FILE="/fhevm-keys/sks"
PUBLIC_PARAMS_FILE="/fhevm-keys/pp"

PKS="$(cat /fhevm-keys/pks | xxd -p | tr -d '\n')"
SKS="$(cat /fhevm-keys/sks | xxd -p | tr -d '\n')"
PUBLIC_PARAMS="$(cat /fhevm-keys/pp | xxd -p | tr -d '\n')"
CKS="$(cat /fhevm-keys/cks | xxd -p | tr -d '\n')"

QUERY="
INSERT INTO tenants(tenant_api_key, chain_id, acl_contract_address, verifying_contract_address, pks_key, sks_key, public_params, cks_key)
VALUES (
'${TENANT_API_KEY}',
12345,
'${ACL_CONTRACT_ADDRESS}',
'${INPUT_VERIFIER_ADDRESS}',
decode('${PKS}', 'hex'),
decode('${SKS}', 'hex'),
decode('${PUBLIC_PARAMS}', 'hex'),
decode('${CKS}', 'hex')
)
"

echo $QUERY | psql $DATABASE_URL

echo 'Test tenant insertion done'
TMP_CSV="/tmp/tenant_data.csv"
echo "tenant_api_key,chain_id,acl_contract_address,verifying_contract_address,pks_key,sks_key,public_params" > $TMP_CSV

echo "$TENANT_API_KEY,$CHAIN_ID,$ACL_CONTRACT_ADDRESS,$INPUT_VERIFIER_ADDRESS,\"\\x$(cat $PKS_FILE | xxd -p | tr -d '\n')\",\"\\x$(cat $SKS_FILE | xxd -p | tr -d '\n')\",\"\\x$(cat $PUBLIC_PARAMS_FILE | xxd -p | tr -d '\n')\"" >> $TMP_CSV

echo "Inserting tenant data using \COPY..."
psql $DATABASE_URL -c "\COPY tenants (tenant_api_key, chain_id, acl_contract_address, verifying_contract_address, pks_key, sks_key, public_params) FROM '$TMP_CSV' CSV HEADER;"

rm -f $TMP_CSV

echo "Database initialization complete."

0 comments on commit 44bd8eb

Please sign in to comment.