40 lines
1.4 KiB
Bash
Executable File
40 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
########### IMPORT EXPORT/SCRIPT FOR DREDD TEST DATA ##############
|
|
###-------------------------------------------------------------###
|
|
###------------------- HOW TO USE THIS FILE --------------------###
|
|
###-------------------------------------------------------------###
|
|
### 1. start express server with `npm run start-api-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` ###
|
|
###################################################################
|
|
|
|
# execute script in its location folder
|
|
cd $(dirname $0)
|
|
|
|
while getopts m:p:d: option
|
|
do
|
|
case "${option}"
|
|
in
|
|
m) MODE=${OPTARG};;
|
|
p) PORT=${OPTARG};;
|
|
d) DATABASE=${OPTARG};;
|
|
esac
|
|
done
|
|
|
|
# array of available collection names
|
|
col=(app_user awarding campaign decoration logBudget logFlag logKill logPoints logRespawn logRevive logTransport logVehicle player promotion rank squad user war )
|
|
|
|
for i in "${col[@]}"
|
|
do
|
|
# provide date for restore process, if data import is needed
|
|
if [ "$MODE" == "save" ]
|
|
then
|
|
echo -e "$(date "+%Y-%m-%dT%T.%3N%z")\tTable: ${i}"
|
|
mongoexport --db ${DATABASE} --port ${PORT} --collection $i --out data/${i}.json;
|
|
else
|
|
mongoimport --db ${DATABASE} --port ${PORT} --collection $i --drop --file data/${i}.json
|
|
fi
|
|
done
|