# for installs post 0.18.1 this file will be harmlessly created
if [[ ! -f "${APP_DATA_DIR}/AT_LEAST_0-18-1" ]]; then
# delete index db for all bitcoin networks
for file in "${ORDINALS_DATA_DIR}/index.redb" "${ORDINALS_DATA_DIR}/testnet3/index.redb" "${ORDINALS_DATA_DIR}/regtest/index.redb" "${ORDINALS_DATA_DIR}/signet/index.redb"; do
# migrate all wallet database files to ord/wallets, ord/testnet3/wallets, ord/regtest/wallets, and ord/signet/wallets for pre-0.18.2 versions: https://github.com/ordinals/ord/releases/tag/0.18.2
# the default unnamed wallet from `ord wallet create` is called ord.redb, but users can create named wallets as <anything>.redb
# we assume that all .redb files except index.redb are wallet database files
# for installs post 0.18.2, the AT_LEAST_0-18-2 file will be harmlessly created
# We only create the wallets directory if there are files to move. This mimics the behavior of ord 0.18.2, which only creates the wallets directory when a wallet database is created.
if [[ ${#files_to_move[@]} -gt 0 ]]; then
mkdir -p "${dir_path}/wallets"
echo "Creating wallets directory in ${dir_path}/wallets"
for file in "${files_to_move[@]}"; do
echo "Moving ${file} to ${dir_path}/wallets/"
mv "${file}" "${dir_path}/wallets/"
done
else
echo "No wallet files to move in ${dir_path}."
fi
else
echo "${dir_path} does not exist, skipping."
fi
done
touch "${APP_DATA_DIR}/AT_LEAST_0-18-2"
echo "Wallet database migration complete, flag file created."
else
echo "Migration flag file already exists, skipping wallet database migration."