1818 exit 1
1919fi
2020
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
2327
2428# starting metabase jar locally
2529java -jar metabase.jar > logs 2>&1 &
@@ -81,7 +85,17 @@ json='{
8185 "visualization_settings": {},
8286 "collection_id": 2
8387}'
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
8599
86100json=' {
87101 "name":"test_card_2",
@@ -94,7 +108,7 @@ json='{
94108 "name":"test_filter",
95109 "display-name":"Test filter",
96110 "type":"dimension",
97- "dimension":["field",72 ,null],
111+ "dimension":["field",COL1_ID ,null],
98112 "widget-type":"string/=",
99113 "default":null,
100114 "id":"810912da-ead5-c87e-de32-6dc5723b9067"
@@ -115,6 +129,9 @@ json='{
115129 }],
116130 "collection_id":2
117131}'
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+
118135echo " $json " | curl -X POST http://localhost:3000/api/card -H " Content-Type: application/json" -H " X-Metabase-Session:$session_id " -d @-
119136
120137json=' {
@@ -123,13 +140,16 @@ json='{
123140 "type":"query",
124141 "query":{
125142 "source-table":9,
126- "filter":["=",["field",72 ,null],"row1 cell1","row3 cell1"]},
143+ "filter":["=",["field",COL1_ID ,null],"row1 cell1","row3 cell1"]},
127144 "database":2
128145 },
129146 "display":"table",
130147 "visualization_settings":{},
131148 "collection_id":2
132149}'
150+ # add the value of $col1_id
151+ json=$( echo " $json " | sed " s/COL1_ID/$col1_id /g" )
152+
133153echo " $json " | curl -X POST http://localhost:3000/api/card -H " Content-Type: application/json" -H " X-Metabase-Session:$session_id " -d @-
134154
135155json=' {
@@ -139,8 +159,8 @@ json='{
139159 "database":2,
140160 "query":{
141161 "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]],
144164 "order-by":[["desc",["aggregation",0,null]]]
145165 },
146166 "type":"query"
@@ -149,6 +169,9 @@ json='{
149169 "visualization_settings":{"table.pivot":false,"graph.dimensions":["col1"],"graph.metrics":["avg"]},
150170 "collection_id":2
151171}'
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+
152175echo " $json " | curl -X POST http://localhost:3000/api/card -H " Content-Type: application/json" -H " X-Metabase-Session:$session_id " -d @-
153176
154177# create a test dashboard
0 commit comments