#!/usr/bin/env bash

source /home/devorch/collab/jgetter/perllib/lib/shell_globals

EXEC=$1

dd=$(date "+%Y%m%d")
yy=$(date "+%Y")
mm=$(date "+%m")
of="abacus-prod-${dd}.sql"

runit "mysqldump --login-path=abacus_prod \
--databases royalty_accounting \
--no-create-db \
--routines \
--verbose \
--ignore_table=royalty_accounting.report_custom \
--ignore_table=royalty_accounting.statement_attachment \
--skip-add-locks \
--skip-disable-keys \
--set-gtid-purged=OFF \
>${of}"

runit "perl -pi -e 's/ra-deploy/jgetter/g' ${of}"

runit "mysql --login-path=abacus_qa < ${of}"

find data-refresh -mindepth 1 -maxdepth 1 -name '*.sql'|while read f
do
runit "mysql --login-path=abacus_qa -D royalty_accounting -v < ${f}"
done

find data-refresh/migration-contracts -mindepth 1 -maxdepth 1 -name '*.sql'|while read f
do
runit "mysql --login-path=abacus_qa -D royalty_accounting -v < ${f}"
done

