-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
backport_db_structure.sh
executable file
·66 lines (58 loc) · 1.9 KB
/
backport_db_structure.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# Fail fast in case of errors:
set -e
clear
echo ' '
echo "=== Copying current DB structure files into *all* framework Projects ==="
echo ' '
echo "This will keep in synch all the other Project folders with the current DB structure"
echo "of the Main Application. It should be run from Main root folder."
echo "Make sure migrations can be run flawlessly on localhost before running this."
echo ' '
echo "--> This will also DUMP & COPY the test DB into goggles_db (when found) <--"
echo ' '
echo "(Any other DB dump stored in *any* other project will be ignored by commits"
echo " and should only be used as local backup.)"
echo ' '
echo "Press ENTER when ready, or CTRL-C to abort."
read
echo "Making sure migrations are run in all environments (this will also update the schema file)..."
RAILS_ENV=test rails db:migrate
rails db:migrate
RAILS_ENV=production rails db:migrate
echo "Saving structure in SQL format..."
rails db:structure:dump
# goggles_db
if [ -d ../goggles_db/db ];
then
echo "Updating goggles_db..."
cp ./db/schema.rb ../goggles_db/spec/dummy/db/schema.rb
cp ./db/structure.sql ../goggles_db/spec/dummy/db/structure.sql
echo "DB dump..."
RAILS_ENV=test rails db:dump
echo "Moving dump to goggles_db..."
mv ./db/dump/test.sql.bz2 ../goggles_db/spec/dummy/db/dump/test.sql.bz2
echo "goggles_db updated: changes need a commit."
else
echo "goggles_db not found, skipping."
fi
# goggles_api
if [ -d ../goggles_api/db ];
then
echo "Updating goggles_api..."
cp ./db/schema.rb ../goggles_api/db/schema.rb
cp ./db/structure.sql ../goggles_api/db/structure.sql
else
echo "goggles_api not found, skipping."
fi
# goggles_admin2
if [ -d ../goggles_admin2/db ];
then
echo "Updating goggles_admin2..."
cp ./db/schema.rb ../goggles_admin2/db/schema.rb
cp ./db/structure.sql ../goggles_admin2/db/structure.sql
else
echo "goggles_admin2 not found, skipping."
fi
echo ' '
echo "All done!"