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 +4 -4
- data/.travis.yml +4 -0
- data/README.md +2 -2
- data/lib/generators/logidze/install/templates/migration.rb.erb +25 -7
- data/lib/logidze/version.rb +1 -1
- data/logidze.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f91810e96c04d3ddc2d629c5aa0179c69a232d52
|
4
|
+
data.tar.gz: 633e81904255a8d8186dc3839c59bb8c84623276
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 039e4e7543e6a9e5415eccd73921fff6a850a25e11b68b437d25356ede09f7c89e713803fdad7c77d8687d22a5ce2fae2809a6765d435f1ffc415c85e6ca33dc
|
7
|
+
data.tar.gz: 0db11276109aa07f6b2350e2acd4034b6cfe4f76325ba97f16ea14306c949fca0362520246454ad65e1becad13411d58ea5d7c7e6c09dd233dceca680a9a7453
|
data/.travis.yml
CHANGED
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.
|
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
|
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
|
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
|
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 :=
|
107
|
-
|
108
|
-
|
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
|
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;
|
data/lib/logidze/version.rb
CHANGED
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
|
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.
|
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-
|
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
|
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
|
54
|
+
version: '1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|