-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdatabase.sh
executable file
·71 lines (64 loc) · 2.1 KB
/
database.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
67
68
69
70
71
#!/bin/bash
# Function to start the servers
start_servers() {
echo "Starting first database server"
# Change directory to the location of your database/restaurant_sys
cd ./database/restaurant_sys
python manage.py runserver 9000 --noreload --settings=restaurant_sys.settings.v1 &
echo "Starting second database server"
python manage.py runserver 9001 --noreload --settings=restaurant_sys.settings.v2 &
}
flush_database() {
echo "Flushing database"
# Change directory to the location of your database/restaurant_sys
cd ./database/restaurant_sys
# Flush the database
python manage.py flush --noinput --settings=restaurant_sys.settings.v1
python manage.py flush --noinput --settings=restaurant_sys.settings.v2
}
# Function to stop the servers
stop_servers() {
echo "Stopping database servers"
# Find and stop the background servers (change the port numbers)
pgrep -f "python manage.py runserver 9000" | xargs kill -9
pgrep -f "python manage.py runserver 9001" | xargs kill -9
}
makemigrations_database() {
echo "Makemigrating database"
# Change directory to the location of your database/restaurant_sys
cd ./database/restaurant_sys
# Migrate the database
python manage.py makemigrations --settings=restaurant_sys.settings.v1
python manage.py makemigrations --settings=restaurant_sys.settings.v2
}
migrate_database() {
echo "Migrating database"
# Change directory to the location of your database/restaurant_sys
cd ./database/restaurant_sys
# Migrate the database
python manage.py migrate --settings=restaurant_sys.settings.v1
python manage.py migrate --settings=restaurant_sys.settings.v2
}
restart_database(){
echo "Restarting database"
stop_servers
flush_database
start_servers
}
# Check the argument provided to the script
if [ "$1" == "start" ]; then
start_servers
elif [ "$1" == "stop" ]; then
stop_servers
elif [ "$1" == "flush" ]; then
flush_database
elif [ "$1" == "makemigrations" ]; then
makemigrations_database
elif [ "$1" == "migrate" ]; then
migrate_database
elif [ "$1" == "restart" ]; then
restart_database
else
echo "Usage: $0 [start|stop]"
exit 1
fi