-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCREATE-setspace-schema
More file actions
executable file
·81 lines (71 loc) · 1.89 KB
/
Copy pathCREATE-setspace-schema
File metadata and controls
executable file
·81 lines (71 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env bash
#
# Synopsis:
# Create the schema "setspace" and udig data types as superuser.
# Description:
# Create the setspace schema and install the udig data type in a database.
# The current role of caller must have super user permission to
# install the udig in setspace.udig in a particular database. Also,
# the schema.sql must be readable in the current directory oif invocation.
#
# Warning: dropping the schema "setspace" also drops columns in tables
# in other schemas like "setcore" and "fffile5". Use this script with
# caution.
#
# Exit Status:
# 0 ok, schema setspace and udig types installed in db $1
# 1 unexpected failure
# Note:
# This script is obsoleted by \if directives in schema.sql
#
PROG=$(basename $0)
PSQL='psql
--no-align
--no-psqlrc
--no-readline
--pset null=Unknown
--quiet
--set=ON_ERROR_STOP=true
--tuples-only
'
IS_SUPER_SQL='
SELECT
rolsuper
FROM
pg_roles
WHERE
rolname = current_role
'
log()
{
echo "$PROG: $@"
}
die()
{
log "ERROR: $@" >&2
exit 1
}
test $# = 1 || die "bad cli arg count: got $#, want 1"
DATABASE=$1
log "database: $DATABASE"
export PGDATABASE=$1
test -n "$SETSPACE_ROOT" || die "env not defined: SETSPACE_ROOT"
log "SETSPACE_ROOT=$SETSPACE_ROOT"
cd $SETSPACE_ROOT || die "cd SETSPACE_ROOT failed: exit status=$?"
log "PGHOST=$PGHOST"
log "PGPORT=$PGPORT"
log "PGUSER=$PGUSER"
log "PGDATABASE=$PGDATABASE"
log "PATH=$PATH"
log 'insure pg_config in PATH ...'
PG_CONFIG=$(which pg_config)
test -x "$PG_CONFIG" || die 'pg_config not in PATH'
log "pg_config path: $PG_CONFIG"
log get role super perms ...
IS_SUPER=$($PSQL --command "$IS_SUPER_SQL") || exit 1
log "is super: $IS_SUPER"
test "$IS_SUPER" = t || die 'current role is not super user'
SCHEMA_PATH=lib/schema.sql
log "schema path: $SCHEMA_PATH"
test -r $SCHEMA_PATH || die "can not read schema.sql"
psql --file $SCHEMA_PATH || die "psql schema failed: exit status=$?"