Kavita/API/redo-migration.sh
Fesaa b40734265b
Social interactions with annotations (#4068)
Co-authored-by: Joe Milazzo <josephmajora@gmail.com>
2025-10-04 13:11:06 -07:00

28 lines
692 B
Bash
Executable File

#!/bin/bash
migrations=($(ls -1 Data/Migrations/*.cs 2>/dev/null | grep -v "Designer.cs" | grep -v "Snapshot.cs" | sort -r))
if [ ${#migrations[@]} -lt 2 ]; then
echo "Error: Need at least 2 migrations to redo"
exit 1
fi
second_last=$(basename "${migrations[1]}" .cs)
last=$(basename "${migrations[0]}" .cs)
last_name=$(echo "$last" | sed 's/^[0-9]*_//')
echo "Rolling back to: $second_last"
echo "Removing and re-adding: $last_name"
read -p "Continue? (y/N) " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
dotnet ef database update "$second_last" && \
dotnet ef migrations remove && \
dotnet ef migrations add "$last_name"
else
echo "Cancelled"
exit 0
fi