#!/bin/bash # regenerate_sqlx_cache.sh # # Script to regenerate SQLx query cache for monero-rpc-pool # # This script: # 1. Creates a temporary SQLite database in a temp directory # 2. Runs all database migrations to set up the schema # 3. Regenerates the SQLx query cache (.sqlx directory) # 4. Cleans up temporary files automatically # # Usage: # ./regenerate_sqlx_cache.sh # # Requirements: # - cargo and sqlx-cli must be installed # - Must be run from the monero-rpc-pool directory # - migrations/ directory must exist with valid migration files # # The generated .sqlx directory should be committed to version control # to enable offline compilation without requiring DATABASE_URL. set -e # Exit on any error echo "๐Ÿ”„ Regenerating SQLx query cache..." # Create a temporary directory for the database TEMP_DIR=$(mktemp -d) TEMP_DB="$TEMP_DIR/temp_sqlx_cache.sqlite" DATABASE_URL="sqlite:$TEMP_DB" echo "๐Ÿ“ Using temporary database: $TEMP_DB" # Function to cleanup on exit cleanup() { echo "๐Ÿงน Cleaning up temporary files..." rm -rf "$TEMP_DIR" } trap cleanup EXIT # Export DATABASE_URL for sqlx commands export DATABASE_URL echo "๐Ÿ—„๏ธ Creating database..." cargo sqlx database create echo "๐Ÿ”„ Running migrations..." cargo sqlx migrate run echo "โšก Preparing SQLx query cache..." cargo sqlx prepare echo "โœ… SQLx query cache regenerated successfully!" echo "๐Ÿ“ The .sqlx directory has been updated with the latest query metadata." echo "๐Ÿ’ก Make sure to commit the .sqlx directory to version control."