#!/bin/sh
export THIS_DIR="$(cd "$( dirname "$0" )" && pwd )"
. $THIS_DIR/../../sysbase/tools/export_php_config_to_shell.sh

#create database
API_DB_NAME=arcp
echo "create database IF NOT EXISTS $API_DB_NAME" | mysql -f -h $API_DB_HOST -u $API_DB_USER --password=$API_DB_PASSWD 2>&1 | grep -v 'password on the command line' || true

#移除舊版(v1)的表格
/usr/bin/php "$THIS_DIR/mysql/drop_v1_tables.php"

#create table
mysql -h $API_DB_HOST -u $API_DB_USER --password=$API_DB_PASSWD $API_DB_NAME < "$THIS_DIR/mysql/create_tables.sql" 2>&1 | grep -v 'password on the command line' || true

if [ ! -d /var/log/api/app_user/ ];then
    mkdir -p /var/log/api/app_user/
fi
chown apache.apache -R /var/log/api/app_user/

# To recursively give directories read&execute privileges:
find /var/log/api/app_user -type d -exec chmod 755 {} +