]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - scripts/rebuilddb_psql.sh
Merge branch 'invite-enabled' of git://gitorious.org/~jeff-themovie/laconica/jeff...
[quix0rs-gnu-social.git] / scripts / rebuilddb_psql.sh
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 Laconica'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 laconica 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/laconica_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