vibe-and-thrive 1.6.4 → 1.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/ralph/utils.sh +122 -33
package/package.json
CHANGED
package/ralph/utils.sh
CHANGED
|
@@ -404,55 +404,144 @@ validate_prd() {
|
|
|
404
404
|
return 0
|
|
405
405
|
}
|
|
406
406
|
|
|
407
|
-
#
|
|
408
|
-
|
|
409
|
-
local
|
|
410
|
-
local config="$RALPH_DIR/config.json"
|
|
407
|
+
# Auto-detect migration tool and return the command
|
|
408
|
+
detect_migration_tool() {
|
|
409
|
+
local search_dir="${1:-.}"
|
|
411
410
|
|
|
412
|
-
|
|
411
|
+
# Alembic (Python/FastAPI/SQLAlchemy)
|
|
412
|
+
if [[ -f "$search_dir/alembic.ini" ]] || [[ -d "$search_dir/alembic" ]]; then
|
|
413
|
+
echo "cd $search_dir && alembic upgrade head"
|
|
414
|
+
return 0
|
|
415
|
+
fi
|
|
413
416
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
+
# Prisma (Node.js)
|
|
418
|
+
if [[ -d "$search_dir/prisma/migrations" ]] || [[ -f "$search_dir/prisma/schema.prisma" ]]; then
|
|
419
|
+
echo "cd $search_dir && npx prisma migrate deploy"
|
|
420
|
+
return 0
|
|
421
|
+
fi
|
|
422
|
+
|
|
423
|
+
# Django
|
|
424
|
+
if [[ -f "$search_dir/manage.py" ]] && [[ -d "$search_dir" ]] && find "$search_dir" -type d -name "migrations" -print -quit | grep -q .; then
|
|
425
|
+
echo "cd $search_dir && python manage.py migrate"
|
|
426
|
+
return 0
|
|
427
|
+
fi
|
|
417
428
|
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
print_warning "migrations.pattern not configured, skipping migration check"
|
|
429
|
+
# Sequelize (Node.js)
|
|
430
|
+
if [[ -f "$search_dir/.sequelizerc" ]]; then
|
|
431
|
+
echo "cd $search_dir && npx sequelize-cli db:migrate"
|
|
422
432
|
return 0
|
|
423
433
|
fi
|
|
424
434
|
|
|
425
|
-
#
|
|
426
|
-
|
|
435
|
+
# TypeORM (Node.js)
|
|
436
|
+
if [[ -f "$search_dir/ormconfig.json" ]] || grep -q '"typeorm"' "$search_dir/package.json" 2>/dev/null; then
|
|
437
|
+
echo "cd $search_dir && npx typeorm migration:run"
|
|
438
|
+
return 0
|
|
439
|
+
fi
|
|
427
440
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
441
|
+
# Knex (Node.js)
|
|
442
|
+
if [[ -f "$search_dir/knexfile.js" ]] || [[ -f "$search_dir/knexfile.ts" ]]; then
|
|
443
|
+
echo "cd $search_dir && npx knex migrate:latest"
|
|
444
|
+
return 0
|
|
431
445
|
fi
|
|
432
446
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
447
|
+
return 1
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
# Find all migration tools in project (searches common app directories)
|
|
451
|
+
find_all_migration_tools() {
|
|
452
|
+
local tools=()
|
|
437
453
|
|
|
438
|
-
|
|
439
|
-
|
|
454
|
+
# Check root
|
|
455
|
+
local root_tool
|
|
456
|
+
if root_tool=$(detect_migration_tool "."); then
|
|
457
|
+
tools+=("$root_tool")
|
|
440
458
|
fi
|
|
441
459
|
|
|
442
|
-
#
|
|
443
|
-
|
|
460
|
+
# Check common app directories
|
|
461
|
+
for dir in apps/* packages/* services/* api backend server; do
|
|
462
|
+
if [[ -d "$dir" ]]; then
|
|
463
|
+
local tool
|
|
464
|
+
if tool=$(detect_migration_tool "$dir"); then
|
|
465
|
+
tools+=("$tool")
|
|
466
|
+
fi
|
|
467
|
+
fi
|
|
468
|
+
done
|
|
444
469
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
470
|
+
# Return unique tools
|
|
471
|
+
printf '%s\n' "${tools[@]}" | sort -u
|
|
472
|
+
}
|
|
448
473
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
474
|
+
# Ensure database migrations are applied before verification
|
|
475
|
+
# Migration commands are idempotent - they no-op if nothing pending
|
|
476
|
+
run_migrations_if_needed() {
|
|
477
|
+
local pre_sha="$1" # unused now, kept for API compatibility
|
|
478
|
+
local config="$RALPH_DIR/config.json"
|
|
479
|
+
|
|
480
|
+
local migrate_cmd=""
|
|
481
|
+
|
|
482
|
+
# Try config first
|
|
483
|
+
if [[ -f "$config" ]]; then
|
|
484
|
+
migrate_cmd=$(jq -r '.migrations.command // empty' "$config" 2>/dev/null)
|
|
485
|
+
fi
|
|
486
|
+
|
|
487
|
+
# Auto-detect if not configured
|
|
488
|
+
if [[ -z "$migrate_cmd" ]]; then
|
|
489
|
+
local detected_tools
|
|
490
|
+
detected_tools=$(find_all_migration_tools)
|
|
491
|
+
|
|
492
|
+
if [[ -z "$detected_tools" ]]; then
|
|
493
|
+
return 0 # No migrations to run
|
|
452
494
|
fi
|
|
453
495
|
|
|
454
|
-
|
|
496
|
+
# Run all detected migration tools
|
|
497
|
+
local failed=0
|
|
498
|
+
while IFS= read -r tool_cmd; do
|
|
499
|
+
[[ -z "$tool_cmd" ]] && continue
|
|
500
|
+
echo -n " Migrations (auto-detected)... "
|
|
501
|
+
|
|
502
|
+
local log_file
|
|
503
|
+
log_file=$(mktemp)
|
|
504
|
+
|
|
505
|
+
if safe_exec "$tool_cmd" "$log_file"; then
|
|
506
|
+
if grep -qiE "applying|migrating|running|upgrade" "$log_file" 2>/dev/null; then
|
|
507
|
+
print_success "applied"
|
|
508
|
+
else
|
|
509
|
+
echo "up to date"
|
|
510
|
+
fi
|
|
511
|
+
else
|
|
512
|
+
print_error "failed"
|
|
513
|
+
echo " Command: $tool_cmd"
|
|
514
|
+
tail -10 "$log_file" | sed 's/^/ /'
|
|
515
|
+
failed=1
|
|
516
|
+
fi
|
|
517
|
+
rm -f "$log_file"
|
|
518
|
+
done <<< "$detected_tools"
|
|
519
|
+
|
|
520
|
+
return $failed
|
|
455
521
|
fi
|
|
456
522
|
|
|
457
|
-
|
|
523
|
+
# Always run migrations - commands are idempotent (no-op if nothing pending)
|
|
524
|
+
# This ensures DB schema is always in sync before tests run
|
|
525
|
+
echo -n " Ensuring migrations applied... "
|
|
526
|
+
|
|
527
|
+
local log_file
|
|
528
|
+
log_file=$(mktemp)
|
|
529
|
+
|
|
530
|
+
if safe_exec "$migrate_cmd" "$log_file"; then
|
|
531
|
+
# Check if any migrations were actually applied
|
|
532
|
+
if grep -qiE "applying|migrating|running|upgrade" "$log_file" 2>/dev/null; then
|
|
533
|
+
print_success "applied"
|
|
534
|
+
else
|
|
535
|
+
echo "up to date"
|
|
536
|
+
fi
|
|
537
|
+
rm -f "$log_file"
|
|
538
|
+
return 0
|
|
539
|
+
else
|
|
540
|
+
print_error "failed"
|
|
541
|
+
echo ""
|
|
542
|
+
echo " Migration error:"
|
|
543
|
+
tail -20 "$log_file" | sed 's/^/ /'
|
|
544
|
+
rm -f "$log_file"
|
|
545
|
+
return 1
|
|
546
|
+
fi
|
|
458
547
|
}
|