#!/bin/bash

set -e

BASE_DIR="/home/realrate/storage/data"
QA_DIR="$BASE_DIR/qa"

mkdir -p "$QA_DIR"

cd "$BASE_DIR"

for dir in at_* de_* us_*; do
    # Check if it's a directory and not already a symlink
    if [ -d "$dir" ] && [ ! -L "$dir" ]; then
        new_dir="${QA_DIR}/${dir}_migrated"
        
        echo "Moving $dir to $new_dir"
        mv "$dir" "$new_dir"

        echo "Creating symlink: $dir -> qa/${dir}_migrated"
        ln -s "qa/${dir}_migrated" "$dir"
    fi
done

echo "✅ Migration and symbolic linking completed."
