/
db.toml
152 lines (136 loc) · 5.16 KB
/
db.toml
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# Tool needed to run DB migrations.
# See: https://github.com/rust-db/refinery/tree/main/refinery_cli
[tasks.install-refinery-cli]
install_crate = { crate_name = "refinery_cli", binary = "refinery", test_arg = "--help" }
# All the prerequisite tooling needed to work with the DB.
[tasks.install-db-prereqs]
workspace = false
run_task = { name = [
"install-refinery-cli",
], parallel = true }
# Setup the local database ready to run the migrations.
[tasks.local-event-db-init]
workspace = false
category = "db"
script_runner = "@shell"
script = '''
cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/src/event-db
export DB_USER_PW="CHANGE_ME"
ls setup
psql -e postgres -f setup/setup-db.sql \
-v dbName=CatalystEventDev \
-v dbDescription="Local Dev Catalayst Event DB" \
-v dbUser="catalyst-event-dev" ${@}
'''
# Run Diesel Migrations, constructing the full up-to-date DB in a local database.
[tasks.run-event-db-migration]
workspace = false
category = "db"
script_runner = "@shell"
script = '''
cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/src/event-db
refinery migrate -c refinery.toml -p ./migrations
'''
[tasks.local-db-test-data-setup]
workspace = false
category = "db"
script_runner = "@shell"
script = '''
cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/src/event-db
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/01_event_table.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/02_snapshot_table.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/03_voter_table.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/04_contribution_table.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/05_goal_table.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/06_objective_table.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/07_voteplan_table.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/08_proposal_table.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/09_proposal_review_table.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/10_review_rating_table.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f test_data/11_objective_review_metric_table.sql ${@}
'''
# Install historic data for past events
[tasks.local-db-historic-data-setup]
workspace = false
category = "db"
script_runner = "@shell"
script = '''
cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/src/event-db
psql -U catalyst-event-dev -d CatalystEventDev -f historic_data/fund_0.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f historic_data/fund_1.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f historic_data/fund_2.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f historic_data/fund_3.sql ${@}
psql -U catalyst-event-dev -d CatalystEventDev -f historic_data/fund_4.sql ${@}
# psql -U catalyst-event-dev -d CatalystEventDev -f historic_data/fund_5.sql ${@}
# psql -U catalyst-event-dev -d CatalystEventDev -f historic_data/fund_6.sql ${@}
# psql -U catalyst-event-dev -d CatalystEventDev -f historic_data/fund_7.sql ${@}
# psql -U catalyst-event-dev -d CatalystEventDev -f historic_data/fund_8.sql ${@}
# psql -U catalyst-event-dev -d CatalystEventDev -f historic_data/fund_9.sql ${@}
'''
# Setup the local database graphql configuration.
[tasks.local-event-db-graphql-init]
workspace = false
category = "db"
script_runner = "@shell"
script = '''
cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/src/event-db
export ADMIN_ROLE_PW="CHANGE_ME"
export ANON_ROLE_PW="CHANGE_ME"
export ADMIN_USER_PW="CHANGE_ME"
psql -e postgres -f setup/graphql-setup.sql \
-v dbName=CatalystEventDev \
-v dbUser="catalyst-event-dev" \
-v adminUserFirstName="Admin" \
-v adminUserLastName="Default" \
-v adminUserAbout="Default Admin User" \
-v adminUserEmail="admin.default@projectcatalyst.io" ${@}
'''
# Setup the local database ready to run the migrations.
[tasks.local-event-db-setup]
workspace = false
category = "db"
dependencies = [
"local-event-db-init",
"local-event-db-graphql-init",
"run-event-db-migration",
"local-db-historic-data-setup"
]
# Setup the local database with the test data.
[tasks.local-event-db-test]
workspace = false
category = "db"
dependencies = [
"local-event-db-init",
"run-event-db-migration",
"local-db-test-data-setup"
]
# Run Diesel Migrations, for documentation purposes.
[tasks.run-event-doc-db-migration]
workspace = false
category = "db"
script_runner = "@shell"
script = '''
cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/src/event-db
refinery migrate -c refinery-docs.toml -p ./migrations
'''
# Setup the local database ready to run the migrations.
[tasks.doc-event-db-init]
workspace = false
category = "db"
script_runner = "@shell"
script = '''
cd ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/src/event-db
psql -e -f setup/setup-db.sql \
-v dbName=CatalystEventDocs \
-v dbDescription="Local Docs Catalayst Event DB" \
-v dbUser="catalyst-event-docs" \
-v dbUserPw="CHANGE_ME" ${@}
'''
# Setup the local database ready to run the migrations.
[tasks.doc-event-db-setup]
workspace = false
category = "db"
dependencies = [
"doc-event-db-init",
"run-event-doc-db-migration"
]