2013-04-01 23:02:24 +02:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
|
|
|
function migration_status {
|
2014-01-31 21:51:55 +01:00
|
|
|
./manage.py migrate --list --settings=zproject.test_settings | sed 's/*/ /' > "$1"
|
2013-04-01 23:02:24 +02:00
|
|
|
}
|
2013-03-05 23:08:55 +01:00
|
|
|
|
2013-10-26 04:24:40 +02:00
|
|
|
template_grep_error_code=$(echo "SELECT 1 from pg_database WHERE datname='zulip_test_template';" | python manage.py dbshell --settings=zproject.test_settings | grep -q "1 row"; echo $?)
|
2013-05-08 05:30:42 +02:00
|
|
|
|
2015-09-26 03:47:30 +02:00
|
|
|
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
|
2015-09-28 19:45:35 +02:00
|
|
|
"$(dirname "$0")/../scripts/setup/terminate-psql-sessions" zulip zulip_test zulip_test_base zulip_test_template
|
|
|
|
psql -h localhost postgres zulip_test << EOF
|
2014-01-30 23:40:07 +01:00
|
|
|
DROP DATABASE IF EXISTS zulip_test;
|
2013-10-26 04:24:40 +02:00
|
|
|
CREATE DATABASE zulip_test TEMPLATE zulip_test_template;
|
2013-05-08 05:30:42 +02:00
|
|
|
EOF
|
2015-09-28 19:57:40 +02:00
|
|
|
sh "$(dirname "$0")/../scripts/setup/flush-memcached"
|
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
|
|
|
|
2015-09-28 19:45:35 +02:00
|
|
|
"$(dirname "$0")/../scripts/setup/terminate-psql-sessions" zulip zulip_test zulip_test_base zulip_test_template
|
|
|
|
|
2014-01-30 23:40:37 +01:00
|
|
|
psql -h localhost postgres zulip_test <<EOF
|
|
|
|
DROP DATABASE IF EXISTS zulip_test;
|
|
|
|
CREATE DATABASE zulip_test TEMPLATE zulip_test_base;
|
|
|
|
EOF
|
2015-09-28 19:57:40 +02:00
|
|
|
sh "$(dirname "$0")/../scripts/setup/flush-memcached"
|
2014-01-30 23:40:37 +01:00
|
|
|
|
2015-08-21 01:01:16 +02:00
|
|
|
python manage.py migrate --noinput --settings=zproject.test_settings
|
2013-07-29 23:03:31 +02:00
|
|
|
migration_status "zerver/fixtures/migration-status"
|
2013-04-01 23:02:24 +02:00
|
|
|
|
2015-08-20 23:47:05 +02:00
|
|
|
# This next line can be simplified to "-n0" once we fix our app (and tests) with 0 messages.
|
|
|
|
python manage.py populate_db --settings=zproject.test_settings --test-suite -n30 \
|
2013-01-08 21:59:52 +01:00
|
|
|
--threads=1 --huddles=0 --personals=0 --percent-huddles=0 --percent-personals=0
|
2013-08-06 22:51:47 +02:00
|
|
|
python manage.py dumpdata --settings=zproject.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.
|
2013-10-26 04:24:40 +02:00
|
|
|
psql -h localhost postgres zulip_test << EOF
|
2014-01-30 23:40:07 +01:00
|
|
|
DROP DATABASE IF EXISTS zulip_test_template;
|
2013-10-26 04:24:40 +02:00
|
|
|
CREATE DATABASE zulip_test_template TEMPLATE zulip_test;
|
2013-05-08 05:30:42 +02:00
|
|
|
EOF
|