logidze 1.2.0 → 1.2.1

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: 7130810a9954a68eb38b0c9484b58091a599d662d36e61d4f2072dbe12612807
4
- data.tar.gz: a4bc08a8a998826263441aa50cb263e5d3bcc36f48ede24bdad60ef4d7e3f640
3
+ metadata.gz: be9e11a375ab711ba02349e3cd14fbd4503af6572d969ced6db24bd36407bf05
4
+ data.tar.gz: '03885f890051fc938cba4089798bcc8b1b753a5ae941c5d93907536e1685ff94'
5
5
  SHA512:
6
- metadata.gz: 1136d0509508787e18f3839f63293b384f315438cb2675f4ff517b2ca3afa9da9e7e71d013a234a745fac860c499bf29ebcb0949bc245576c53d02a2217f30d9
7
- data.tar.gz: 9ee0339acaddf4c442da9699485e33acc57bc0ae20c98a80b5b08ea940cc59a6bc6a93c5d2d5d56d6eac95d4f86f4704bf85536f601304908b6cb5fc28dfb913
6
+ metadata.gz: 24bc6a181263eaeb98762e8c183ba74b717a3195d2809460ceeddfbeefdc63c4b72e3c5da2b8426bba2722c765a41c27bf3ff2d3e265b5760a561795e205ee5a
7
+ data.tar.gz: 96f0e22ccad449d642320a9bf105e05ed15623ecaa1a52e453bfda356df2dbf9cb13eda235c6e288e1cf62d0484234f92104673c7ef15c9fbfe135d8bb757b16
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 1.2.1 (2022-01-13)
6
+
7
+ - [Fixes [#207](https://github.com/palkan/logidze/issues/207)] Add support for the use of `table_name_prefix` or `table_name_suffix`. ([@cavi21][])
8
+
9
+ - [Fixes [#205](https://github.com/palkan/logidze/issues/205)] Allow `rails destroy logidze:model SomeModel` to delete the migration file. ([@danielmklein][])
10
+
5
11
  ## 1.2.0 (2021-06-11)
6
12
 
7
13
  - Add user-defined exception handling ([@skryukov][])
@@ -359,3 +365,5 @@ This is a quick fix for a more general problem (see [#59](https://github.com/pal
359
365
  [@oleg-kiviljov]: https://github.com/oleg-kiviljov
360
366
  [@skryukov]: https://github.com/skryukov
361
367
  [@bf4]: https://github.com/bf4
368
+ [@cavi21]: https://github.com/cavi21
369
+ [@danielmklein]: https://github.com/danielmklein
data/README.md CHANGED
@@ -34,6 +34,7 @@ Other requirements:
34
34
  - [Log size limits](#log-size-limits)
35
35
  - [Tracking only selected columns](#tracking-only-selected-columns)
36
36
  - [Logs timestamps](#logs-timestamps)
37
+ - [Undoing a Generated Invocation](#undoing-a-generated-invocation)
37
38
  - [Usage](#usage)
38
39
  - [Basic API](#basic-api)
39
40
  - [Track meta information](#track-meta-information)
@@ -134,8 +135,8 @@ Model.create_logidze_snapshot
134
135
  Model.create_logidze_snapshot(timestamp: :created_at)
135
136
 
136
137
  # filter columns
137
- Model.create_logidze_snapshot(only: %(name))
138
- Model.create_logidze_snapshot(except: %(password))
138
+ Model.create_logidze_snapshot(only: %w[name])
139
+ Model.create_logidze_snapshot(except: %w[password])
139
140
 
140
141
  # or call a similar method (but with !) on a record
141
142
 
@@ -178,6 +179,16 @@ bundle exec rails generate logidze:model Post --timestamp_column time
178
179
  bundle exec rails generate logidze:model Post --timestamp_column nil # "null" and "false" will also work
179
180
  ```
180
181
 
182
+ ### Undoing a Generated Invocation
183
+
184
+ If you would like to re-do your `rails generate` anew, as with other generators you can use `rails destroy` to revert it, which will delete the migration file and undo the injection of `has_logidze` into the model file:
185
+
186
+ ```sh
187
+ bundle exec rails destroy logidze:model Post
188
+ ```
189
+
190
+ **IMPORTANT**: If you use non-UTC time zone for Active Record (`config.active_record.default_timezone`), you MUST always infer log timestamps from a timestamp column (e.g., when back-filling data); otherwise, you may end up with inconsistent logs ([#199](https://github.com/palkan/logidze/issues/199)). In general, we recommend using UTC as the database time unless there is a very strong reason not to.
191
+
181
192
  ## Usage
182
193
 
183
194
  ### Basic API
@@ -274,11 +285,13 @@ Logidze.append_on_undo = true
274
285
  You can store any meta information you want inside your version (it could be IP address, user agent, etc.). To add it you should wrap your code with a block:
275
286
 
276
287
  ```ruby
277
- Logidze.with_meta(ip: request.ip) do
288
+ Logidze.with_meta({ip: request.ip}) do
278
289
  post.save!
279
290
  end
280
291
  ```
281
292
 
293
+ **NOTE:** You should pass metadata as a Hash; passing keyword arguments doesn't work in Ruby 3.0+.
294
+
282
295
  Meta expects a hash to be passed so you won't need to encode and decode JSON manually.
283
296
 
284
297
  By default `.with_meta` wraps the block into a DB transaction. That could lead to an unexpected behavior, especially, when using `.with_meta` within an around_action. To avoid wrapping the block into a DB transaction use `transactional: false` option.
@@ -472,7 +485,7 @@ $ bundle exec rails generate logidze:model Post --update --only=title,body,ratin
472
485
 
473
486
  ### Pending upgrade check [Experimental]
474
487
 
475
- Logidze can check for a pending upgrade. Use `Logidze.pending_upgrade = :warn` to be notified by warning, or `Logidze.pending_upgrade = :error` if you want Logidze to raise an error.
488
+ Logidze can check for a pending upgrade. Use `Logidze.on_pending_upgrade = :warn` to be notified by warning, or `Logidze.on_pending_upgrade = :error` if you want Logidze to raise an error.
476
489
 
477
490
  ### Upgrading from 0.x to 1.0 (edge)
478
491
 
@@ -562,9 +575,19 @@ Related issues: [#69](https://github.com/palkan/logidze/issues/69).
562
575
 
563
576
  ## Development
564
577
 
565
- We use [Dip](https://github.com/bibendi/dip) for development. Provision the project by running `dip provision` and then use `dip bundle`, `dip rspec` or `dip bash` to interact with a Docker development environment.
578
+ This project requires a PostgreSQL instance running with the following setup:
579
+
580
+ ```sh
581
+ # For testing
582
+ createdb -h postgres -U postgres logidze_test
583
+
584
+ # For benchmarks
585
+ createdb -h postgres -U postgres logidze_bench
586
+ createdb -h postgres -U postgres logidze_perf_bench
587
+ psql -d logidze_bench -c 'CREATE EXTENSION IF NOT EXISTS hstore;'
588
+ ```
566
589
 
567
- If you prefer developing on your local machine, make user you have Postgres installed and run `./bin/setup`.
590
+ This project is compatible with [Reusable Docker environment](https://evilmartians.com/chronicles/reusable-development-containers-with-docker-compose-and-dip) setup.
568
591
 
569
592
  ## Contributing
570
593
 
@@ -45,7 +45,7 @@ module Logidze
45
45
  warn "Use only one: --only or --except"
46
46
  exit(1)
47
47
  end
48
- migration_template "migration.rb.erb", "db/migrate/#{migration_file_name}"
48
+ migration_template "migration.rb.erb", "db/migrate/#{migration_name}.rb"
49
49
  end
50
50
 
51
51
  def generate_fx_trigger
@@ -73,8 +73,9 @@ module Logidze
73
73
  end
74
74
  end
75
75
 
76
- def migration_file_name
77
- "#{migration_name}.rb"
76
+ def full_table_name
77
+ config = ActiveRecord::Base
78
+ "#{config.table_name_prefix}#{table_name}#{config.table_name_suffix}"
78
79
  end
79
80
 
80
81
  def limit
@@ -12,14 +12,18 @@ class <%= @migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::M
12
12
  dir.up do
13
13
  <%- if update? -%>
14
14
  # Drop legacy trigger if any (<1.0)
15
- execute "DROP TRIGGER IF EXISTS logidze_on_<%= table_name %> on <%= table_name %>;"
15
+ execute <<~SQL
16
+ DROP TRIGGER IF EXISTS "logidze_on_<%= full_table_name %>" on "<%= full_table_name %>";
17
+ SQL
16
18
 
17
19
  <%- end -%>
18
20
  create_trigger :logidze_on_<%= table_name %>, on: :<%= table_name %>
19
21
  end
20
22
 
21
23
  dir.down do
22
- execute "DROP TRIGGER IF EXISTS logidze_on_<%= table_name %> on <%= table_name %>;"
24
+ execute <<~SQL
25
+ DROP TRIGGER IF EXISTS "logidze_on_<%= full_table_name %>" on "<%= full_table_name %>";
26
+ SQL
23
27
  end
24
28
  end
25
29
  <%- end -%>
@@ -27,7 +31,9 @@ class <%= @migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::M
27
31
  reversible do |dir|
28
32
  dir.up do
29
33
  <%- if update? -%>
30
- execute "DROP TRIGGER IF EXISTS logidze_on_<%= table_name %> on <%= table_name %>;"
34
+ execute <<~SQL
35
+ DROP TRIGGER IF EXISTS "logidze_on_<%= full_table_name %>" on "<%= full_table_name %>";
36
+ SQL
31
37
 
32
38
  <%- end -%>
33
39
  execute <<~SQL
@@ -44,7 +50,9 @@ class <%= @migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::M
44
50
  # Uncomment this line if you want to raise an error.
45
51
  # raise ActiveRecord::IrreversibleMigration
46
52
  <%- else -%>
47
- execute "DROP TRIGGER IF EXISTS logidze_on_<%= table_name %> on <%= table_name %>;"
53
+ execute <<~SQL
54
+ DROP TRIGGER IF EXISTS "logidze_on_<%= full_table_name %>" on "<%= full_table_name %>";
55
+ SQL
48
56
  <%- end -%>
49
57
  end
50
58
  end
@@ -54,7 +62,7 @@ class <%= @migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::M
54
62
  reversible do |dir|
55
63
  dir.up do
56
64
  execute <<~SQL
57
- UPDATE <%= table_name %> as t
65
+ UPDATE "<%= full_table_name %>" as t
58
66
  SET log_data = logidze_snapshot(<%= logidze_snapshot_parameters %>);
59
67
  SQL
60
68
  end
@@ -1,5 +1,5 @@
1
- CREATE TRIGGER logidze_on_<%= table_name %>
2
- BEFORE UPDATE OR INSERT ON <%= table_name %> FOR EACH ROW
1
+ CREATE TRIGGER <%= %Q("logidze_on_#{full_table_name}") %>
2
+ BEFORE UPDATE OR INSERT ON <%= %Q("#{full_table_name}") %> FOR EACH ROW
3
3
  WHEN (coalesce(current_setting('logidze.disabled', true), '') <> 'on')
4
4
  -- Parameters: history_size_limit (integer), timestamp_column (text), filtered_columns (text[]),
5
5
  -- include_columns (boolean), debounce_time_ms (integer)
data/lib/logidze/model.rb CHANGED
@@ -213,7 +213,7 @@ module Logidze
213
213
 
214
214
  # Loads log_data field from the database, stores to the attributes hash and returns it
215
215
  def reload_log_data
216
- self.log_data = self.class.where(self.class.primary_key => id).pluck("#{self.class.table_name}.log_data").first
216
+ self.log_data = self.class.where(self.class.primary_key => id).pluck("#{self.class.table_name}.log_data".to_sym).first
217
217
  end
218
218
 
219
219
  # Nullify log_data column for a single record
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Logidze
4
- VERSION = "1.2.0"
4
+ VERSION = "1.2.1"
5
5
  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: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - palkan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-11 00:00:00.000000000 Z
11
+ date: 2022-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -216,7 +216,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
216
216
  - !ruby/object:Gem::Version
217
217
  version: '0'
218
218
  requirements: []
219
- rubygems_version: 3.2.10
219
+ rubygems_version: 3.2.22
220
220
  signing_key:
221
221
  specification_version: 4
222
222
  summary: PostgreSQL JSONB-based model changes tracking