···11+#!/bin/bash
22+33+# Script to copy .sqlx files to all Rust projects that use SQLx
44+# This is needed for offline SQLx builds (SQLX_OFFLINE=true)
55+66+set -e
77+88+# Get the script directory (should be in teal/scripts/)
99+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1010+PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
1111+1212+# Source .sqlx directory
1313+SQLX_SOURCE="$PROJECT_ROOT/.sqlx"
1414+1515+# List of projects that use SQLx (relative to project root)
1616+SQLX_PROJECTS=(
1717+ "apps/aqua"
1818+ "services/cadet"
1919+ "services/satellite"
2020+)
2121+2222+echo "🔧 Setting up SQLx offline files..."
2323+2424+# Check if source .sqlx directory exists
2525+if [ ! -d "$SQLX_SOURCE" ]; then
2626+ echo "❌ Source .sqlx directory not found at: $SQLX_SOURCE"
2727+ echo " Make sure you've run 'cargo sqlx prepare' from the services directory first."
2828+ exit 1
2929+fi
3030+3131+# Copy .sqlx files to each project that needs them
3232+for project in "${SQLX_PROJECTS[@]}"; do
3333+ project_path="$PROJECT_ROOT/$project"
3434+ target_sqlx="$project_path/.sqlx"
3535+3636+ if [ ! -d "$project_path" ]; then
3737+ echo "⚠️ Project directory not found: $project_path (skipping)"
3838+ continue
3939+ fi
4040+4141+ # Check if project actually uses SQLx
4242+ if [ ! -f "$project_path/Cargo.toml" ]; then
4343+ echo "⚠️ No Cargo.toml found in $project (skipping)"
4444+ continue
4545+ fi
4646+4747+ if ! grep -q "sqlx" "$project_path/Cargo.toml"; then
4848+ echo "⚠️ Project $project doesn't appear to use SQLx (skipping)"
4949+ continue
5050+ fi
5151+5252+ echo "📦 Copying .sqlx files to $project..."
5353+5454+ # Remove existing .sqlx directory if it exists
5555+ if [ -d "$target_sqlx" ]; then
5656+ rm -rf "$target_sqlx"
5757+ fi
5858+5959+ # Copy the .sqlx directory
6060+ cp -r "$SQLX_SOURCE" "$target_sqlx"
6161+6262+ echo " ✅ Copied $(ls -1 "$target_sqlx" | wc -l) query files"
6363+done
6464+6565+echo "✅ SQLx offline setup complete!"
6666+echo ""
6767+echo "Note: If you add new SQL queries or modify existing ones, you'll need to:"
6868+echo "1. Run 'cargo sqlx prepare' from the services directory"
6969+echo "2. Run this script again to update all project copies"