evt-message_store-postgres-database 0.9.0.1 → 0.10.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: 544236fd8913ca01aca2a8fe933af45b7ff7000c368072c2df0d385c4eb40c82
4
- data.tar.gz: 18c0a4f6906247ae4357c22a05844ceaf447fd03c4b0d410c6b1a095c9f76c4e
3
+ metadata.gz: d9ee310a4aacf67ad9d3a97bde6dcf969b39afdc32c578004797894f91716fcf
4
+ data.tar.gz: d5afd1eba683a6862097a165dc8e5129635a817e05238318b6b1f98ea3074a38
5
5
  SHA512:
6
- metadata.gz: 44d4e64e6c5bc7f132b845525ef75b4c13a216f1db654788fbaaed6e222665f7d09868785a1ff74537ee1c3e7d735fdd98067620209c347bb22db84fb8067ab6
7
- data.tar.gz: c3f284cc83cd66b8d86a8d59d31465f8e7db51e403c9962dec2e84ab5e49ad657c26ddd15f908516038071262e545192fd91c9e2ad0029be0510c7e3619fe331
6
+ metadata.gz: 7d5075bcea7470bb1d8dc320e83a39d79163e93e40bba7bc9dd0881a51e536dc16442beec4be75fe070c0417d8762a661833a1adaefbbc6f0df25c6b5d3fe0d3
7
+ data.tar.gz: 26180f49acedaad535d836294e8d18e006838efdb4740c146e154efffe5f267d5a4363af05f2046f8a6cd39b31899fdac28c02a0707c77060e77b3fe630e726f
File without changes
@@ -0,0 +1,29 @@
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 grant-privileges {
21
+ base=$(script_dir)
22
+ psql $database -f $base/user/privileges.sql
23
+ echo
24
+ }
25
+
26
+ echo
27
+ echo "Granting Privileges"
28
+ echo "- - -"
29
+ grant-privileges
data/database/install.sh CHANGED
@@ -8,15 +8,6 @@ echo "= = ="
8
8
  echo
9
9
 
10
10
  default_name=message_store
11
-
12
- if [ -z ${DATABASE_USER+x} ]; then
13
- echo "(DATABASE_USER is not set. Default will be used.)"
14
- user=$default_name
15
- else
16
- user=$DATABASE_USER
17
- fi
18
- echo "Database user is: $user"
19
-
20
11
  if [ -z ${DATABASE_NAME+x} ]; then
21
12
  echo "(DATABASE_NAME is not set. Default will be used.)"
22
13
  database=$default_name
@@ -33,7 +24,8 @@ function script_dir {
33
24
  }
34
25
 
35
26
  function create-user {
36
- createuser -s $user
27
+ base=$(script_dir)
28
+ psql -f $base/user/role.sql
37
29
  echo
38
30
  }
39
31
 
@@ -44,19 +36,20 @@ function create-database {
44
36
 
45
37
  function create-extensions {
46
38
  base=$(script_dir)
47
- psql $database -f $base/extensions.sql
39
+ psql $database -f $base/extension/pgcrypto.sql
48
40
  echo
49
41
  }
50
42
 
51
43
  function create-table {
52
- psql $database -f $base/table/messages-table.sql
44
+ base=$(script_dir)
45
+ psql $database -f $base/table/messages.sql
53
46
  echo
54
47
  }
55
48
 
56
49
  base=$(script_dir)
57
50
 
58
51
  echo
59
- echo "Creating User: $user"
52
+ echo "Creating User: message_store"
60
53
  echo "- - -"
61
54
  create-user
62
55
 
@@ -83,3 +76,8 @@ source $base/install-indexes.sh
83
76
 
84
77
  # Install views
85
78
  source $base/install-views.sh
79
+
80
+ echo
81
+ echo "Granting Privileges"
82
+ echo "- - -"
83
+ source $base/install-privileges.sh
@@ -1,7 +1,7 @@
1
1
  -- ----------------------------
2
2
  -- Table structure for messages
3
3
  -- ----------------------------
4
- CREATE TABLE "public"."messages" (
4
+ CREATE TABLE IF NOT EXISTS "public"."messages" (
5
5
  "id" UUID NOT NULL DEFAULT gen_random_uuid(),
6
6
  "stream_name" varchar(255) NOT NULL COLLATE "default",
7
7
  "type" varchar(255) NOT NULL COLLATE "default",
@@ -1,8 +1,6 @@
1
1
  DO $$
2
2
  BEGIN
3
- IF EXISTS (SELECT 1 FROM pg_type WHERE typname = 'message') THEN
4
- DROP TYPE message CASCADE;
5
- END IF;
3
+ DROP TYPE IF EXISTS message CASCADE;
6
4
 
7
5
  CREATE TYPE message AS (
8
6
  id varchar,
@@ -26,32 +26,48 @@ fi
26
26
  echo "Database name is: $database"
27
27
  echo
28
28
 
29
- function delete-user {
30
- user_exists=`psql postgres -qtAXc "SELECT 1 FROM pg_roles WHERE rolname='$user'"`
29
+ # function delete-user {
30
+ # user_exists=`psql postgres -qtAXc "SELECT 1 FROM pg_roles WHERE rolname='$user'"`
31
+
32
+ # if [ "$user_exists" = "1" ]; then
33
+ # echo "Deleting database user \"$user\"..."
34
+ # dropuser $user
35
+ # else
36
+ # echo "Database user \"$user\" does not exist. Not deleting."
37
+ # fi
31
38
 
32
- if [ "$user_exists" = "1" ]; then
33
- echo "Deleting database user \"$user\"..."
34
- dropuser $user
35
- else
36
- echo "Database user \"$user\" does not exist. Not deleting."
37
- fi
39
+ # echo
40
+ # }
38
41
 
42
+ function delete-user {
43
+ psql -P pager=off -c "DROP ROLE IF EXISTS $user;"
39
44
  echo
40
45
  }
41
46
 
42
- function delete-database {
43
- database_exists=`psql postgres -qtAXc "SELECT 1 FROM pg_database WHERE datname='$database'"`
47
+ # function delete-database {
48
+ # database_exists=`psql postgres -qtAXc "SELECT 1 FROM pg_database WHERE datname='$database'"`
49
+
50
+ # if [ "$database_exists" = "1" ]; then
51
+ # echo "Deleting database \"$database\"..."
52
+ # dropdb $database
53
+ # else
54
+ # echo "Database \"$database\" does not exist. Not deleting."
55
+ # fi
44
56
 
45
- if [ "$database_exists" = "1" ]; then
46
- echo "Deleting database \"$database\"..."
47
- dropdb $database
48
- else
49
- echo "Database \"$database\" does not exist. Not deleting."
50
- fi
57
+ # echo
58
+ # }
51
59
 
60
+ function delete-database {
61
+ psql -P pager=off -c "DROP DATABASE IF EXISTS $database;"
52
62
  echo
53
63
  }
54
64
 
55
-
65
+ echo
66
+ echo "Deleting database \"$database\"..."
67
+ echo "- - -"
56
68
  delete-database
69
+
70
+ echo
71
+ echo "Deleting database user \"$user\"..."
72
+ echo "- - -"
57
73
  delete-user
@@ -0,0 +1,24 @@
1
+ -- Table
2
+ GRANT SELECT, INSERT ON messages TO message_store;
3
+
4
+ -- Sequence
5
+ GRANT USAGE, SELECT ON SEQUENCE messages_global_position_seq TO message_store;
6
+
7
+ -- Functions
8
+ GRANT EXECUTE ON FUNCTION gen_random_uuid TO message_store;
9
+ GRANT EXECUTE ON FUNCTION md5(text) TO message_store;
10
+ GRANT EXECUTE ON FUNCTION hash_64 TO message_store;
11
+ GRANT EXECUTE ON FUNCTION category TO message_store;
12
+ GRANT EXECUTE ON FUNCTION stream_version TO message_store;
13
+ GRANT EXECUTE ON FUNCTION write_message TO message_store;
14
+ GRANT EXECUTE ON FUNCTION get_stream_messages TO message_store;
15
+ GRANT EXECUTE ON FUNCTION get_category_messages TO message_store;
16
+ GRANT EXECUTE ON FUNCTION get_last_message TO message_store;
17
+
18
+ -- Views
19
+ GRANT SELECT, INSERT ON category_type_summary TO message_store;
20
+ GRANT SELECT, INSERT ON stream_summary TO message_store;
21
+ GRANT SELECT, INSERT ON stream_type_summary TO message_store;
22
+ GRANT SELECT, INSERT ON type_category_summary TO message_store;
23
+ GRANT SELECT, INSERT ON type_stream_summary TO message_store;
24
+ GRANT SELECT, INSERT ON type_summary TO message_store;
@@ -0,0 +1,7 @@
1
+ DO $$
2
+ BEGIN
3
+ CREATE ROLE message_store WITH LOGIN;
4
+ EXCEPTION
5
+ WHEN duplicate_object THEN
6
+ RAISE NOTICE 'The message_store role already exists';
7
+ END$$;
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ root = File.expand_path '../database', __dir__
4
+ script_filename = 'install-indexes.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 = 'install-privileges.sh'
5
+ script_filepath = File.join root, script_filename
6
+
7
+ system script_filepath
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evt-message_store-postgres-database
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0.1
4
+ version: 0.10.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-08-09 00:00:00.000000000 Z
11
+ date: 2018-09-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: " "
14
14
  email: opensource@eventide-project.org
@@ -19,6 +19,7 @@ executables:
19
19
  - evt-pg-update-db
20
20
  - evt-pg-delete-db
21
21
  - evt-pg-print-stream-type-summary
22
+ - evt-pg-install-indexes
22
23
  - evt-pg-write-test-message
23
24
  - evt-pg-create-db
24
25
  - evt-pg-print-type-category-summary
@@ -29,6 +30,7 @@ executables:
29
30
  - evt-pg-print-type-stream-summary
30
31
  - evt-pg-print-type-summary
31
32
  - evt-pg-print-stream-summary
33
+ - evt-pg-install-privileges
32
34
  extensions: []
33
35
  extra_rdoc_files: []
34
36
  files:
@@ -36,13 +38,12 @@ files:
36
38
  - database/benchmark_get.sql
37
39
  - database/benchmark_write.sql
38
40
  - database/clear-messages.sh
39
- - database/extensions.sql
41
+ - database/extension/pgcrypto.sql
40
42
  - database/functions/category.sql
41
43
  - database/functions/get-category-messages.sql
42
44
  - database/functions/get-last-message.sql
43
45
  - database/functions/get-stream-messages.sql
44
46
  - database/functions/hash-64.sql
45
- - database/functions/scratch.sql
46
47
  - database/functions/stream-version.sql
47
48
  - database/functions/write-message.sql
48
49
  - database/indexes/messages-category-global-position.sql
@@ -50,6 +51,7 @@ files:
50
51
  - database/indexes/messages-stream-name-position-uniq.sql
51
52
  - database/install-functions.sh
52
53
  - database/install-indexes.sh
54
+ - database/install-privileges.sh
53
55
  - database/install-views.sh
54
56
  - database/install.sh
55
57
  - database/print-category-type-summary.sh
@@ -60,10 +62,12 @@ files:
60
62
  - database/print-type-stream-summary.sh
61
63
  - database/print-type-summary.sh
62
64
  - database/rename-updated-to-recorded.sh
63
- - database/table/messages-table.sql
65
+ - database/table/messages.sql
64
66
  - database/types/message.sql
65
67
  - database/uninstall.sh
66
68
  - database/update.sh
69
+ - database/user/privileges.sql
70
+ - database/user/role.sql
67
71
  - database/views/category-type-summary.sql
68
72
  - database/views/stream-summary.sql
69
73
  - database/views/stream-type-summary.sql
@@ -75,6 +79,8 @@ files:
75
79
  - scripts/evt-pg-create-db
76
80
  - scripts/evt-pg-delete-db
77
81
  - scripts/evt-pg-install-functions
82
+ - scripts/evt-pg-install-indexes
83
+ - scripts/evt-pg-install-privileges
78
84
  - scripts/evt-pg-install-views
79
85
  - scripts/evt-pg-open-database-scripts-dir
80
86
  - scripts/evt-pg-print-category-type-summary
@@ -1,68 +0,0 @@
1
- :stream_name, na(:position), na(:batch_size), :condition
2
-
3
-
4
- module Defaults
5
- def self.position
6
- 0
7
- end
8
-
9
- def self.batch_size
10
- 1000
11
- end
12
- end
13
-
14
-
15
- - - -
16
-
17
- command := 'SELECT * FROM messages WHERE $1';
18
- RETURN QUERY EXECUTE command USING where_clause;
19
-
20
- - - -
21
- select * from messages where metadata @> '{"correlationStreamName":"someCorrelation"}';
22
- - - -
23
- select * from get_messages($$metadata @> '{"correlationStreamName":"someCorrelation"}'$$);
24
- - - -
25
-
26
-
27
- _sql := format('
28
- SELECT *
29
- FROM (
30
- SELECT p.person_id, p.name, p.team, %1$s(s.score)::int AS score
31
- ,rank() OVER (PARTITION BY p.team
32
- ORDER BY %1$s(s.score) DESC)::int AS rnk
33
- FROM person p
34
- %2$s score s USING (person_id)
35
- %3$s
36
- GROUP BY 1
37
- ) sub
38
- WHERE rnk < 3
39
- ORDER BY team, rnk'
40
- , _agg
41
- , CASE WHEN _left_join THEN 'LEFT JOIN' ELSE 'JOIN' END
42
- , CASE WHEN _where_name <> '' THEN 'WHERE p.name LIKE $1' ELSE '' END
43
- );
44
-
45
- -- debug -- quote when tested ok
46
- -- RAISE NOTICE '%', _sql;
47
-
48
- -- execute -- unquote when tested ok
49
- RETURN QUERY EXECUTE _sql
50
-
51
-
52
- - - -
53
-
54
- CREATE OR REPLACE FUNCTION get_messages()
55
- RETURNS SETOF messages
56
- AS $$
57
- DECLARE
58
- _sql text;
59
- BEGIN
60
-
61
- _sql := 'RETURN QUERY SELECT * FROM messages'
62
-
63
- -- RETURN QUERY EXECUTE _sql
64
-
65
- RETURN QUERY SELECT * FROM messages;
66
- END;
67
- $$ LANGUAGE plpgsql
68
- VOLATILE;