#!/bin/bash
source $HOME/.gamerc
[ "$1" == "" ] && exec echo "Usage: $0 <TAG>"

TAG=$1
[ ! -z $TAG ] && CONDITIONAL_STATEMENT=" WHERE tag = '$TAG'"

CHECK_CNT=$(psql -U postgres $ACCOUNT_DB_NAME -c "COPY (SELECT COUNT(*) FROM xl_event_send_reward_by_system $CONDITIONAL_STATEMENT) TO STDOUT;")

if [ "$CHECK_CNT" -gt 0 ]; then
	psql -U postgres $ACCOUNT_DB_NAME -c "DELETE FROM xl_event_send_reward_by_system $CONDITIONAL_STATEMENT;"
else
	echo "Empty Data."
fi
