This file looks large and may slow your browser down if we attempt
to syntax highlight it, so we are showing it without any
pretty colors.
Highlight
it anyway.
| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# ******************************* WARNING ********************************* |
| 4 |
# Do not run this script until you have read and understood the information |
| 5 |
# below, AND backed up your database. Failure to observe these instructions |
| 6 |
# may result in losing all the data in your database. |
| 7 |
# |
| 8 |
# This script is used to upgrade StatusNet's PostgreSQL database to the |
| 9 |
# latest version. It does the following: |
| 10 |
# |
| 11 |
# 1. Dumps the existing data to /tmp/rebuilddb_psql.sql |
| 12 |
# 2. Clears out the objects (tables, etc) in the database schema |
| 13 |
# 3. Reconstructs the database schema using the latest script |
| 14 |
# 4. Restores the data dumped in step 1 |
| 15 |
# |
| 16 |
# You MUST run this script as the 'postgres' user. |
| 17 |
# You MUST be able to write to /tmp/rebuilddb_psql.sql |
| 18 |
# You MUST specify the statusnet database user and database name on the |
| 19 |
# command line, e.g. ./rebuilddb_psql.sh myuser mydbname |
| 20 |
# |
| 21 |
|
| 22 |
user=$1 |
| 23 |
DB=$2 |
| 24 |
|
| 25 |
cd `dirname $0` |
| 26 |
|
| 27 |
pg_dump -a -D --disable-trigger $DB > /tmp/rebuilddb_psql.sql |
| 28 |
psql -c "drop schema public cascade; create schema public;" $DB |
| 29 |
psql -c "grant all privileges on schema public to $user;" $DB |
| 30 |
psql $DB < ../db/statusnet_pg.sql |
| 31 |
psql $DB < /tmp/rebuilddb_psql.sql |
| 32 |
for tab in `psql -c '\dts' $DB -tA | cut -d\| -f2`; do |
| 33 |
psql -c "ALTER TABLE \"$tab\" OWNER TO $user;" $DB |
| 34 |
done |