Skip to content

Instantly share code, notes, and snippets.

@tkuchiki
Last active November 28, 2016 08:13
Show Gist options
  • Save tkuchiki/eb14ed34e4744a7f48a0a7ad820fdd41 to your computer and use it in GitHub Desktop.
Save tkuchiki/eb14ed34e4744a7f48a0a7ad820fdd41 to your computer and use it in GitHub Desktop.
# redash.0.11.0.b2016 to redash.0.12.0.b2449
$ upgrade.sh 0.12.0.b2449
#!/bin/bash
new_version="${1}"
if [ "${new_version}" = "" ]; then
echo "\$1(= version) is required."
exit 1
fi
new_version_path="/opt/redash/redash.${new_version}"
new_version_archive="redash.${new_version}.tar.gz"
base_dir=/opt/redash
current_version_path="$(readlink ${base_dir}/current)"
current_version="$(basename ${current_version_path})"
cd ${base_dir}
sudo wget --header="Accept: application/octet-stream" https://github.com/getredash/redash/releases/download/v${new_version}/${new_version_archive}
sudo mkdir -p ${new_version_path}
sudo tar -C ${new_version_path} -xvf ${new_version_archive}
sudo rm -f ${new_version_archive}
sudo chown redash -R ${new_version_path}
sudo ln -nfs ${base_dir}/.env ${new_version_path}/.env
if !(cmp ${current_version_path}/requirements.txt ${new_version_path}/requirements.txt); then
sudo pip install -r ${new_version_path}/requirements.txt
fi
# backup
sudo -u postgres pg_dump redash > ${current_version}.$(date +"%Y%m%dT%M%H%S").sql
cd ${new_version_path}
do_migration() {
sudo -u redash PYTHONPATH=. bin/run python ${1}
}
for f in $(find ${new_version_path}/migrations/ -type f | sort); do
current_f="${current_version_path}/migrations/$(basename ${f})"
if [ ! -f ${current_f} ]; then
do_migration ${f}
continue
fi
cmp -s ${f} ${current_f} || do_migration ${f}
done
sudo ln -nfs ${new_version_path} ${base_dir}/current
sudo service redash_supervisord restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment