#!/usr/bin/env bash

# Generate the database migration files

set -o xtrace

VERSION="$( head -1 debian/changelog | awk -F'[()-]' '{ print $2 }' )"

sudo ip addr add 10.0.1.250/32 dev lo

pushd $( git rev-parse --show-toplevel ) &>/dev/null
pushd api-daemon &>/dev/null
export PVC_CONFIG_FILE="../pvc.sample.conf"
export FLASK_APP=./pvcapid-manage_flask.py
flask db migrate -m "PVC version ${VERSION}"
flask db upgrade
popd &>/dev/null
popd &>/dev/null

sudo ip addr del 10.0.1.250/32 dev lo
