-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapply-migration.sh
More file actions
executable file
·76 lines (61 loc) · 1.99 KB
/
Copy pathapply-migration.sh
File metadata and controls
executable file
·76 lines (61 loc) · 1.99 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
function _dbg_print() {
if [[ "${DEBUG}" -eq 1 ]]; then
echo "[DEBUG] $@"
fi
}
if [[ -f ".env" ]]; then
source .env
_dbg_print "Loaded environment file '.env'"
else
_dbg_print "No environment file found"
fi
function _build_connection_string() {
if [[ -z "${DATABASE_CONNECTION_STRING}" ]]; then
_dbg_print "DATABASE_CONNECTION_STRING not found, building from individual environment variables"
_hn="${DATABASE_HOST}"
if [[ -z "${_hn}" ]]; then
_hn="db"
fi
if [[ -n "${DATABASE_PORT}" ]]; then
_hn="${_hn}:${DATABASE_PORT}"
fi
_working=""
if [[ -n "${_hn}" ]]; then
_working="Host=${_hn}"
fi
if [[ -n "${DATABASE_NAME}" ]]; then
_working="${_working};Database=${DATABASE_NAME}"
else
_working="${_working};Database=kasta"
fi
if [[ -n "${DATABASE_USER}" ]]; then
_working="${_working};Username=${DATABASE_USER}"
else
_working="${_working};Username=postgres"
fi
if [[ -n "${DATABASE_PASSWORD}" ]]; then
_working="${_working};Password=${DATABASE_PASSWORD}"
fi
if [[ -n "${DATABASE_APPEND}" ]]; then
_working="${_working};${DATABASE_APPEND}"
fi
echo $_working
else
echo $DATABASE_CONNECTION_STRING
fi
return 0
}
_connection_string=$(_build_connection_string)
if [[ -z "${_connection_string}" ]]; then
echo "Missing required environment variable (see README.md, section 'Migration Script')"
exit 1
fi
if [[ -z "${1}" ]]; then
echo "Missing migration name"
echo "Usage: ./apply-migration.sh [name]"
exit 1
fi
_dbg_print "Connection String: $_connection_string"
_dbg_print " Migration Name: $1"
CUSTOM_ENV_LOCATION="../.env" dotnet ef database update $1 --project "Kasta.Data" --context "Kasta.Data.ApplicationDbContext" --connection "$DATABASE_CONNECTION_STRING"