-
Notifications
You must be signed in to change notification settings - Fork 0
/
reseed.sh
executable file
·46 lines (35 loc) · 986 Bytes
/
reseed.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
#! /usr/bin/env bash
readonly DB_CONFIG_FILE=../config/database.json
run_sequelize()
{
node ../node_modules/.bin/sequelize --config="${DB_CONFIG_FILE}" "$@"
}
write_config_line()
{
if [[ -z "$2" ]]
then
echo "\"$1\": null"
return
fi
echo "\"$1\": \"$2\""
}
main()
{
pushd src
# make sure the config file exists
if [[ ! -f "${DB_CONFIG_FILE}" ]]
then
echo "Writing database config file from environment"
echo "{" > "${DB_CONFIG_FILE}"
echo " $(write_config_line "username" "${DB_USERNAME}")," >> "${DB_CONFIG_FILE}"
echo " $(write_config_line "password" "${DB_PASSWORD}")," >> "${DB_CONFIG_FILE}"
echo " $(write_config_line "database" "${DB_DATABASE}")," >> "${DB_CONFIG_FILE}"
echo " $(write_config_line "host" "${DB_HOST}")," >> "${DB_CONFIG_FILE}"
echo " $(write_config_line "dialect" "${DB_DIALECT}")" >> "${DB_CONFIG_FILE}"
echo "}" >> "${DB_CONFIG_FILE}"
fi
run_sequelize db:seed:undo:all
run_sequelize db:seed:all
popd
}
main "$@"