2013-04-01 23:02:24 +02:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
|
|
|
function migration_status {
|
|
|
|
./manage.py migrate --list | sed 's/*/ /' > "$1"
|
|
|
|
}
|
2013-03-05 23:08:55 +01:00
|
|
|
|
2013-05-08 05:30:42 +02:00
|
|
|
template_grep_error_code=$(echo "SELECT 1 from pg_database WHERE datname='humbug_test_template';" | python manage.py dbshell --settings=humbug.test_settings | grep -q "1 row"; echo $?)
|
|
|
|
|
|
|
|
if [ $template_grep_error_code == "0" ]; then
|
2013-07-29 23:03:31 +02:00
|
|
|
migration_status zerver/fixtures/available-migrations
|
|
|
|
if [ -e zerver/fixtures/migration-status ] &&
|
|
|
|
cmp -s zerver/fixtures/available-migrations zerver/fixtures/migration-status &&
|
2013-04-01 23:02:24 +02:00
|
|
|
[ "$1" != "--force" ]; then
|
2013-05-08 05:30:42 +02:00
|
|
|
psql -h localhost postgres humbug_test << EOF
|
|
|
|
DROP DATABASE humbug_test;
|
|
|
|
CREATE DATABASE humbug_test TEMPLATE humbug_test_template;
|
|
|
|
EOF
|
2013-03-05 23:08:55 +01:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2013-07-29 23:03:31 +02:00
|
|
|
mkdir -p zerver/fixtures
|
2013-01-10 22:58:01 +01:00
|
|
|
|
|
|
|
# Remove time.pyc to try to prevent it from screwing people importing
|
2013-07-29 23:03:31 +02:00
|
|
|
# time from inside zerver.lib. We can drop this hack after a bit.
|
|
|
|
rm -f zerver/lib/time.pyc
|
2013-01-10 22:58:01 +01:00
|
|
|
|
2013-05-08 05:30:42 +02:00
|
|
|
|
|
|
|
echo "DROP SCHEMA humbug CASCADE; CREATE SCHEMA humbug;" | python manage.py dbshell --settings=humbug.test_settings
|
2012-10-11 00:10:48 +02:00
|
|
|
python manage.py syncdb --noinput --settings=humbug.test_settings
|
2013-01-09 18:16:07 +01:00
|
|
|
python manage.py migrate --settings=humbug.test_settings --all
|
2013-07-29 23:03:31 +02:00
|
|
|
migration_status "zerver/fixtures/migration-status"
|
2013-04-01 23:02:24 +02:00
|
|
|
|
2013-01-08 21:59:52 +01:00
|
|
|
# This next line can be simplified to "-n0" once we fix our app with 0 messages.
|
|
|
|
python manage.py populate_db --settings=humbug.test_settings --test-suite -n2 \
|
|
|
|
--threads=1 --huddles=0 --personals=0 --percent-huddles=0 --percent-personals=0
|
2012-10-25 06:11:28 +02:00
|
|
|
python manage.py dumpdata --settings=humbug.test_settings \
|
2013-07-29 23:03:31 +02:00
|
|
|
zerver.UserProfile zerver.Stream zerver.Recipient \
|
|
|
|
zerver.Subscription zerver.Message zerver.Huddle zerver.Realm \
|
|
|
|
zerver.UserMessage zerver.Client \
|
|
|
|
zerver.DefaultStream > zerver/fixtures/messages.json
|
2013-03-05 23:08:55 +01:00
|
|
|
|
2013-05-08 05:30:42 +02:00
|
|
|
# create pristine template database, for fast fixture restoration after tests are run.
|
|
|
|
psql -h localhost postgres humbug_test << EOF
|
|
|
|
DROP DATABASE humbug_test_template;
|
|
|
|
CREATE DATABASE humbug_test_template TEMPLATE humbug_test;
|
|
|
|
EOF
|