Enhance migration script to support environment-specific appsettings for Managing.Workers; improve connection string extraction logic with fallback to Managing.Api for SandboxRemote and ProductionRemote environments. Update createSwapOrderTxn to correct variable naming for clarity and add dynamic execution fee calculation in swapGmxTokensImpl.
This commit is contained in:
@@ -62,6 +62,7 @@ PROJECT_ROOT_DIR="$(dirname "$SCRIPT_DIR")" # One level up from scripts/
|
||||
SRC_DIR="$PROJECT_ROOT_DIR/src"
|
||||
DB_PROJECT_PATH="$SRC_DIR/Managing.Infrastructure.Database"
|
||||
API_PROJECT_PATH="$SRC_DIR/Managing.Api"
|
||||
WORKERS_PROJECT_PATH="$SRC_DIR/Managing.Workers"
|
||||
DOCKER_DIR="$SRC_DIR/Managing.Docker" # Adjust if your docker-compose files are elsewhere
|
||||
|
||||
# Define absolute path for backup directory with environment subfolder
|
||||
@@ -108,27 +109,61 @@ start_postgres_if_needed() {
|
||||
|
||||
# Helper function to extract connection details from appsettings
|
||||
extract_connection_details() {
|
||||
local appsettings_file="$API_PROJECT_PATH/appsettings.$ENVIRONMENT.json"
|
||||
local default_appsettings="$API_PROJECT_PATH/appsettings.json"
|
||||
local appsettings_file=""
|
||||
local default_appsettings=""
|
||||
|
||||
# For SandboxRemote and ProductionRemote, check Managing.Workers first
|
||||
if [ "$ENVIRONMENT" = "SandboxRemote" ] || [ "$ENVIRONMENT" = "ProductionRemote" ]; then
|
||||
appsettings_file="$WORKERS_PROJECT_PATH/appsettings.$ENVIRONMENT.json"
|
||||
default_appsettings="$WORKERS_PROJECT_PATH/appsettings.json"
|
||||
log "📋 Checking Managing.Workers for environment: $ENVIRONMENT"
|
||||
else
|
||||
appsettings_file="$API_PROJECT_PATH/appsettings.$ENVIRONMENT.json"
|
||||
default_appsettings="$API_PROJECT_PATH/appsettings.json"
|
||||
fi
|
||||
|
||||
# Try environment-specific file first, then default
|
||||
if [ -f "$appsettings_file" ]; then
|
||||
log "📋 Reading connection string from: appsettings.$ENVIRONMENT.json"
|
||||
log "📋 Reading connection string from: $(basename "$appsettings_file")"
|
||||
# Look for PostgreSql.ConnectionString first, then fallback to ConnectionString
|
||||
CONNECTION_STRING=$(grep -A 3 '"PostgreSql"' "$appsettings_file" | grep -o '"ConnectionString": *"[^"]*"' | cut -d'"' -f4)
|
||||
if [ -z "$CONNECTION_STRING" ]; then
|
||||
CONNECTION_STRING=$(grep -o '"ConnectionString": *"[^"]*"' "$appsettings_file" | cut -d'"' -f4)
|
||||
fi
|
||||
elif [ -f "$default_appsettings" ]; then
|
||||
log "📋 Reading connection string from: appsettings.json (default)"
|
||||
log "📋 Reading connection string from: $(basename "$default_appsettings") (default)"
|
||||
# Look for PostgreSql.ConnectionString first, then fallback to ConnectionString
|
||||
CONNECTION_STRING=$(grep -A 3 '"PostgreSql"' "$default_appsettings" | grep -o '"ConnectionString": *"[^"]*"' | cut -d'"' -f4)
|
||||
if [ -z "$CONNECTION_STRING" ]; then
|
||||
CONNECTION_STRING=$(grep -o '"ConnectionString": *"[^"]*"' "$default_appsettings" | cut -d'"' -f4)
|
||||
fi
|
||||
else
|
||||
warn "⚠️ Could not find appsettings file for environment $ENVIRONMENT"
|
||||
return 1
|
||||
# If Workers file not found for SandboxRemote/ProductionRemote, fallback to API
|
||||
if [ "$ENVIRONMENT" = "SandboxRemote" ] || [ "$ENVIRONMENT" = "ProductionRemote" ]; then
|
||||
warn "⚠️ Could not find appsettings file in Managing.Workers, trying Managing.Api..."
|
||||
appsettings_file="$API_PROJECT_PATH/appsettings.$ENVIRONMENT.json"
|
||||
default_appsettings="$API_PROJECT_PATH/appsettings.json"
|
||||
|
||||
if [ -f "$appsettings_file" ]; then
|
||||
log "📋 Reading connection string from: $(basename "$appsettings_file") (fallback to API)"
|
||||
CONNECTION_STRING=$(grep -A 3 '"PostgreSql"' "$appsettings_file" | grep -o '"ConnectionString": *"[^"]*"' | cut -d'"' -f4)
|
||||
if [ -z "$CONNECTION_STRING" ]; then
|
||||
CONNECTION_STRING=$(grep -o '"ConnectionString": *"[^"]*"' "$appsettings_file" | cut -d'"' -f4)
|
||||
fi
|
||||
elif [ -f "$default_appsettings" ]; then
|
||||
log "📋 Reading connection string from: $(basename "$default_appsettings") (default, fallback to API)"
|
||||
CONNECTION_STRING=$(grep -A 3 '"PostgreSql"' "$default_appsettings" | grep -o '"ConnectionString": *"[^"]*"' | cut -d'"' -f4)
|
||||
if [ -z "$CONNECTION_STRING" ]; then
|
||||
CONNECTION_STRING=$(grep -o '"ConnectionString": *"[^"]*"' "$default_appsettings" | cut -d'"' -f4)
|
||||
fi
|
||||
else
|
||||
warn "⚠️ Could not find appsettings file for environment $ENVIRONMENT"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
warn "⚠️ Could not find appsettings file for environment $ENVIRONMENT"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -z "$CONNECTION_STRING" ]; then
|
||||
|
||||
Reference in New Issue
Block a user