simplifying schema evolution
[quassel.git] / src / core / SQL / upgradeSchema.sh
1 #!/bin/bash
2
3 TARGET_DIR=$1
4 if [ ! $TARGET_DIR ]; then
5     TARGET_DIR=`pwd`
6 fi
7
8 if [[ ! -d $TARGET_DIR ]]; then
9     echo "No such directory $TARGET_DIR"
10     exit 1
11 fi
12
13 cd $TARGET_DIR
14
15 CURRENT_VERSION=$(ls | sort -n | tail -n1)
16
17 if [ ! $CURRENT_VERSION ]; then
18     echo "no previous schema found to upgrade from"
19     exit 2
20 fi
21
22 ((NEW_VERSION=$CURRENT_VERSION + 1))
23
24 mkdir $NEW_VERSION
25 git add $NEW_VERSION
26 find $CURRENT_VERSION -depth 1 \! -name "upgrade_*" \! -name ".*" -exec git mv {} $NEW_VERSION \;