logidze 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -2
- data/bin/console +1 -0
- data/lib/generators/logidze/install/templates/migration.rb.erb +15 -10
- data/lib/generators/logidze/model/templates/migration.rb.erb +4 -1
- data/lib/logidze/history.rb +2 -0
- data/lib/logidze/migration.rb +19 -0
- data/lib/logidze/responsible.rb +1 -1
- data/lib/logidze/version.rb +1 -1
- data/lib/logidze.rb +2 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1a840d3c86c64317abe7c5b69a8dcc978e9efc7
|
4
|
+
data.tar.gz: 221465ea78ebb99cf8335415d5c378484d4ddb9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 414193540e8570e67f735664e42f09b97fc3e736d8110d0373192ab41b651cf6b597b863e194bc99fbba71a73500d0a96c3ab5205da55e23a709ac4eb76bc2e8
|
7
|
+
data.tar.gz: 7883e8e97309016d2b11b43744fdd07c15aea256408cb65d2d72c55ce1405d461ba6d3d684d5010ca00a8fa634122fe2efb5a7893e0d875dcaff3e783d8eaf4c
|
data/README.md
CHANGED
@@ -60,6 +60,18 @@ To backfill table data (i.e. create initial snapshots) add `backfill` option:
|
|
60
60
|
rails generate logidze:model Post --backfill
|
61
61
|
```
|
62
62
|
|
63
|
+
## Troubleshooting
|
64
|
+
|
65
|
+
The most common problem is `"permission denied to set parameter "logidze.xxx"` caused by `ALTER DATABASE ...` query.
|
66
|
+
Logidze requires at least database owner privileges (which is not always possible).
|
67
|
+
|
68
|
+
Here is a quick and straightforward [workaround](https://github.com/palkan/logidze/issues/11#issuecomment-260703464) by [@nobodyzzz](https://github.com/nobodyzzz).
|
69
|
+
|
70
|
+
**NOTE**: if you're using PostgreSQL >= 9.6 you need neither the workaround nor owner privileges because Logidze (>= 0.3.1) can work without `ALTER DATABASE ...`.
|
71
|
+
|
72
|
+
Nevertheless, you still need super-user privileges to enable `hstore` extension (or you can use [PostgreSQL Extension Whitelisting](https://github.com/dimitri/pgextwlist)).
|
73
|
+
|
74
|
+
|
63
75
|
## Upgrade from previous versions
|
64
76
|
|
65
77
|
We try to make upgrade process as simple as possible. For now, the only required action is to create and run a migration:
|
@@ -202,9 +214,9 @@ The `log_data` column has the following format:
|
|
202
214
|
"c": {
|
203
215
|
"attr": "new value", // updated fields with new values
|
204
216
|
"attr2": "new value"
|
205
|
-
}
|
206
|
-
},
|
217
|
+
},
|
207
218
|
"r": 42 // Resposibility ID (if provided)
|
219
|
+
}
|
208
220
|
]
|
209
221
|
}
|
210
222
|
```
|
data/bin/console
CHANGED
@@ -1,14 +1,19 @@
|
|
1
1
|
class <%= @migration_class_name %> < ActiveRecord::Migration
|
2
|
+
require 'logidze/migration'
|
3
|
+
include Logidze::Migration
|
4
|
+
|
2
5
|
def up
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
unless current_setting_missing_supported?
|
7
|
+
execute <<-SQL
|
8
|
+
DO $$
|
9
|
+
BEGIN
|
10
|
+
EXECUTE 'ALTER DATABASE ' || quote_ident(current_database()) || ' SET logidze.disabled=' || quote_literal('');
|
11
|
+
EXECUTE 'ALTER DATABASE ' || quote_ident(current_database()) || ' SET logidze.responsible=' || quote_literal('');
|
12
|
+
END;
|
13
|
+
$$
|
14
|
+
LANGUAGE plpgsql;
|
15
|
+
SQL
|
16
|
+
end
|
12
17
|
|
13
18
|
execute <<-SQL
|
14
19
|
CREATE OR REPLACE FUNCTION logidze_version(v bigint, data jsonb) RETURNS jsonb AS $body$
|
@@ -23,7 +28,7 @@ class <%= @migration_class_name %> < ActiveRecord::Migration
|
|
23
28
|
'c',
|
24
29
|
logidze_exclude_keys(data, 'log_data')
|
25
30
|
);
|
26
|
-
IF current_setting('logidze.responsible') <> '
|
31
|
+
IF coalesce(#{current_setting('logidze.responsible')}, '') <> '' THEN
|
27
32
|
buf := jsonb_set(buf, ARRAY['r'], to_jsonb(current_setting('logidze.responsible')));
|
28
33
|
END IF;
|
29
34
|
RETURN buf;
|
@@ -1,4 +1,7 @@
|
|
1
1
|
class <%= @migration_class_name %> < ActiveRecord::Migration
|
2
|
+
require 'logidze/migration'
|
3
|
+
include Logidze::Migration
|
4
|
+
|
2
5
|
def up
|
3
6
|
<% unless only_trigger? %>
|
4
7
|
add_column :<%= table_name %>, :log_data, :jsonb
|
@@ -7,7 +10,7 @@ class <%= @migration_class_name %> < ActiveRecord::Migration
|
|
7
10
|
execute <<-SQL
|
8
11
|
CREATE TRIGGER logidze_on_<%= table_name %>
|
9
12
|
BEFORE UPDATE OR INSERT ON <%= table_name %> FOR EACH ROW
|
10
|
-
WHEN (current_setting('logidze.disabled') <> 'on')
|
13
|
+
WHEN (coalesce(#{current_setting('logidze.disabled')}, '') <> 'on')
|
11
14
|
EXECUTE PROCEDURE logidze_logger(<%= limit || '' %>);
|
12
15
|
SQL
|
13
16
|
|
data/lib/logidze/history.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Logidze
|
3
|
+
# Contains helpers for handling different PG versions
|
4
|
+
module Migration
|
5
|
+
# Checks whether pg function `current_setting` support `missing_ok` argument
|
6
|
+
# (since 9.6)
|
7
|
+
def current_setting_missing_supported?
|
8
|
+
ActiveRecord::Base.connection.send(:postgresql_version) >= 90_600
|
9
|
+
end
|
10
|
+
|
11
|
+
def current_setting(name)
|
12
|
+
if current_setting_missing_supported?
|
13
|
+
"current_setting('#{name}', true)"
|
14
|
+
else
|
15
|
+
"current_setting('#{name}')"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/logidze/responsible.rb
CHANGED
@@ -9,7 +9,7 @@ module Logidze # :nodoc:
|
|
9
9
|
"SET LOCAL logidze.responsible = #{ActiveRecord::Base.connection.quote(responsible_id)};"
|
10
10
|
)
|
11
11
|
res = yield
|
12
|
-
ActiveRecord::Base.connection.execute "SET LOCAL logidze.responsible
|
12
|
+
ActiveRecord::Base.connection.execute "SET LOCAL logidze.responsible TO DEFAULT;"
|
13
13
|
res
|
14
14
|
end
|
15
15
|
end
|
data/lib/logidze/version.rb
CHANGED
data/lib/logidze.rb
CHANGED
@@ -19,9 +19,9 @@ module Logidze
|
|
19
19
|
# Logidze.without_logging { Post.update_all(active: true) }
|
20
20
|
def self.without_logging
|
21
21
|
ActiveRecord::Base.transaction do
|
22
|
-
ActiveRecord::Base.connection.execute "SET LOCAL logidze.disabled
|
22
|
+
ActiveRecord::Base.connection.execute "SET LOCAL logidze.disabled TO on;"
|
23
23
|
res = yield
|
24
|
-
ActiveRecord::Base.connection.execute "SET LOCAL logidze.disabled
|
24
|
+
ActiveRecord::Base.connection.execute "SET LOCAL logidze.disabled TO DEFAULT;"
|
25
25
|
res
|
26
26
|
end
|
27
27
|
end
|
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.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- palkan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -185,6 +185,7 @@ files:
|
|
185
185
|
- lib/logidze/history.rb
|
186
186
|
- lib/logidze/history/type.rb
|
187
187
|
- lib/logidze/history/version.rb
|
188
|
+
- lib/logidze/migration.rb
|
188
189
|
- lib/logidze/model.rb
|
189
190
|
- lib/logidze/responsible.rb
|
190
191
|
- lib/logidze/version.rb
|