evt-message_store-postgres-database 0.5.0.0 → 0.6.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c588c659a4212dc17462524446f968ccddf10998e8ac7d3c4a6ed0df4f76aba7
4
- data.tar.gz: b1d06c04be9d5098f76084b6f2bd676fdc91888feadc03d23d26e76d59ace978
3
+ metadata.gz: d3a52a67d61c7b82f6dbdf1859bc19ba5c5cccee8f1b7463aa89fd2395ab7326
4
+ data.tar.gz: dd2b045c1bb470c3f5c160c36a0d21090fc522f79563d48abae1f8d7d83df112
5
5
  SHA512:
6
- metadata.gz: 0bc24c1182bf2c4db4c9b0da6b9011a33f3592307d53c8c7eec1a89759f6d41dbf028bf7b301d124bd1e3dc64787e35de008ede6c82c3ddd51ba63aca6e65176
7
- data.tar.gz: 5292fc4bbfc8ccdaa5578f146dfcf2f46ce0b75d93021f8df88528878ac1821995affba56900323df1ab12501f6976ba922ed8202f295db170728ffd52397bfb
6
+ metadata.gz: 2e934f4216be131a030905f6db71448213b8688256c218379fad8ed46b73c05dbdf08d39c995d5c52e5a1014ebe5fa476ade52842bfbfdf2727e06c46970b5ee
7
+ data.tar.gz: 5e98034583a8ea74581ab0d032a619f3c50927e21b9bd430536d1f466c47e89ba9d25a2770c34d21831b2f5a9b1ff2596257b72bfef046049a345b4392415b1d
@@ -50,12 +50,6 @@ function create-functions {
50
50
  echo "get_last_message function"
51
51
  psql $database -f $base/functions/get-last-message.sql
52
52
 
53
- echo "get_stream_summary function"
54
- psql $database -f $base/functions/get-stream-summary.sql
55
-
56
- echo "get_type_summary function"
57
- psql $database -f $base/functions/get-type-summary.sql
58
-
59
53
  echo
60
54
  }
61
55
 
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ default_name=message_store
6
+
7
+ if [ -z ${DATABASE_NAME+x} ]; then
8
+ echo "(DATABASE_NAME is not set. Default will be used.)"
9
+ database=$default_name
10
+ else
11
+ database=$DATABASE_NAME
12
+ fi
13
+ echo "Database name is: $database"
14
+
15
+ function script_dir {
16
+ val="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
17
+ echo "$val"
18
+ }
19
+
20
+ function create-views {
21
+ base=$(script_dir)
22
+
23
+ echo "stream_summary view"
24
+ psql $database -f $base/views/stream-summary.sql
25
+
26
+ echo "type_summary view"
27
+ psql $database -f $base/views/type-summary.sql
28
+
29
+ echo "type_stream_summary view"
30
+ psql $database -f $base/views/stream-type-summary.sql
31
+
32
+ echo "type_stream_summary view"
33
+ psql $database -f $base/views/type-stream-summary.sql
34
+
35
+ echo
36
+ }
37
+
38
+ echo
39
+ echo "Creating Views"
40
+ echo "- - -"
41
+ create-views
@@ -78,21 +78,23 @@ echo "Creating Database: $database"
78
78
  echo "- - -"
79
79
  create-database
80
80
 
81
-
82
81
  echo
83
82
  echo "Creating Extensions"
84
83
  echo "- - -"
85
84
  create-extensions
86
85
 
87
-
88
86
  echo
89
87
  echo "Creating Table"
90
88
  echo "- - -"
91
89
  create-table
92
90
 
91
+ # Install functions
93
92
  source $base/install-functions.sh
94
93
 
95
94
  echo
96
95
  echo "Creating Indexes"
97
96
  echo "- - -"
98
97
  create-indexes
98
+
99
+ # Install views
100
+ source $base/install-views.sh
@@ -38,7 +38,7 @@ fi
38
38
  echo
39
39
 
40
40
  if [ -z $stream_name ]; then
41
- psql $database -U $user -x -c "SELECT * FROM messages"
41
+ psql $database -U $user -x -P pager=off -c "SELECT * FROM messages"
42
42
  else
43
- psql $database -U $user -x -c "SELECT * FROM messages WHERE stream_name = '$stream_name'"
43
+ psql $database -U $user -x -P pager=off -c "SELECT * FROM messages WHERE stream_name = '$stream_name'"
44
44
  fi
@@ -36,9 +36,9 @@ echo "= = ="
36
36
  echo
37
37
 
38
38
  if [ -z $stream_name ]; then
39
- psql $database -U $user -P pager=off -c "SELECT * FROM get_stream_summary();"
39
+ psql $database -U $user -P pager=off -c "SELECT * FROM stream_summary ORDER BY message_count DESC;"
40
40
  psql $database -U $user -P pager=off -c "SELECT COUNT(*) AS total_count FROM messages;"
41
41
  else
42
- psql $database -U $user -P pager=off -c "SELECT * FROM get_stream_summary('$stream_name');"
42
+ psql $database -U $user -P pager=off -c "SELECT * FROM stream_summary WHERE stream_name LIKE '%$stream_name%' ORDER BY message_count DESC;"
43
43
  psql $database -U $user -P pager=off -c "SELECT COUNT(*) AS total_count FROM messages WHERE stream_name LIKE '%$stream_name%';"
44
44
  fi
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ echo
6
+
7
+ default_name=message_store
8
+
9
+ if [ -z ${DATABASE_USER+x} ]; then
10
+ echo "(DATABASE_USER is not set)"
11
+ user=$default_name
12
+ else
13
+ user=$DATABASE_USER
14
+ fi
15
+ echo "Database user is: $user"
16
+
17
+ if [ -z ${DATABASE_NAME+x} ]; then
18
+ echo "(DATABASE_NAME is not set)"
19
+ database=$default_name
20
+ else
21
+ database=$DATABASE_NAME
22
+ fi
23
+ echo "Database name is: $database"
24
+
25
+ if [ -z ${STREAM_NAME+x} ]; then
26
+ echo "(STREAM_NAME is not set)"
27
+ stream_name=''
28
+ else
29
+ stream_name=$STREAM_NAME
30
+ echo "Stream name is: $STREAM_NAME"
31
+ fi
32
+
33
+ echo
34
+ echo "Stream Stream Summary"
35
+ echo "= = ="
36
+ echo
37
+
38
+ if [ -z $stream_name ]; then
39
+ psql $database -U $user -P pager=off -c "SELECT * FROM stream_type_summary ORDER BY stream_name, message_count DESC, type;"
40
+ psql $database -U $user -P pager=off -c "SELECT COUNT(*) AS total_count FROM messages;"
41
+ else
42
+ psql $database -U $user -P pager=off -c "SELECT * FROM stream_type_summary WHERE stream_name LIKE '%$stream_name%' ORDER BY stream_name, message_count DESC;"
43
+ psql $database -U $user -P pager=off -c "SELECT COUNT(*) AS total_count FROM messages WHERE stream_name LIKE '%$stream_name%';"
44
+ fi
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ echo
6
+
7
+ default_name=message_store
8
+
9
+ if [ -z ${DATABASE_USER+x} ]; then
10
+ echo "(DATABASE_USER is not set)"
11
+ user=$default_name
12
+ else
13
+ user=$DATABASE_USER
14
+ fi
15
+ echo "Database user is: $user"
16
+
17
+ if [ -z ${DATABASE_NAME+x} ]; then
18
+ echo "(DATABASE_NAME is not set)"
19
+ database=$default_name
20
+ else
21
+ database=$DATABASE_NAME
22
+ fi
23
+ echo "Database name is: $database"
24
+
25
+ if [ -z ${TYPE+x} ]; then
26
+ echo "(TYPE is not set)"
27
+ type=''
28
+ else
29
+ type=$TYPE
30
+ echo "Type is: $TYPE"
31
+ fi
32
+
33
+ echo
34
+ echo "Type Stream Summary"
35
+ echo "= = ="
36
+ echo
37
+
38
+ if [ -z $type ]; then
39
+ psql $database -U $user -P pager=off -c "SELECT * FROM type_stream_summary ORDER BY type, message_count DESC, stream_name;"
40
+ psql $database -U $user -P pager=off -c "SELECT COUNT(*) AS total_count FROM messages;"
41
+ else
42
+ psql $database -U $user -P pager=off -c "SELECT * FROM type_stream_summary WHERE type LIKE '%$type%' ORDER BY type, message_count DESC, stream_name;"
43
+ psql $database -U $user -P pager=off -c "SELECT COUNT(*) AS total_count FROM messages WHERE type LIKE '%$type%';"
44
+ fi
@@ -27,7 +27,7 @@ if [ -z ${TYPE+x} ]; then
27
27
  type=''
28
28
  else
29
29
  type=$TYPE
30
- echo "Stream name is: $TYPE"
30
+ echo "Type is: $TYPE"
31
31
  fi
32
32
 
33
33
  echo
@@ -36,9 +36,9 @@ echo "= = ="
36
36
  echo
37
37
 
38
38
  if [ -z $type ]; then
39
- psql $database -U $user -P pager=off -c "SELECT * FROM get_type_summary();"
39
+ psql $database -U $user -P pager=off -c "SELECT * FROM type_summary ORDER BY message_count DESC;"
40
40
  psql $database -U $user -P pager=off -c "SELECT COUNT(*) AS total_count FROM messages;"
41
41
  else
42
- psql $database -U $user -P pager=off -c "SELECT * FROM get_type_summary('$type');"
42
+ psql $database -U $user -P pager=off -c "SELECT * FROM type_summary WHERE type LIKE '%$type%' ORDER BY message_count DESC;"
43
43
  psql $database -U $user -P pager=off -c "SELECT COUNT(*) AS total_count FROM messages WHERE type LIKE '%$type%';"
44
44
  fi
@@ -0,0 +1,28 @@
1
+ CREATE OR REPLACE VIEW stream_summary AS
2
+ WITH
3
+ stream_count AS (
4
+ SELECT
5
+ stream_name,
6
+ COUNT(id) AS message_count
7
+ FROM
8
+ messages
9
+ GROUP BY
10
+ stream_name
11
+ ),
12
+
13
+ total_count AS (
14
+ SELECT
15
+ COUNT(id)::decimal AS total_count
16
+ FROM
17
+ messages
18
+ )
19
+
20
+ SELECT
21
+ stream_name,
22
+ message_count,
23
+ ROUND((message_count / total_count)::decimal * 100, 2) AS percent
24
+ FROM
25
+ stream_count,
26
+ total_count
27
+ ORDER BY
28
+ stream_name;
@@ -0,0 +1,32 @@
1
+ CREATE OR REPLACE VIEW stream_type_summary AS
2
+ WITH
3
+ type_count AS (
4
+ SELECT
5
+ stream_name,
6
+ type,
7
+ COUNT(id) AS message_count
8
+ FROM
9
+ messages
10
+ GROUP BY
11
+ stream_name,
12
+ type
13
+ ),
14
+
15
+ total_count AS (
16
+ SELECT
17
+ COUNT(id)::decimal AS total_count
18
+ FROM
19
+ messages
20
+ )
21
+
22
+ SELECT
23
+ stream_name,
24
+ type,
25
+ message_count,
26
+ ROUND((message_count / total_count)::decimal * 100, 2) AS percent
27
+ FROM
28
+ type_count,
29
+ total_count
30
+ ORDER BY
31
+ stream_name,
32
+ type;
@@ -0,0 +1,32 @@
1
+ CREATE OR REPLACE VIEW type_stream_summary AS
2
+ WITH
3
+ type_count AS (
4
+ SELECT
5
+ type,
6
+ stream_name,
7
+ COUNT(id) AS message_count
8
+ FROM
9
+ messages
10
+ GROUP BY
11
+ type,
12
+ stream_name
13
+ ),
14
+
15
+ total_count AS (
16
+ SELECT
17
+ COUNT(id)::decimal AS total_count
18
+ FROM
19
+ messages
20
+ )
21
+
22
+ SELECT
23
+ type,
24
+ stream_name,
25
+ message_count,
26
+ ROUND((message_count / total_count)::decimal * 100, 2) AS percent
27
+ FROM
28
+ type_count,
29
+ total_count
30
+ ORDER BY
31
+ type,
32
+ stream_name;
@@ -0,0 +1,28 @@
1
+ CREATE OR REPLACE VIEW type_summary AS
2
+ WITH
3
+ type_count AS (
4
+ SELECT
5
+ type,
6
+ COUNT(id) AS message_count
7
+ FROM
8
+ messages
9
+ GROUP BY
10
+ type
11
+ ),
12
+
13
+ total_count AS (
14
+ SELECT
15
+ COUNT(id)::decimal AS total_count
16
+ FROM
17
+ messages
18
+ )
19
+
20
+ SELECT
21
+ type,
22
+ message_count,
23
+ ROUND((message_count / total_count)::decimal * 100, 2) AS percent
24
+ FROM
25
+ type_count,
26
+ total_count
27
+ ORDER BY
28
+ type;
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ root = File.expand_path '../database', __dir__
4
+ script_filename = 'print-stream-type-summary.sh'
5
+ script_filepath = File.join root, script_filename
6
+
7
+ system script_filepath
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ root = File.expand_path '../database', __dir__
4
+ script_filename = 'print-type-stream-summary.sh'
5
+ script_filepath = File.join root, script_filename
6
+
7
+ system script_filepath
metadata CHANGED
@@ -1,26 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evt-message_store-postgres-database
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0.0
4
+ version: 0.6.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Eventide Project
8
8
  autorequire:
9
9
  bindir: scripts
10
10
  cert_chain: []
11
- date: 2018-07-19 00:00:00.000000000 Z
11
+ date: 2018-07-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: " "
14
14
  email: opensource@eventide-project.org
15
15
  executables:
16
16
  - evt-pg-print-messages
17
17
  - evt-pg-delete-db
18
+ - evt-pg-print-stream-type-summary
18
19
  - evt-pg-write-test-message
19
20
  - evt-pg-create-db
20
21
  - evt-pg-install-database-functions
21
22
  - evt-pg-open-database-scripts-dir
22
23
  - evt-pg-clear-messages
23
24
  - evt-pg-recreate-db
25
+ - evt-pg-print-type-stream-summary
24
26
  - evt-pg-print-type-summary
25
27
  - evt-pg-print-stream-summary
26
28
  extensions: []
@@ -35,8 +37,6 @@ files:
35
37
  - database/functions/get-category-messages.sql
36
38
  - database/functions/get-last-message.sql
37
39
  - database/functions/get-stream-messages.sql
38
- - database/functions/get-stream-summary.sql
39
- - database/functions/get-type-summary.sql
40
40
  - database/functions/hash-64.sql
41
41
  - database/functions/scratch.sql
42
42
  - database/functions/stream-version.sql
@@ -45,13 +45,20 @@ files:
45
45
  - database/indexes/messages-id-uniq.sql
46
46
  - database/indexes/messages-stream-name-position-uniq.sql
47
47
  - database/install-functions.sh
48
+ - database/install-views.sh
48
49
  - database/install.sh
49
50
  - database/print-messages.sh
50
51
  - database/print-stream-summary.sh
52
+ - database/print-stream-type-summary.sh
53
+ - database/print-type-stream-summary.sh
51
54
  - database/print-type-summary.sh
52
55
  - database/table/messages-table.sql
53
56
  - database/types/message.sql
54
57
  - database/uninstall.sh
58
+ - database/views/stream-summary.sql
59
+ - database/views/stream-type-summary.sql
60
+ - database/views/type-stream-summary.sql
61
+ - database/views/type-summary.sql
55
62
  - database/write-test-message.sh
56
63
  - scripts/evt-pg-clear-messages
57
64
  - scripts/evt-pg-create-db
@@ -60,6 +67,8 @@ files:
60
67
  - scripts/evt-pg-open-database-scripts-dir
61
68
  - scripts/evt-pg-print-messages
62
69
  - scripts/evt-pg-print-stream-summary
70
+ - scripts/evt-pg-print-stream-type-summary
71
+ - scripts/evt-pg-print-type-stream-summary
63
72
  - scripts/evt-pg-print-type-summary
64
73
  - scripts/evt-pg-recreate-db
65
74
  - scripts/evt-pg-write-test-message
@@ -1,60 +0,0 @@
1
- CREATE OR REPLACE FUNCTION get_stream_summary(
2
- _stream_name varchar DEFAULT NULL
3
- )
4
- RETURNS TABLE (
5
- stream_name varchar,
6
- message_count bigint,
7
- percent decimal
8
- )
9
- AS $$
10
- DECLARE
11
- command text;
12
- BEGIN
13
- command := '
14
- WITH
15
- stream_count AS (
16
- SELECT
17
- stream_name,
18
- COUNT(id) AS message_count
19
- FROM
20
- messages
21
- GROUP BY
22
- stream_name
23
- ),
24
-
25
- total_count AS (
26
- SELECT
27
- COUNT(id)::decimal AS total_count
28
- FROM
29
- messages
30
- )
31
-
32
- SELECT
33
- stream_name,
34
- message_count,
35
- ROUND((message_count / total_count)::decimal * 100, 2) AS percent
36
- FROM
37
- stream_count,
38
- total_count';
39
-
40
- IF _stream_name is not null THEN
41
- _stream_name := '%' || _stream_name || '%';
42
- command := command || '
43
- WHERE
44
- stream_name LIKE $1';
45
- END IF;
46
-
47
- command := command || '
48
- ORDER BY
49
- message_count DESC';
50
-
51
- -- RAISE NOTICE '%', command;
52
-
53
- IF _stream_name is not null THEN
54
- RETURN QUERY EXECUTE command USING _stream_name;
55
- ELSE
56
- RETURN QUERY EXECUTE command;
57
- END IF;
58
- END;
59
- $$ LANGUAGE plpgsql
60
- VOLATILE;
@@ -1,60 +0,0 @@
1
- CREATE OR REPLACE FUNCTION get_type_summary(
2
- _type varchar DEFAULT NULL
3
- )
4
- RETURNS TABLE (
5
- type varchar,
6
- message_count bigint,
7
- percent decimal
8
- )
9
- AS $$
10
- DECLARE
11
- command text;
12
- BEGIN
13
- command := '
14
- WITH
15
- type_count AS (
16
- SELECT
17
- type,
18
- COUNT(id) AS message_count
19
- FROM
20
- messages
21
- GROUP BY
22
- type
23
- ),
24
-
25
- total_count AS (
26
- SELECT
27
- COUNT(id)::decimal AS total_count
28
- FROM
29
- messages
30
- )
31
-
32
- SELECT
33
- type,
34
- message_count,
35
- ROUND((message_count / total_count)::decimal * 100, 2) AS percent
36
- FROM
37
- type_count,
38
- total_count';
39
-
40
- IF _type is not null THEN
41
- _type := '%' || _type || '%';
42
- command := command || '
43
- WHERE
44
- type LIKE $1';
45
- END IF;
46
-
47
- command := command || '
48
- ORDER BY
49
- message_count DESC';
50
-
51
- -- RAISE NOTICE '%', command;
52
-
53
- IF _type is not null THEN
54
- RETURN QUERY EXECUTE command USING _type;
55
- ELSE
56
- RETURN QUERY EXECUTE command;
57
- END IF;
58
- END;
59
- $$ LANGUAGE plpgsql
60
- VOLATILE;