forked from ennerperez/ddd-mvc-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmigrate.sh
51 lines (46 loc) · 1.69 KB
/
migrate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
context="Default"
name=
clear=false
update=false
rollback=false
output=
for i in "$@"; do
case $1 in
-c|--context) context="$2"; shift ;;
-n|--name) name="$2"; shift ;;
-c|--clear) clear=true ;;
-u|--update) update=true ;;
-r|--rollback) rollback=true ;;
-o|--output) output="$2"; break ;;
esac
shift
done
context_name="${context}Context"
if [[ "$clear" == true ]]; then
dotnet ef database drop -f --context ${context_name} --project src/Persistence --startup-project src/Web
if [[ -d "src/Persistence/Migrations/${context}" ]]; then
rm -r -f "src/Persistence/Migrations/${context}"
fi
else
if [[ "$rollback" == true ]]; then
dotnet ef migrations remove --force --context ${context_name} --project src/Persistence --startup-project src/Web
fi
fi
if [[ "$output" != "" ]]; then
now=$(date '+%Y%m%d')
script_name="${now}_${context}Context_${output}"
dotnet ef migrations script -i --context ${context_name} -o src/Persistence/Migrations/${context}/Scripts/$script_name.sql --project src/Persistence --startup-project src/Web
echo "Done: ${script_name}"
else
if [[ "$name" != "" ]]; then
dotnet ef migrations add ${name} -o "Migrations/${context}" --context ${context_name} --project src/Persistence --startup-project src/Web
if [[ "$update" == true ]]; then
dotnet ef database update ${name} --context ${context_name} --project src/Persistence --startup-project src/Web
fi
else
if [[ "$update" == true ]]; then
dotnet ef database update --context ${context_name} --project src/Persistence --startup-project src/Web
fi
fi
fi