New script to perform the upgrade of the site.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Tue, 12 Oct 2010 14:47:38 +0000 (16:47 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Tue, 12 Oct 2010 14:47:38 +0000 (16:47 +0200)
Instead of calling:
 % cd upgrade/{version}/
 % ./update.sh
The migration of the db can be done through:
 % upgrade/update.sh

The script will automatically discover the version of the upgrade scripts
to be run.

Note: my goal is to build a script that can be used to perform most of the
steps of the migration, not only the upgrade of the db and, if possible,
that can detect the needed upgrades (let say "what must I do to upgrade
this site that ran platal 0.10.1 to platal 1.0.1"). Feel free to
improve this script.

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
upgrade/update.sh [new file with mode: 0755]

diff --git a/upgrade/update.sh b/upgrade/update.sh
new file mode 100755 (executable)
index 0000000..4036c76
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+
+spoolroot="$(readlink -f $(dirname $0)/..)"
+dbversionfile="$spoolroot/spool/tmp/db_version"
+
+currentversion="$(grep 'VERSION' $spoolroot/ChangeLog | cut -d ' ' -f 2 | head -n 1)"
+previousversion="$(cat $dbversionfile 2> /dev/null)"
+
+function die() {
+  echo "$1" 1>&2
+  exit 1
+}
+
+if [ "$currentversion" != "$previousversion" ]; then
+  cd $spoolroot/upgrade/$currentversion/
+  ./update.sh "$@" || die "Upgrade to $currentversion failed"
+  echo "$currentversion" > $dbversionfile
+else
+  echo "Already at version $currentversion"
+fi