Skip to content

Commit

Permalink
Allow user to pass in list of database files. Don't force user to run…
Browse files Browse the repository at this point in the history
… tests for *all* databases.
  • Loading branch information
totten committed Dec 7, 2012
1 parent e5dcdd6 commit f2cb443
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ cd civicrm-upgrade-test
cp civicrm-upgrade-test.settings.txt civicrm-upgrade-test.settings
vi civicrm-upgrade-test.settings
## Note: The file will include comments on the configuration options
```

### Usage

```bash
## Run the script with a single database
bash civicrm-upgrade-test databases/4.2.0-setupsh.sql.bz2

## Run the script
bash civicrm-upgrade-test
## Run the script with all databases
bash civicrm-upgrade-test databases/*.sql.bz2
```
38 changes: 21 additions & 17 deletions civicrm-upgrade-test
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ function abspath {
fi
}

function showHelp {
echo "usage: $0 [--out /path/to/output/dir] [--web /path/to/web/root] [--db mysql_database_name] <file1.sql.bz2> <file2.sql.bz2> ..."
}

#####################################################################
## Load options

Expand All @@ -29,16 +33,13 @@ else
echo "Warning: Could not find $SCRIPT_DIR/civicrm-upgrade-test.settings"
fi

DATABASE_FILES=""
while [ -n "$1" ]; do
case "$1" in
--web)
WEB_ROOT="$2"
shift 2
;;
--in)
DATABASE_DIRS="$2"
shift 2
;;
--out)
OUTPUT_DIR="$2"
shift 2
Expand All @@ -47,30 +48,28 @@ while [ -n "$1" ]; do
TEST_DATABASE="$2"
shift 2
;;
*)
echo "unrecognized: $1"
echo "usage: $0 [--in /path/to/database/dumpdir] [--out /path/to/output/dir] [--web /path/to/web/root] [--db mysql_database_name]"
--help)
showHelp
exit 1
;;
*)
DATABASE_FILES="$DATABASE_FILES $1"
shift
;;
esac
done

#####################################################################
## Validate options
echo "Web Dir: [$WEB_ROOT]"
echo "Database Dir: [$DATABASE_DIR]"
echo "Output Dir: [$OUTPUT_DIR]"
echo "Database: [$TEST_DATABASE]"
echo "Database Name: [$TEST_DATABASE]"
echo ""

if [ ! -d "$WEB_ROOT" ]; then
echo "Missing or invalid web dir"
exit 2
fi
if [ ! -d "$DATABASE_DIR" ]; then
echo "Missing or invalid database dir"
exit 2
fi
if [ ! -d "$OUTPUT_DIR" ]; then
#echo "Missing or invalid output dir"
#exit 2
Expand All @@ -88,6 +87,11 @@ if [ -z "$TEST_DATABASE" ]; then
echo "Missing or invalid database name"
exit 2
fi
if [ -z "$DATABASE_FILES" ]; then
echo "Missing list of database backup files (*.sql.bz2)"
showHelp
exit 2
fi

#####################################################################
## Run upgrades
Expand All @@ -97,15 +101,15 @@ else
DRUSH="drush"
fi

cd "$WEB_ROOT"
for SQLBZ2 in "${DATABASE_DIR}"/*.sql.bz2 ; do
echo "Test $SQLBZ2"
for SQLBZ2 in $DATABASE_FILES ; do
echo "Test [$SQLBZ2]"
NAME=$(basename $SQLBZ2)

echo "drop database $TEST_DATABASE" | mysql
echo "create database $TEST_DATABASE" | mysql
bzcat "$SQLBZ2" | mysql "$TEST_DATABASE"
pushd "$WEB_ROOT" > /dev/null
$DRUSH civicrm-upgrade-db > "${OUTPUT_DIR}/${NAME}.out"
exit
popd > /dev/null
echo
done
3 changes: 0 additions & 3 deletions civicrm-upgrade-test.settings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@ WEB_ROOT=/Applications/MAMP/htdocs
## The MySQL database which stores CiviCRM
TEST_DATABASE=civi

## The directory which contains *.sql.bz2 files for example DBs
DATABASE_DIR="$SCRIPT_DIR/databases"

## The directory which stores output from each test run
OUTPUT_DIR="$SCRIPT_DIR/output"

0 comments on commit f2cb443

Please sign in to comment.