mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-12-18 01:54:29 -05:00
Unify the sqlx migrations (#528)
* Skeleton * remove sqlite_dev_setup.sh --------- Co-authored-by: Maksim Kirillov <maksim.kirillov@staticlabs.de> Co-authored-by: Binarybaron <binarybaron@protonmail.com>
This commit is contained in:
parent
517a4fa574
commit
aa471a631e
27 changed files with 19 additions and 86 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -10,6 +10,9 @@ build/
|
||||||
monero-rpc-pool/temp_db.sqlite
|
monero-rpc-pool/temp_db.sqlite
|
||||||
monero-rpc-pool/temp.db
|
monero-rpc-pool/temp.db
|
||||||
|
|
||||||
|
# Shared temporary database for SQLx cache regeneration
|
||||||
|
tempdb.sqlite
|
||||||
|
|
||||||
# auto-generated files by swap-orchestrator
|
# auto-generated files by swap-orchestrator
|
||||||
swap-orchestrator/docker-compose.yml
|
swap-orchestrator/docker-compose.yml
|
||||||
swap-orchestrator/config.toml
|
swap-orchestrator/config.toml
|
||||||
|
|
|
||||||
3
justfile
3
justfile
|
|
@ -87,6 +87,9 @@ bindings:
|
||||||
fmt:
|
fmt:
|
||||||
dprint fmt
|
dprint fmt
|
||||||
|
|
||||||
|
generate-sqlx-cache:
|
||||||
|
./regenerate_sqlx_cache.sh
|
||||||
|
|
||||||
# Run eslint for the GUI frontend
|
# Run eslint for the GUI frontend
|
||||||
check_gui_eslint:
|
check_gui_eslint:
|
||||||
cd src-gui && yarn run eslint
|
cd src-gui && yarn run eslint
|
||||||
|
|
|
||||||
|
|
@ -1,56 +0,0 @@
|
||||||
#!/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."
|
|
||||||
|
|
@ -5,10 +5,10 @@
|
||||||
# Script to regenerate SQLx query cache for monero-rpc-pool
|
# Script to regenerate SQLx query cache for monero-rpc-pool
|
||||||
#
|
#
|
||||||
# This script:
|
# This script:
|
||||||
# 1. Creates a temporary SQLite database in a temp directory
|
# 1. Creates a temporary SQLite database in the workspace root
|
||||||
# 2. Runs all database migrations to set up the schema
|
# 2. Runs all database migrations to set up the schema
|
||||||
# 3. Regenerates the SQLx query cache (.sqlx directory)
|
# 3. Regenerates the SQLx query cache (.sqlx directory)
|
||||||
# 4. Cleans up temporary files automatically
|
# 4. Cleans up temporary database file automatically
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
# ./regenerate_sqlx_cache.sh
|
# ./regenerate_sqlx_cache.sh
|
||||||
|
|
@ -25,19 +25,15 @@ set -e # Exit on any error
|
||||||
|
|
||||||
echo "🔄 Regenerating SQLx query cache..."
|
echo "🔄 Regenerating SQLx query cache..."
|
||||||
|
|
||||||
# Create a temporary directory for the database
|
WORKSPACE_ROOT="$(pwd)"
|
||||||
TEMP_DIR=$(mktemp -d)
|
|
||||||
TEMP_DB="$TEMP_DIR/temp_sqlx_cache.sqlite"
|
# Use shared temporary database in workspace root
|
||||||
|
TEMP_DB="$WORKSPACE_ROOT/tempdb.sqlite"
|
||||||
DATABASE_URL="sqlite:$TEMP_DB"
|
DATABASE_URL="sqlite:$TEMP_DB"
|
||||||
|
|
||||||
echo "📁 Using temporary database: $TEMP_DB"
|
rm -f "$TEMP_DB"
|
||||||
|
|
||||||
# Function to cleanup on exit
|
echo "📁 Using temporary database: $TEMP_DB"
|
||||||
cleanup() {
|
|
||||||
echo "🧹 Cleaning up temporary files..."
|
|
||||||
rm -rf "$TEMP_DIR"
|
|
||||||
}
|
|
||||||
trap cleanup EXIT
|
|
||||||
|
|
||||||
# Export DATABASE_URL for sqlx commands
|
# Export DATABASE_URL for sqlx commands
|
||||||
export DATABASE_URL
|
export DATABASE_URL
|
||||||
|
|
@ -45,11 +41,13 @@ export DATABASE_URL
|
||||||
echo "🗄️ Creating database..."
|
echo "🗄️ Creating database..."
|
||||||
cargo sqlx database create
|
cargo sqlx database create
|
||||||
|
|
||||||
echo "🔄 Running migrations..."
|
for dir in swap monero-sys monero-rpc-pool; do
|
||||||
cargo sqlx migrate run
|
echo "🔄 Running migrations in $dir..."
|
||||||
|
(cd "$WORKSPACE_ROOT/$dir" && cargo sqlx migrate run --ignore-missing)
|
||||||
|
done
|
||||||
|
|
||||||
echo "⚡ Preparing SQLx query cache..."
|
echo "⚡ Preparing SQLx query cache..."
|
||||||
cargo sqlx prepare
|
cargo sqlx prepare --workspace
|
||||||
|
|
||||||
echo "✅ SQLx query cache regenerated successfully!"
|
echo "✅ SQLx query cache regenerated successfully!"
|
||||||
echo "📝 The .sqlx directory has been updated with the latest query metadata."
|
echo "📝 The .sqlx directory has been updated with the latest query metadata."
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# run this script from the swap dir
|
|
||||||
# make sure you have sqlx-cli installed: cargo install --version 0.6.3 sqlx-cli
|
|
||||||
# it's advised for the sqlx-cli to be the same version as specified in cargo.toml
|
|
||||||
|
|
||||||
# this script creates a temporary sqlite database
|
|
||||||
# then runs the migration scripts to create the tables (migrations folder)
|
|
||||||
# then it prepares the offline sqlx-data.json rust mappings
|
|
||||||
DATABASE_URL=sqlite:tempdb cargo sqlx database create
|
|
||||||
DATABASE_URL=sqlite:tempdb cargo sqlx migrate run
|
|
||||||
# needs the absolute path here
|
|
||||||
# https://github.com/launchbadge/sqlx/issues/1399
|
|
||||||
DB_PATH=$(readlink -f tempdb)
|
|
||||||
DATABASE_URL="sqlite:$DB_PATH" cargo sqlx prepare -- --bin swap
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue