onaio/onadata — pull request #85 by ukanga (2014-01-08 11:56:25+00:00)
Title: DO NOT MERGE: mysql to postgressql

# The Plan

create onadata user and db in psql
```bash
createuser -d -e -P -s onadata
createdb -E UTF8 -T template0 --locale=en_US.utf8 -O onadata onadata
```

with mysql settings dumpdata
```bash
python manage.py dumpdata --settings=formhub.settings > all.json
```

with postgresql settings, and a blank database
- edit local_settings DATABASE to point to postgresql backend
- syncdb, migrate

```bash
python manage.py syncdb --noinput --settings=formhub.settings
python manage.py migrate --settings=formhub.settings
```

set psql password in .pgpass
```bash
echo "*:*:*:onadata:onadatapasswd" > ~/.pgpass
chmod 600 ~/.pgpass
```

truncate tables
```bash
python manage.py sqlflush --settings=formhub.settings | psql -U onadata onadata
```

disable post_save, comment out the post_save.connect lines
```bash
find . -name '*.pyc' -type f -exec rm {} \;
grep -r post_save
```

loaddata
```bash
python manage.py loaddata --settings=formhub.settings all.json
```

Update to latest
```bash
git checkout origin/master
find . -name '*.pyc' -type f -exec rm {} \;
find * -empty -exec rmdir {} \;

cp formhub/local_settings.py onadata/settings/local_settings.py
```

edit local_settings to import from .common instead of from .settings
edit .bashrc
```bash
export DJANGO_SETTINGS_MODULE=onadata.settings.common
echo "export DJANGO_SETTINGS_MODULE=onadata.settings.common" >> ~/.bashrc

python manage syncdb
python manage migrate
```

clear sessions
```bash
python manage.py clearsessions
```