#!/bin/bash

# 載入 gamerc
source ~/.gamerc

# 台版收藏冊ID與名稱對應
cat ${WORKING_DIRECTORY}/common-${SOURCE_OF_SYNC_TO_LIVE}/Data/db/s_collection.ini | egrep '^[0-9].*' | sed 's/,/=>/g' | awk -F"|" '{print $1","$2","$3","$5","$7}' > /tmp/collection2db_tw.csv

# 台版場景對應 CSV 同步到 Ctrl 機, 並更新到 collection2db
scp /tmp/collection2db_tw.csv ctrl:/tmp

ssh ctrl "psql -U postgres WebTool -c \"CREATE TABLE IF NOT EXISTS collection2db (collection_id integer primary key, collection_name text, item_id integer, display integer, collection_point integer)\""
ssh ctrl "psql -U postgres WebTool -c \"TRUNCATE collection2db\""
ssh ctrl "psql -U postgres WebTool -c \"COPY collection2db (collection_id,collection_name,item_id,display,collection_point) FROM '/tmp/collection2db_tw.csv' csv\""
