18
18
exit 1
19
19
fi
20
20
21
- # downloading metabase jar
22
- wget -q https://downloads.metabase.com/v$MB_VERSION /metabase.jar
21
+ # cleaup (in case the script is not running for the first time)
22
+ rm -f metabase.db.mv.db
23
+ rm -f metabase.db.trace.db
24
+
25
+ # downloading metabase jar file
26
+ wget -O metabase.jar -q https://downloads.metabase.com/v$MB_VERSION /metabase.jar
23
27
24
28
# starting metabase jar locally
25
29
java -jar metabase.jar > logs 2>&1 &
@@ -81,7 +85,17 @@ json='{
81
85
"visualization_settings": {},
82
86
"collection_id": 2
83
87
}'
84
- echo " $json " | curl -X POST http://localhost:3000/api/card -H " Content-Type: application/json" -H " X-Metabase-Session:$session_id " -d @-
88
+ echo " $json " | curl -X POST http://localhost:3000/api/card -H " Content-Type: application/json" -H " X-Metabase-Session:$session_id " -d @- > output
89
+
90
+ # the order of the IDs assigned to columns is not based on the db column order
91
+ grep -q ' ,73.*,72' output
92
+ if [[ $? -eq 0 ]]; then
93
+ col1_id=73;
94
+ col2_id=72;
95
+ else
96
+ col1_id=72;
97
+ col2_id=73;
98
+ fi
85
99
86
100
json=' {
87
101
"name":"test_card_2",
@@ -94,7 +108,7 @@ json='{
94
108
"name":"test_filter",
95
109
"display-name":"Test filter",
96
110
"type":"dimension",
97
- "dimension":["field",72 ,null],
111
+ "dimension":["field",COL1_ID ,null],
98
112
"widget-type":"string/=",
99
113
"default":null,
100
114
"id":"810912da-ead5-c87e-de32-6dc5723b9067"
@@ -115,6 +129,9 @@ json='{
115
129
}],
116
130
"collection_id":2
117
131
}'
132
+ # add the value of $col1_id (because of presense of single and double quotes in the json string, I decided to add the variable value in this way)
133
+ json=$( echo " $json " | sed " s/COL1_ID/$col1_id /g" )
134
+
118
135
echo " $json " | curl -X POST http://localhost:3000/api/card -H " Content-Type: application/json" -H " X-Metabase-Session:$session_id " -d @-
119
136
120
137
json=' {
@@ -123,13 +140,16 @@ json='{
123
140
"type":"query",
124
141
"query":{
125
142
"source-table":9,
126
- "filter":["=",["field",72 ,null],"row1 cell1","row3 cell1"]},
143
+ "filter":["=",["field",COL1_ID ,null],"row1 cell1","row3 cell1"]},
127
144
"database":2
128
145
},
129
146
"display":"table",
130
147
"visualization_settings":{},
131
148
"collection_id":2
132
149
}'
150
+ # add the value of $col1_id
151
+ json=$( echo " $json " | sed " s/COL1_ID/$col1_id /g" )
152
+
133
153
echo " $json " | curl -X POST http://localhost:3000/api/card -H " Content-Type: application/json" -H " X-Metabase-Session:$session_id " -d @-
134
154
135
155
json=' {
@@ -139,8 +159,8 @@ json='{
139
159
"database":2,
140
160
"query":{
141
161
"source-table":9,
142
- "aggregation":[["avg",["field",73 ,null]]],
143
- "breakout":[["field",72 ,null]],
162
+ "aggregation":[["avg",["field",COL2_ID ,null]]],
163
+ "breakout":[["field",COL1_ID ,null]],
144
164
"order-by":[["desc",["aggregation",0,null]]]
145
165
},
146
166
"type":"query"
@@ -149,6 +169,9 @@ json='{
149
169
"visualization_settings":{"table.pivot":false,"graph.dimensions":["col1"],"graph.metrics":["avg"]},
150
170
"collection_id":2
151
171
}'
172
+ # add the value of $col1_id and $col2_id
173
+ json=$( echo " $json " | sed " s/COL1_ID/$col1_id /g" | sed " s/COL2_ID/$col2_id /g" )
174
+
152
175
echo " $json " | curl -X POST http://localhost:3000/api/card -H " Content-Type: application/json" -H " X-Metabase-Session:$session_id " -d @-
153
176
154
177
# create a test dashboard
0 commit comments