-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsetup_mac_data.sh
executable file
·97 lines (84 loc) · 2.71 KB
/
setup_mac_data.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash
source .env
function configureDatabase() {
brew install postgresql
echo "Database $LEARN_OPS_DB does not exist"
psql -c "DROP DATABASE IF EXISTS $LEARN_OPS_DB WITH (FORCE);"
psql -c "CREATE DATABASE $LEARN_OPS_DB;"
psql -c "CREATE USER $LEARN_OPS_USER WITH PASSWORD '$LEARN_OPS_PASSWORD';"
psql -c "ALTER ROLE $LEARN_OPS_USER SET client_encoding TO 'utf8';"
psql -c "ALTER ROLE $LEARN_OPS_USER SET default_transaction_isolation TO 'read committed';"
psql -c "ALTER ROLE $LEARN_OPS_USER SET timezone TO 'UTC';"
psql -c "GRANT ALL PRIVILEGES ON DATABASE $LEARN_OPS_USER TO $LEARN_OPS_DB;"
}
function generateSocialFixture() {
echo '[
{
"model": "sites.site",
"pk": 1,
"fields": {
"domain": "learningplatform.com",
"name": "Learning Platform"
}
},
{
"model": "socialaccount.socialapp",
"pk": 1,
"fields": {
"provider": "github",
"name": "Github",
"client_id": "'"$LEARN_OPS_CLIENT_ID"'",
"secret": "'"$LEARN_OPS_SECRET_KEY"'",
"key": "",
"sites": [
1
]
}
}
]
' >./LearningAPI/fixtures/socialaccount.json
}
function generateSuperuserFixture() {
export DJANGO_SETTINGS_MODULE="LearningPlatform.settings"
hashedPassword=$(python3 ./djangopass.py "$LEARN_OPS_SUPERUSER_PASSWORD" >&1)
echo '[
{
"model": "auth.user",
"pk": null,
"fields": {
"password": "'"$hashedPassword"'",
"last_login": null,
"is_superuser": true,
"username": "'"$LEARN_OPS_SUPERUSER_NAME"'",
"first_name": "Admina",
"last_name": "Straytor",
"email": "[email protected]",
"is_staff": true,
"is_active": true,
"date_joined": "2023-03-17T03:03:13.265Z",
"groups": [
2
],
"user_permissions": []
}
}
]' >./LearningAPI/fixtures/superuser.json
}
function initializeProject() {
pipenv --python 3.9.1
# Install project requirements
pipenv install
# Run existing migrations
pipenv run migrate
# Load data from backup
pipenv run bash -c "python3 manage.py flush --no-input \
&& python3 manage.py loaddata socialaccount \
&& python3 manage.py loaddata complete_backup \
&& python3 manage.py loaddata superuser"
rm ./LearningAPI/fixtures/superuser.json
rm ./LearningAPI/fixtures/socialaccount.json
}
configureDatabase
generateSocialFixture
generateSuperuserFixture
initializeProject