Update script safemigration
This commit is contained in:
@@ -477,17 +477,13 @@ for attempt in 1 2 3; do
|
|||||||
# If pg_dump fails, fall back to EF Core migration script
|
# If pg_dump fails, fall back to EF Core migration script
|
||||||
warn "⚠️ pg_dump failed, falling back to EF Core migration script..."
|
warn "⚠️ pg_dump failed, falling back to EF Core migration script..."
|
||||||
|
|
||||||
# Get the first migration name to generate complete script
|
# Generate complete backup script (all migrations from beginning)
|
||||||
FIRST_MIGRATION=$(get_first_migration)
|
log "📋 Generating complete backup script (all migrations)..."
|
||||||
|
if (cd "$DB_PROJECT_PATH" && ASPNETCORE_ENVIRONMENT="$ENVIRONMENT" dotnet ef migrations script --idempotent --no-build --startup-project "$API_PROJECT_PATH" --output "$BACKUP_FILE"); then
|
||||||
if [ -n "$FIRST_MIGRATION" ]; then
|
|
||||||
log "📋 Generating complete backup script from initial migration: $FIRST_MIGRATION"
|
|
||||||
if (cd "$DB_PROJECT_PATH" && ASPNETCORE_ENVIRONMENT="$ENVIRONMENT" dotnet ef migrations script --from "$FIRST_MIGRATION" --idempotent --no-build --startup-project "$API_PROJECT_PATH" --output "$BACKUP_FILE"); then
|
|
||||||
log "✅ Complete EF Core Migration SQL Script generated: $BACKUP_FILE_DISPLAY"
|
log "✅ Complete EF Core Migration SQL Script generated: $BACKUP_FILE_DISPLAY"
|
||||||
BACKUP_SUCCESS=true
|
BACKUP_SUCCESS=true
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
# Try fallback without specifying from migration
|
|
||||||
ERROR_OUTPUT=$( (cd "$DB_PROJECT_PATH" && ASPNETCORE_ENVIRONMENT="$ENVIRONMENT" dotnet ef migrations script --idempotent --no-build --startup-project "$API_PROJECT_PATH" --output "$BACKUP_FILE") 2>&1 || true)
|
ERROR_OUTPUT=$( (cd "$DB_PROJECT_PATH" && ASPNETCORE_ENVIRONMENT="$ENVIRONMENT" dotnet ef migrations script --idempotent --no-build --startup-project "$API_PROJECT_PATH" --output "$BACKUP_FILE") 2>&1 || true)
|
||||||
if [ $attempt -lt 3 ]; then
|
if [ $attempt -lt 3 ]; then
|
||||||
warn "⚠️ Backup attempt $attempt failed. Retrying in 5 seconds..."
|
warn "⚠️ Backup attempt $attempt failed. Retrying in 5 seconds..."
|
||||||
@@ -499,42 +495,18 @@ for attempt in 1 2 3; do
|
|||||||
error " Migration aborted for safety reasons."
|
error " Migration aborted for safety reasons."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
# Fallback: generate script without specifying from migration
|
|
||||||
if (cd "$DB_PROJECT_PATH" && ASPNETCORE_ENVIRONMENT="$ENVIRONMENT" dotnet ef migrations script --idempotent --no-build --startup-project "$API_PROJECT_PATH" --output "$BACKUP_FILE"); then
|
|
||||||
log "✅ EF Core Migration SQL Script generated: $BACKUP_FILE_DISPLAY"
|
|
||||||
BACKUP_SUCCESS=true
|
|
||||||
break
|
|
||||||
else
|
|
||||||
# Try fallback without specifying from migration
|
|
||||||
ERROR_OUTPUT=$( (cd "$DB_PROJECT_PATH" && ASPNETCORE_ENVIRONMENT="$ENVIRONMENT" dotnet ef migrations script --idempotent --no-build --startup-project "$API_PROJECT_PATH" --output "$BACKUP_FILE") 2>&1 || true)
|
|
||||||
if [ $attempt -lt 3 ]; then
|
|
||||||
warn "⚠️ Backup attempt $attempt failed. Retrying in 5 seconds..."
|
|
||||||
warn " EF CLI Output: $ERROR_OUTPUT"
|
|
||||||
sleep 5
|
|
||||||
else
|
|
||||||
error "❌ Database backup failed after 3 attempts."
|
|
||||||
error " EF CLI Output: $ERROR_OUTPUT"
|
|
||||||
error " Migration aborted for safety reasons."
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# If pg_dump is not available, use EF Core migration script
|
# If pg_dump is not available, use EF Core migration script
|
||||||
warn "⚠️ pg_dump not available, using EF Core migration script for backup..."
|
warn "⚠️ pg_dump not available, using EF Core migration script for backup..."
|
||||||
|
|
||||||
# Get the first migration name to generate complete script
|
# Generate complete backup script (all migrations from beginning)
|
||||||
FIRST_MIGRATION=$(get_first_migration)
|
log "📋 Generating complete backup script (all migrations)..."
|
||||||
|
if (cd "$DB_PROJECT_PATH" && ASPNETCORE_ENVIRONMENT="$ENVIRONMENT" dotnet ef migrations script --idempotent --no-build --startup-project "$API_PROJECT_PATH" --output "$BACKUP_FILE"); then
|
||||||
if [ -n "$FIRST_MIGRATION" ]; then
|
|
||||||
log "📋 Generating complete backup script from initial migration: $FIRST_MIGRATION"
|
|
||||||
if (cd "$DB_PROJECT_PATH" && ASPNETCORE_ENVIRONMENT="$ENVIRONMENT" dotnet ef migrations script --from "$FIRST_MIGRATION" --idempotent --no-build --startup-project "$API_PROJECT_PATH" --output "$BACKUP_FILE"); then
|
|
||||||
log "✅ Complete EF Core Migration SQL Script generated: $BACKUP_FILE_DISPLAY"
|
log "✅ Complete EF Core Migration SQL Script generated: $BACKUP_FILE_DISPLAY"
|
||||||
BACKUP_SUCCESS=true
|
BACKUP_SUCCESS=true
|
||||||
break
|
break
|
||||||
else
|
else
|
||||||
# Try fallback without specifying from migration
|
|
||||||
ERROR_OUTPUT=$( (cd "$DB_PROJECT_PATH" && ASPNETCORE_ENVIRONMENT="$ENVIRONMENT" dotnet ef migrations script --idempotent --no-build --startup-project "$API_PROJECT_PATH" --output "$BACKUP_FILE") 2>&1 || true)
|
ERROR_OUTPUT=$( (cd "$DB_PROJECT_PATH" && ASPNETCORE_ENVIRONMENT="$ENVIRONMENT" dotnet ef migrations script --idempotent --no-build --startup-project "$API_PROJECT_PATH" --output "$BACKUP_FILE") 2>&1 || true)
|
||||||
if [ $attempt -lt 3 ]; then
|
if [ $attempt -lt 3 ]; then
|
||||||
warn "⚠️ Backup attempt $attempt failed. Retrying in 5 seconds..."
|
warn "⚠️ Backup attempt $attempt failed. Retrying in 5 seconds..."
|
||||||
@@ -546,26 +518,6 @@ for attempt in 1 2 3; do
|
|||||||
error " Migration aborted for safety reasons."
|
error " Migration aborted for safety reasons."
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
# Fallback: generate script without specifying from migration
|
|
||||||
if (cd "$DB_PROJECT_PATH" && ASPNETCORE_ENVIRONMENT="$ENVIRONMENT" dotnet ef migrations script --idempotent --no-build --startup-project "$API_PROJECT_PATH" --output "$BACKUP_FILE"); then
|
|
||||||
log "✅ EF Core Migration SQL Script generated: $BACKUP_FILE_DISPLAY"
|
|
||||||
BACKUP_SUCCESS=true
|
|
||||||
break
|
|
||||||
else
|
|
||||||
# Try fallback without specifying from migration
|
|
||||||
ERROR_OUTPUT=$( (cd "$DB_PROJECT_PATH" && ASPNETCORE_ENVIRONMENT="$ENVIRONMENT" dotnet ef migrations script --idempotent --no-build --startup-project "$API_PROJECT_PATH" --output "$BACKUP_FILE") 2>&1 || true)
|
|
||||||
if [ $attempt -lt 3 ]; then
|
|
||||||
warn "⚠️ Backup attempt $attempt failed. Retrying in 5 seconds..."
|
|
||||||
warn " EF CLI Output: $ERROR_OUTPUT"
|
|
||||||
sleep 5
|
|
||||||
else
|
|
||||||
error "❌ Database backup failed after 3 attempts."
|
|
||||||
error " EF CLI Output: $ERROR_OUTPUT"
|
|
||||||
error " Migration aborted for safety reasons."
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -672,15 +624,8 @@ fi
|
|||||||
|
|
||||||
# Generate migration script based on database state
|
# Generate migration script based on database state
|
||||||
if [ "$DB_HAS_TABLES" = "true" ]; then
|
if [ "$DB_HAS_TABLES" = "true" ]; then
|
||||||
# For databases with existing tables, we need to generate a complete script
|
# For databases with existing tables, generate a complete idempotent script
|
||||||
# that includes all migrations from the beginning
|
log "📝 Generating complete migration script (idempotent) for database with existing tables..."
|
||||||
log "📝 Generating complete migration script from initial migration..."
|
|
||||||
|
|
||||||
# Get the first migration name to generate script from the beginning
|
|
||||||
FIRST_MIGRATION=$(get_first_migration)
|
|
||||||
|
|
||||||
if [ -n "$FIRST_MIGRATION" ]; then
|
|
||||||
log "📋 Generating complete script for all migrations (idempotent)..."
|
|
||||||
if (cd "$DB_PROJECT_PATH" && ASPNETCORE_ENVIRONMENT="$ENVIRONMENT" dotnet ef migrations script --idempotent --no-build --startup-project "$API_PROJECT_PATH" --output "$MIGRATION_SCRIPT"); then
|
if (cd "$DB_PROJECT_PATH" && ASPNETCORE_ENVIRONMENT="$ENVIRONMENT" dotnet ef migrations script --idempotent --no-build --startup-project "$API_PROJECT_PATH" --output "$MIGRATION_SCRIPT"); then
|
||||||
log "✅ Complete migration script generated (all migrations, idempotent): $(basename "$MIGRATION_SCRIPT")"
|
log "✅ Complete migration script generated (all migrations, idempotent): $(basename "$MIGRATION_SCRIPT")"
|
||||||
else
|
else
|
||||||
@@ -692,30 +637,9 @@ if [ "$DB_HAS_TABLES" = "true" ]; then
|
|||||||
error " Backup script available at: $BACKUP_FILE_DISPLAY"
|
error " Backup script available at: $BACKUP_FILE_DISPLAY"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
# Fallback: generate script without specifying from migration
|
|
||||||
log "📝 Fallback: Generating migration script without specifying from migration..."
|
|
||||||
if (cd "$DB_PROJECT_PATH" && ASPNETCORE_ENVIRONMENT="$ENVIRONMENT" dotnet ef migrations script --idempotent --no-build --startup-project "$API_PROJECT_PATH" --output "$MIGRATION_SCRIPT"); then
|
|
||||||
log "✅ Migration script generated (idempotent): $(basename "$MIGRATION_SCRIPT")"
|
|
||||||
else
|
|
||||||
ERROR_OUTPUT=$( (cd "$DB_PROJECT_PATH" && ASPNETCORE_ENVIRONMENT="$ENVIRONMENT" dotnet ef migrations script --idempotent --no-build --startup-project "$API_PROJECT_PATH" --output "$MIGRATION_SCRIPT") 2>&1 || true )
|
|
||||||
error "❌ Failed to generate idempotent migration script."
|
|
||||||
error " EF CLI Output: $ERROR_OUTPUT"
|
|
||||||
error " Check the .NET project logs for detailed errors."
|
|
||||||
if [ "$CREATE_BACKUP" = "true" ] && [ -n "$BACKUP_FILE_DISPLAY" ]; then
|
|
||||||
error " Backup script available at: $BACKUP_FILE_DISPLAY"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
# Use full script generation for empty databases (generate script from the very beginning)
|
# Use full script generation for empty databases (generate script from the very beginning)
|
||||||
log "📝 Generating full migration script for empty database..."
|
log "📝 Generating full migration script for empty database..."
|
||||||
|
|
||||||
# Get the first migration name to generate script from the beginning
|
|
||||||
FIRST_MIGRATION=$(get_first_migration)
|
|
||||||
|
|
||||||
if [ -n "$FIRST_MIGRATION" ]; then
|
|
||||||
log "📋 Generating complete script for all migrations..."
|
|
||||||
if (cd "$DB_PROJECT_PATH" && ASPNETCORE_ENVIRONMENT="$ENVIRONMENT" dotnet ef migrations script --no-build --startup-project "$API_PROJECT_PATH" --output "$MIGRATION_SCRIPT"); then
|
if (cd "$DB_PROJECT_PATH" && ASPNETCORE_ENVIRONMENT="$ENVIRONMENT" dotnet ef migrations script --no-build --startup-project "$API_PROJECT_PATH" --output "$MIGRATION_SCRIPT"); then
|
||||||
log "✅ Complete migration script generated (all migrations): $(basename "$MIGRATION_SCRIPT")"
|
log "✅ Complete migration script generated (all migrations): $(basename "$MIGRATION_SCRIPT")"
|
||||||
else
|
else
|
||||||
@@ -727,21 +651,6 @@ else
|
|||||||
error " Backup script available at: $BACKUP_FILE_DISPLAY"
|
error " Backup script available at: $BACKUP_FILE_DISPLAY"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
# Fallback: generate script without specifying from migration
|
|
||||||
log "📝 Fallback: Generating migration script without specifying from migration..."
|
|
||||||
if (cd "$DB_PROJECT_PATH" && ASPNETCORE_ENVIRONMENT="$ENVIRONMENT" dotnet ef migrations script --no-build --startup-project "$API_PROJECT_PATH" --output "$MIGRATION_SCRIPT"); then
|
|
||||||
log "✅ Migration script generated (fallback): $(basename "$MIGRATION_SCRIPT")"
|
|
||||||
else
|
|
||||||
ERROR_OUTPUT=$( (cd "$DB_PROJECT_PATH" && ASPNETCORE_ENVIRONMENT="$ENVIRONMENT" dotnet ef migrations script --no-build --startup-project "$API_PROJECT_PATH" --output "$MIGRATION_SCRIPT") 2>&1 || true )
|
|
||||||
error "❌ Failed to generate fallback migration script."
|
|
||||||
error " EF CLI Output: $ERROR_OUTPUT"
|
|
||||||
error " Check the .NET project logs for detailed errors."
|
|
||||||
if [ "$CREATE_BACKUP" = "true" ] && [ -n "$BACKUP_FILE_DISPLAY" ]; then
|
|
||||||
error " Backup script available at: $BACKUP_FILE_DISPLAY"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Show the migration script path to the user for review
|
# Show the migration script path to the user for review
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"PostgreSql": {
|
"PostgreSql": {
|
||||||
"ConnectionString": "Host=kaigen-db.kaigen.managing.live;Port=5433;Database=managing;Username=postgres;Password=2ab5423dcca4aa2d",
|
"ConnectionString": "Host=kaigen-db.kaigen.managing.live;Port=5432;Database=managing;Username=postgres;Password=2ab5423dcca4aa2d",
|
||||||
"Orleans": "Host=kaigen-db.kaigen.managing.live;Port=5433;Database=orleans;Username=postgres;Password=2ab5423dcca4aa2d"
|
"Orleans": "Host=kaigen-db.kaigen.managing.live;Port=5432;Database=orleans;Username=postgres;Password=2ab5423dcca4aa2d"
|
||||||
},
|
},
|
||||||
"InfluxDb": {
|
"InfluxDb": {
|
||||||
"Url": "https://influx-db.kaigen.managing.live",
|
"Url": "https://influx-db.kaigen.managing.live",
|
||||||
|
|||||||
Reference in New Issue
Block a user