2018-03-24 19:04:22 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2018-04-02 00:32:45 +02:00
|
|
|
########### IMPORT EXPORT/SCRIPT FOR DREDD TEST DATA ##############
|
|
|
|
###-------------------------------------------------------------###
|
|
|
|
###------------------- HOW TO USE THIS FILE --------------------###
|
|
|
|
###-------------------------------------------------------------###
|
|
|
|
### 1. start express server with `npm run start-test` ###
|
|
|
|
### 2. import data by executing script: `./populate-data.sh` ###
|
|
|
|
### 3. change data in app as you need for tests ###
|
|
|
|
### 4. export data state with: `./populate-data.sh -m save` ###
|
|
|
|
###################################################################
|
2018-03-24 19:04:22 +01:00
|
|
|
|
|
|
|
# execute script in its location folder
|
|
|
|
cd $(dirname $0)
|
|
|
|
|
2018-04-02 00:32:45 +02:00
|
|
|
while getopts m:p:d: option
|
|
|
|
do
|
|
|
|
case "${option}"
|
|
|
|
in
|
|
|
|
m) MODE=${OPTARG};;
|
|
|
|
p) PORT=${OPTARG};;
|
|
|
|
d) DATABASE=${OPTARG};;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2018-03-24 19:04:22 +01:00
|
|
|
# array of available collection names
|
2018-03-30 12:53:49 +02:00
|
|
|
col=(app_user awarding campaign decoration logBudget logFlag logKill logPoints logRespawn logRevive logTransport logVehicle player promotion rank squad user war )
|
2018-03-24 19:04:22 +01:00
|
|
|
|
|
|
|
for i in "${col[@]}"
|
|
|
|
do
|
|
|
|
# provide date for restore process, if data import is needed
|
2018-04-02 00:32:45 +02:00
|
|
|
if [ "$MODE" == "save" ]
|
2018-03-24 19:04:22 +01:00
|
|
|
then
|
|
|
|
echo -e "$(date "+%Y-%m-%dT%T.%3N%z")\tTable: ${i}"
|
2018-04-02 00:32:45 +02:00
|
|
|
mongoexport --db ${DATABASE} --port ${PORT} --collection $i --out data/${i}.json;
|
2018-03-24 19:04:22 +01:00
|
|
|
else
|
2018-04-02 00:32:45 +02:00
|
|
|
mongoimport --db ${DATABASE} --port ${PORT} --collection $i --drop --file data/${i}.json
|
2018-03-24 19:04:22 +01:00
|
|
|
fi
|
|
|
|
done
|