-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-object-generate.sh
executable file
·121 lines (83 loc) · 3.52 KB
/
run-object-generate.sh
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/sh
date=$(date '+%Y-%m-%d')
cat > /tmp/sql-prod <<EOF
--set client_min_messages = warning;
--\d+ (shows sequence)
--epoch
--select extract(epoch from date_added) from t_transaction;
--select date_part('epoch', date_added) from t_transaction;
--SELECT EXTRACT(EPOCH FROM TIMESTAMP '2016-10-25T00:14:30.000');
--extract(epoch from date_trunc('month', current_timestamp)
--REVOKE CONNECT ON DATABASE finance_db FROM PUBLIC, henninb;
--TO_TIMESTAMP('1538438975')
DROP DATABASE IF EXISTS finance_db;
CREATE DATABASE finance_db;
GRANT ALL PRIVILEGES ON DATABASE finance_db TO henninb;
REVOKE CONNECT ON DATABASE finance_db FROM public;
\connect finance_db;
CREATE SCHEMA prod;
EOF
cat > /tmp/sql-test <<EOF
--set client_min_messages = warning;
--\d+ (shows sequence)
--epoch
--select extract(epoch from date_added) from t_transaction;
--select date_part('epoch', date_added) from t_transaction;
--SELECT EXTRACT(EPOCH FROM TIMESTAMP '2016-10-25T00:14:30.000');
--extract(epoch from date_trunc('month', current_timestamp)
--REVOKE CONNECT ON DATABASE finance_test_db FROM PUBLIC, henninb;
--TO_TIMESTAMP('1538438975')
DROP DATABASE IF EXISTS finance_test_db;
CREATE DATABASE finance_test_db;
GRANT ALL PRIVILEGES ON DATABASE finance_test_db TO henninb;
REVOKE CONNECT ON DATABASE finance_test_db FROM public;
\connect finance_test_db;
CREATE SCHEMA stage;
CREATE SCHEMA int;
CREATE SCHEMA func;
EOF
cat > /tmp/sql-fresh <<EOF
--set client_min_messages = warning;
--\d+ (shows sequence)
--epoch
--select extract(epoch from date_added) from t_transaction;
--select date_part('epoch', date_added) from t_transaction;
--SELECT EXTRACT(EPOCH FROM TIMESTAMP '2016-10-25T00:14:30.000');
--extract(epoch from date_trunc('month', current_timestamp)
--REVOKE CONNECT ON DATABASE finance_test_db FROM PUBLIC, henninb;
--TO_TIMESTAMP('1538438975')
DROP DATABASE IF EXISTS finance_fresh_db;
CREATE DATABASE finance_fresh_db;
GRANT ALL PRIVILEGES ON DATABASE finance_fresh_db TO henninb;
REVOKE CONNECT ON DATABASE finance_fresh_db FROM public;
\connect finance_fresh_db;
CREATE SCHEMA prod;
EOF
cat /tmp/sql-prod "$HOME/projects/github.com/henninb/raspi-finance-endpoint/src/main/resources/db/migration/prod/V01__create-ddl-objects-prod.sql" > finance_db-create.sql
cat /tmp/sql-test "$HOME/projects/github.com/henninb/raspi-finance-endpoint/src/main/resources/db/migration/prod/V01__create-ddl-objects-prod.sql" > finance_test_db-create.sql
cat /tmp/sql-test "$HOME/projects/github.com/henninb/raspi-finance-endpoint/src/test/integration/resources/db/migration/int/V01__create-ddl-objects-int.sql" > finance_test_db-create-int.sql
cat /tmp/sql-test "$HOME/projects/github.com/henninb/raspi-finance-endpoint/src/test/functional/resources/db/migration/func/V01__create-ddl-objects-func.sql" > finance_test_db-create-func.sql
cat /tmp/sql-fresh "$HOME/projects/github.com/henninb/raspi-finance-endpoint/src/main/resources/db/migration/prod/V01__create-ddl-objects-prod.sql" > finance_fresh_db-create.sql
exit 0
if [ "$OS" = "Darwin" ]; then
server=$(ipconfig getifaddr en0)
else
server=$(hostname -i | awk '{print $1}')
fi
if [ $# -ne 1 ] && [ $# -ne 2 ]; then
echo "Usage: $0 [server] [port]"
exit 1
fi
if [ -n "$1" ]; then
server=$1
fi
if [ -n "$2" ]; then
port=$2
fi
echo "server is '$server', port is set to '$port'."
echo "Press enter to continue"
read -r x
echo "$x" > /dev/null
echo postgresql database password
psql -t -h "${server}" -p "${port}" -U henninb -F t -d finance_db < "select-receipt-image.sql" | tee -a "select-receipt-image-${date}.log"
exit 0