[backend/database] Add script to prune .Designer.cs migration files (ISH-119)

This commit is contained in:
Laura Hausmann 2024-04-14 21:17:45 +02:00
parent 88324bab3f
commit 90591db3c3
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -0,0 +1,27 @@
#!/bin/bash
set -e
if [[ $(uname) == "Darwin" ]]; then
SED="gsed"
else
SED="sed"
fi
import="using Microsoft.EntityFrameworkCore.Infrastructure;"
dbc=" [DbContext(typeof(DatabaseContext))]"
for file in $(find "$(dirname $0)/Migrations" -name '*.Designer.cs'); do
echo "$file"
csfile="${file%.Designer.cs}.cs"
if [[ ! -f $csfile ]]; then
echo "$csfile doesn't exist, exiting"
exit 1
fi
lineno=$($SED -n '/^{/=' "$csfile")
((lineno+=2))
migr=$(grep "\[Migration" "$file")
$SED -i "${lineno}i \\$migr" "$csfile"
$SED -i "${lineno}i \\$dbc" "$csfile"
$SED -i "2i $import" "$csfile"
rm "$file"
done