forked from civiccc/buffet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_setup
executable file
·46 lines (37 loc) · 1.7 KB
/
db_setup
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
#!/bin/sh
# If Bundler exports unhelpful settings, they will mess with our expectations,
# particularly when we call bundle exec down below. We sidestep this issue by
# unsetting them.
unset BUNDLE_BIN_PATH
unset BUNDLE_GEMFILE
unset RUBYOPT
unset GEM_PATH
unset GEM_HOME
export RAILS_ENV=test
if [[ $# -eq 0 ]]
then
echo "Running this script manually is discouraged. If you insist, you must pass in each host individually, and run it from the directory of the rails app."
exit 1
fi
mysql -u root -e 'drop database if exists buffet_causes_test'
mysql -u root -e 'create database buffet_causes_test'
mysql -u root -e 'drop database if exists buffet_wishes_test'
mysql -u root -e 'create database buffet_wishes_test'
bundle exec rake db:migrate # wart here is that we don't migrate wishes
mysqldump --no-data -u root buffet_causes_test > buffet_causes_test.dump
mysqldump --no-data -u root wishes_development > buffet_wishes_test.dump
mysql -u root buffet_wishes_test < buffet_wishes_test.dump
for host in `$@` #Loop through argument list
do
echo $host
sh -c "scp buffet_causes_test.dump \
buffet_wishes_test.dump \
buffet@$host:~/ &&
ssh buffet@$host 'mysql -u root -e \"drop database if exists buffet_causes_test\" && \
mysql -u root -e \"create database buffet_causes_test\" && \
mysql -u root -e \"drop database if exists buffet_wishes_test\" && \
mysql -u root -e \"create database buffet_wishes_test\" && \
mysql -u root buffet_causes_test < buffet_causes_test.dump && \
mysql -u root buffet_wishes_test < buffet_wishes_test.dump'" &
done
wait