-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathssq
More file actions
executable file
·75 lines (61 loc) · 1.65 KB
/
ssq
File metadata and controls
executable file
·75 lines (61 loc) · 1.65 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
#!/usr/bin/env bash
#
# Synopsis:
# Command line front end to sql queries for all schemas.
# Usage:
# ssq # help
# ssq hel # help
# ssq ls # list schemas qith ssq support
# Note:
# A schema of "." indicates using $(basename $(pwd))
#
# Consider adding action "ssq env <var>" for various global values,
# like PSQL.
#
PROG=$(basename $0)
USAGE="usage: $PROG [help | ls | <schema>"
usage()
{
echo "usage: $PROG [ls | help | <schema> ...options]"
}
die()
{
echo "$PROG: ERROR: $@" >&2
usage
exit 1
}
ACTION="$1"
[ $# -eq 0 -o "$ACTION" = help ] && exec echo $USAGE
shift
test -n "$SETSPACE_ROOT" || die "env not defined: SETSPACE_ROOT"
cd $SETSPACE_ROOT || die "cd failed: $SETSPACE_ROOT"
source lib/ssq-common.bash
# list the schemas that support ssq
[ "$ACTION" = ls ] && exec libexec/ssq-ls $@
SCHEMA=$ACTION
#
# Schema "." means use directory the script started in;
# otherwise, use schema on the command line.
#
if [ "$SCHEMA" = '.' ]; then
# use starting directory as schema name
SCHEMA=$(basename $OLDPWD)
test -d schema/$SCHEMA || die "current dir not a schema: $SCHEMA"
else
test -d "schema/$SCHEMA" || die "unknown schema: $SCHEMA"
fi
# exec "ssq <schema>" status
if [ $# = 0 ]; then
PSQL="$SSQ_COMMON_PSQL_EXPAND --set timing=on"
$PSQL \
--file lib/ssq-schema-status.sql \
--var since=yesterday \
--var schema=$SCHEMA ||
die "psql schema status failed: exit status=$?"
exit 0
fi
cd schema/$SCHEMA || die "cd schema $SCHEMA failed; exit status=$?"
source etc/profile || die "$SCHEMA: source etc/profile failed"
LIBEXEC="libexec/ssq-$SCHEMA"
test -x $LIBEXEC || die "no ssq for schema: $SCHEMA"
exec $LIBEXEC $@