Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Dec 7, 2012
0 parents commit a7b8f76
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
civicrm-upgrade-test.settings
output/*
databases/private-*
*~
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
The civicrm-upgrade-test suite provides a set of sample databases which can
be used for testing upgrade-logic.

### Scope

To facilitate testing of many databases, the current script uses the
command-line based upgrade system (drush) and never uses the web-based UI
(civicrm/upgrade). Therefore, it is appropriate for testing the database
manipulations -- but it does not test the UI aspects of the upgrader (such
as browser compatibility).

### Pre-Requisites

* Have a Unix-like environment (bash)
* Install Drupal 7, CiviCRM, and Drush
* Use separate databases for Drupal and CiviCRM
* Configure the username/password for a MySQL administrator in ~/.my.cnf

### Setup

```bash
## Checkout the repo
cd $HOME
git clone git://github.com/totten/civicrm-upgrade-test.git

## Create and edit a settings file
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

## Run the script
bash civicrm-upgrade-test
```
111 changes: 111 additions & 0 deletions civicrm-upgrade-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/bin/bash

## Determine the absolute path to a directory or file
function abspath {
if [[ -d "$1" ]]
then
pushd "$1" >/dev/null
pwd
popd >/dev/null
elif [[ -e $1 ]]
then
pushd "$(dirname "$1")" >/dev/null
echo "$(pwd)/$(basename "$1")"
popd >/dev/null
else
echo "$1" does not exist! >&2
return 127
fi
}

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

SCRIPT_PATH=$(abspath "$0")
SCRIPT_DIR=$(dirname "$SCRIPT_PATH")
if [ -f "$SCRIPT_DIR/civicrm-upgrade-test.settings" ]; then
source "$SCRIPT_DIR/civicrm-upgrade-test.settings"
else
echo "Warning: Could not find $SCRIPT_DIR/civicrm-upgrade-test.settings"
fi

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
;;
--db)
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]"
exit 1
;;
esac
done

#####################################################################
## Validate options
echo "Web Dir: [$WEB_ROOT]"
echo "Database Dir: [$DATABASE_DIR]"
echo "Output Dir: [$OUTPUT_DIR]"
echo "Database: [$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
if [ -z "$OUTPUT_DIR" ]; then
echo "Missing output dir"
exit
elif mkdir -p "$OUTPUT_DIR" ; then
echo "Created output dir"
else
echo "Failed to make output dir"
exit
fi
fi
if [ -z "$TEST_DATABASE" ]; then
echo "Missing or invalid database name"
exit 2
fi

#####################################################################
## Run upgrades
if [ -n "$DRUPAL_SITE" ]; then
DRUSH="drush -l $DRUPAL_SITE"
else
DRUSH="drush"
fi

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

echo "drop database $TEST_DATABASE" | mysql
echo "create database $TEST_DATABASE" | mysql
bzcat "$SQLBZ2" | mysql "$TEST_DATABASE"
$DRUSH civicrm-upgrade-db > "${OUTPUT_DIR}/${NAME}.out"
exit
echo
done
14 changes: 14 additions & 0 deletions civicrm-upgrade-test.settings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## The base directory of the test installation
WEB_ROOT=/Applications/MAMP/htdocs

## (For Drupal multisite) Specify the name of the Drupal site
# DRUPAL_SITE=test.localhost

## 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 a7b8f76

Please sign in to comment.