logidze 0.2.2 → 0.2.3

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
  SHA1:
3
- metadata.gz: fcb9249498ac35c0236653c1209d6395679c4d41
4
- data.tar.gz: efd95cb463680a5e000f5e2b96dae8d7d1bc7c0a
3
+ metadata.gz: f91810e96c04d3ddc2d629c5aa0179c69a232d52
4
+ data.tar.gz: 633e81904255a8d8186dc3839c59bb8c84623276
5
5
  SHA512:
6
- metadata.gz: 9e51780490e139a4a475367527480edd0e3530f7c6bda2ef92d0da2591ac8a4e6f8177d2131b7b4f9563e2db3d4ceb6878e1b3574a6ce14206f7b1e9105ba641
7
- data.tar.gz: 9922f8494d288bb0fd520abaae87872c3f1f8ceeaa0613689eee7637d8d9c423549a4aa545b09d9ef743213ca3503a2303bdce2ad4f1cb733bef817a19bddb2e
6
+ metadata.gz: 039e4e7543e6a9e5415eccd73921fff6a850a25e11b68b437d25356ede09f7c89e713803fdad7c77d8687d22a5ce2fae2809a6765d435f1ffc415c85e6ca33dc
7
+ data.tar.gz: 0db11276109aa07f6b2350e2acd4034b6cfe4f76325ba97f16ea14306c949fca0362520246454ad65e1becad13411d58ea5d7c7e6c09dd233dceca680a9a7453
data/.travis.yml CHANGED
@@ -33,3 +33,7 @@ matrix:
33
33
  gemfile: gemfiles/rails5.gemfile
34
34
  - rvm: 2.3.1
35
35
  gemfile: gemfiles/rails42.gemfile
36
+ - rvm: 2.1.6
37
+ gemfile: gemfiles/rails42.gemfile
38
+ - rvm: 2.2.3
39
+ gemfile: gemfiles/rails42.gemfile
data/README.md CHANGED
@@ -6,12 +6,12 @@ Logidze provides tools for logging DB records changes. Just like [audited](https
6
6
 
7
7
  Logidze allows you to create a DB-level log (using triggers) and gives you an API to browse this log.
8
8
  The log is stored with the record itself in JSONB column. No additional tables required.
9
- Currently, only PostgreSQL 9.5+ is supported.
9
+ Currently, only PostgreSQL 9.5+ is supported (for PostgreSQL 9.4 try [jsonbx](http://www.pgxn.org/dist/jsonbx/1.0.0/) extension).
10
10
 
11
11
  [Read the story behind Logidze](https://evilmartians.com/chronicles/introducing-logidze?utm_source=logidze)
12
12
 
13
13
  Other requirements:
14
- - Ruby ~> 2.3;
14
+ - Ruby ~> 2.1;
15
15
  - Rails >= 4.2 (Yes, Rails 5 is supported!).
16
16
 
17
17
  <a href="https://evilmartians.com/">
@@ -1,6 +1,6 @@
1
1
  class <%= @migration_class_name %> < ActiveRecord::Migration
2
2
  def up
3
- execute <<~SQL
3
+ execute <<-SQL
4
4
  DO $$
5
5
  BEGIN
6
6
  EXECUTE 'ALTER DATABASE ' || current_database() || ' SET logidze.disabled TO off';
@@ -9,7 +9,7 @@ class <%= @migration_class_name %> < ActiveRecord::Migration
9
9
  LANGUAGE plpgsql;
10
10
  SQL
11
11
 
12
- execute <<~SQL
12
+ execute <<-SQL
13
13
  CREATE OR REPLACE FUNCTION logidze_snapshot(item jsonb) RETURNS jsonb AS $body$
14
14
  BEGIN
15
15
  return json_build_object(
@@ -21,7 +21,7 @@ class <%= @migration_class_name %> < ActiveRecord::Migration
21
21
  'v',
22
22
  1,
23
23
  'c',
24
- item - 'log_data'
24
+ logidze_exclude_keys(item,'log_data')
25
25
  )
26
26
  )
27
27
  );
@@ -29,6 +29,21 @@ class <%= @migration_class_name %> < ActiveRecord::Migration
29
29
  $body$
30
30
  LANGUAGE plpgsql;
31
31
 
32
+ CREATE OR REPLACE FUNCTION logidze_exclude_keys(obj jsonb, VARIADIC keys text[]) RETURNS jsonb AS $body$
33
+ DECLARE
34
+ res jsonb;
35
+ key text;
36
+ BEGIN
37
+ res := obj;
38
+ FOREACH key IN ARRAY keys
39
+ LOOP
40
+ res := res - key;
41
+ END LOOP;
42
+ RETURN res;
43
+ END;
44
+ $body$
45
+ LANGUAGE plpgsql;
46
+
32
47
  CREATE OR REPLACE FUNCTION logidze_compact_history(log_data jsonb) RETURNS jsonb AS $body$
33
48
  DECLARE
34
49
  merged jsonb;
@@ -103,9 +118,12 @@ class <%= @migration_class_name %> < ActiveRecord::Migration
103
118
  END LOOP;
104
119
  END IF;
105
120
 
106
- changes := hstore_to_jsonb_loose(
107
- hstore(NEW.*) - hstore(OLD.*)
108
- ) - 'log_data';
121
+ changes := logidze_exclude_keys(
122
+ hstore_to_jsonb_loose(
123
+ hstore(NEW.*) - hstore(OLD.*)
124
+ ),
125
+ 'log_data'
126
+ );
109
127
 
110
128
  new_v := (NEW.log_data#>>'{h,-1,v}')::int + 1;
111
129
 
@@ -144,7 +162,7 @@ class <%= @migration_class_name %> < ActiveRecord::Migration
144
162
  end
145
163
 
146
164
  def down
147
- execute <<~SQL
165
+ execute <<-SQL
148
166
  DROP FUNCTION logidze_compact_history(jsonb) CASCADE;
149
167
  DROP FUNCTION logidze_snapshot(jsonb) CASCADE;
150
168
  DROP FUNCTION logidze_logger() CASCADE;
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Logidze
3
- VERSION = "0.2.2"
3
+ VERSION = "0.2.3"
4
4
  end
data/logidze.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.add_dependency "rails", ">= 4.2"
21
21
 
22
22
  spec.add_development_dependency "pg", "~>0.18"
23
- spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "bundler", "~> 1"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
  spec.add_development_dependency "rspec-rails", ">= 3.4"
26
26
  spec.add_development_dependency "database_cleaner", "~> 1.5"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logidze
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - palkan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-03 00:00:00.000000000 Z
11
+ date: 2016-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.11'
47
+ version: '1'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.11'
54
+ version: '1'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement