logidze 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 662f0ec1e4b6945cffe599484e53691651d70599
4
+ data.tar.gz: 6e82b77620011fa0b758376d810cf7faa5bf305e
5
+ SHA512:
6
+ metadata.gz: dd2b1e23e0ce3bef64d331cdb9e2ad19eb18ab7c0ca39264813ef75167fc6c4a2848dfc136ed1bd50f0bb85ad92e7e19d2894a8ed37dc767c15570c24e59c259
7
+ data.tar.gz: 99597d63737e5cd7d35e88e5466a26a286895a3dac5252805d038c15c651ac375f67785303beee55585198836a543b74fcd207182d9179acd6e5818e48405242
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,50 @@
1
+ AllCops:
2
+ # Include gemspec and Rakefile
3
+ Include:
4
+ - 'lib/**/*.rb'
5
+ - 'lib/**/*.rake'
6
+ - 'spec/**/*.rb'
7
+ Exclude:
8
+ - 'bin/**/*'
9
+ - 'spec/dummy/**/*'
10
+ RunRailsCops: true
11
+ DisplayCopNames: true
12
+ StyleGuideCopsOnly: false
13
+
14
+ Style/AccessorMethodName:
15
+ Enabled: false
16
+
17
+ Style/TrivialAccessors:
18
+ Enabled: false
19
+
20
+ Style/Documentation:
21
+ Exclude:
22
+ - 'spec/**/*.rb'
23
+
24
+ Style/StringLiterals:
25
+ Enabled: false
26
+
27
+ Style/SpaceInsideStringInterpolation:
28
+ EnforcedStyle: no_space
29
+
30
+ Style/BlockDelimiters:
31
+ Exclude:
32
+ - 'spec/**/*.rb'
33
+
34
+ Lint/AmbiguousRegexpLiteral:
35
+ Enabled: false
36
+
37
+ Metrics/MethodLength:
38
+ Exclude:
39
+ - 'spec/**/*.rb'
40
+
41
+ Metrics/LineLength:
42
+ Max: 100
43
+ Exclude:
44
+ - 'spec/**/*.rb'
45
+
46
+ Rails/Date:
47
+ Enabled: false
48
+
49
+ Rails/TimeZone:
50
+ Enabled: false
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'pry'
4
+ # Specify your gem's dependencies in logidze.gemspec
5
+ gemspec
6
+
7
+ local_gemfile = 'Gemfile.local'
8
+
9
+ if File.exist?(local_gemfile)
10
+ eval(File.read(local_gemfile)) # rubocop:disable Lint/Eval
11
+ else
12
+ gem 'activerecord', '~>4.2'
13
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 palkan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,35 @@
1
+ [![Gem Version](https://badge.fury.io/rb/logidze.svg)](https://rubygems.org/gems/logidze) [![Vexor Status](https://ci.vexor.io/projects/163dc587-613e-4643-a071-a56edbe12f34/status.svg)](https://ci.vexor.io/ui/projects/163dc587-613e-4643-a071-a56edbe12f34/builds)
2
+
3
+ # Logidze
4
+
5
+ TBD
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'logidze'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install logidze
22
+
23
+ ## Usage
24
+
25
+ TBD
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/palkan/logidze.
30
+
31
+
32
+ ## License
33
+
34
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
35
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,28 @@
1
+ # Database name
2
+ ifndef DB
3
+ DB = logidze_bench
4
+ endif
5
+
6
+ # Transactions count
7
+ ifndef T
8
+ T = 10000
9
+ endif
10
+
11
+ all:
12
+ make plain
13
+ make hstore
14
+ make keys
15
+
16
+ setup:
17
+ pgbench -i -q $(DB)
18
+
19
+ plain: setup
20
+ pgbench -f bench.sql -t $(T) -r $(DB)
21
+
22
+ hstore: setup
23
+ psql -q -d $(DB) -f hstore_trigger_setup.sql
24
+ pgbench -f bench.sql -t $(T) -r $(DB)
25
+
26
+ keys: setup
27
+ psql -q -d $(DB) -f keys_trigger_setup.sql
28
+ pgbench -f bench.sql -t $(T) -r $(DB)
@@ -0,0 +1,6 @@
1
+ \set naccounts 100000 * :scale
2
+ \setrandom aid 1 :naccounts
3
+ \setrandom delta -5000 5000
4
+ BEGIN;
5
+ UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
6
+ END;
@@ -0,0 +1,38 @@
1
+ CREATE OR REPLACE FUNCTION hstore_logger() RETURNS TRIGGER AS $body$
2
+ DECLARE
3
+ changes_h jsonb;
4
+ size integer;
5
+ buffer jsonb;
6
+ BEGIN
7
+ size := jsonb_array_length(NEW.log);
8
+
9
+ changes_h := hstore_to_jsonb_loose(
10
+ hstore(NEW.*) - hstore(OLD.*)
11
+ );
12
+
13
+ NEW.log := jsonb_set(
14
+ NEW.log,
15
+ ARRAY[size::text],
16
+ jsonb_build_object(
17
+ 'ts',
18
+ extract(epoch from now())::int,
19
+ 'i',
20
+ (NEW.log#>>ARRAY[(size - 1)::text, 'i'])::int + 1,
21
+ 'd',
22
+ changes_h
23
+ ),
24
+ true
25
+ );
26
+ return NEW;
27
+ END;
28
+ $body$
29
+ LANGUAGE plpgsql;
30
+
31
+
32
+ ALTER TABLE pgbench_accounts ADD COLUMN log jsonb DEFAULT '[]' NOT NULL;
33
+
34
+ UPDATE pgbench_accounts SET log = to_jsonb(ARRAY[json_build_object('i', 0)])::jsonb;
35
+
36
+ CREATE TRIGGER hstore_log_accounts
37
+ BEFORE UPDATE ON pgbench_accounts FOR EACH ROW
38
+ EXECUTE PROCEDURE hstore_logger();
@@ -0,0 +1,50 @@
1
+ CREATE OR REPLACE FUNCTION keys_logger() RETURNS TRIGGER AS $body$
2
+ DECLARE
3
+ changes_h jsonb;
4
+ size integer;
5
+ old_j jsonb;
6
+ new_j jsonb;
7
+ item record;
8
+ BEGIN
9
+ size := jsonb_array_length(NEW.log);
10
+ old_j := to_jsonb(OLD);
11
+ new_j := to_jsonb(NEW);
12
+ changes_h := '{}'::jsonb;
13
+
14
+ FOR item in SELECT key as k, value as v FROM jsonb_each(new_j)
15
+ LOOP
16
+ IF item.v <> jsonb_extract_path(old_j, item.k) THEN
17
+ changes_h := jsonb_set(
18
+ changes_h,
19
+ ARRAY[item.k],
20
+ item.v
21
+ );
22
+ END IF;
23
+ END LOOP;
24
+
25
+ NEW.log := jsonb_set(
26
+ NEW.log,
27
+ ARRAY[size::text],
28
+ jsonb_build_object(
29
+ 'ts',
30
+ extract(epoch from now())::int,
31
+ 'i',
32
+ (NEW.log#>>ARRAY[(size - 1)::text, 'i'])::int + 1,
33
+ 'd',
34
+ changes_h
35
+ ),
36
+ true
37
+ );
38
+ return NEW;
39
+ END;
40
+ $body$
41
+ LANGUAGE plpgsql;
42
+
43
+
44
+ ALTER TABLE pgbench_accounts ADD COLUMN log jsonb DEFAULT '[]' NOT NULL;
45
+
46
+ UPDATE pgbench_accounts SET log = to_jsonb(ARRAY[json_build_object('i', 0)])::jsonb;
47
+
48
+ CREATE TRIGGER keys_log_accounts
49
+ BEFORE UPDATE ON pgbench_accounts FOR EACH ROW
50
+ EXECUTE PROCEDURE keys_logger();
@@ -0,0 +1,5 @@
1
+ require "logidze/version"
2
+
3
+ module Logidze
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module Logidze
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'logidze/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "logidze"
8
+ spec.version = Logidze::VERSION
9
+ spec.authors = ["palkan"]
10
+ spec.email = ["dementiev.vm@gmail.com"]
11
+
12
+ spec.summary = "PostgreSQL JSON-based auditing"
13
+ spec.description = "PostgreSQL JSON-based auditing"
14
+ spec.homepage = "http://github.com/palkan/logidze"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_runtime_dependency "activerecord", "~>4"
21
+
22
+ spec.add_development_dependency "pg", "~>0.18"
23
+ spec.add_development_dependency "bundler", "~> 1.11"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.4"
26
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logidze
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - palkan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pg
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.18'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.18'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.4'
83
+ description: PostgreSQL JSON-based auditing
84
+ email:
85
+ - dementiev.vm@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".rubocop.yml"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bench/Makefile
99
+ - bench/bench.sql
100
+ - bench/hstore_trigger_setup.sql
101
+ - bench/keys_trigger_setup.sql
102
+ - lib/logidze.rb
103
+ - lib/logidze/version.rb
104
+ - logidze.gemspec
105
+ homepage: http://github.com/palkan/logidze
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.5.1
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: PostgreSQL JSON-based auditing
129
+ test_files: []
130
+ has_rdoc: