logidze 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7ac978c39954a679f81242ef85020969e2639f8
4
- data.tar.gz: 1d7b280698b769ed44bda02c14249660ae67bfdd
3
+ metadata.gz: a553a435446577ff945a979411dcd5d36c6185e7
4
+ data.tar.gz: 4c06374961f3073969d5f7d16184bd7e7e8d5dd9
5
5
  SHA512:
6
- metadata.gz: 22adef27322f4a653d0bcb45230261c0380476f81c6f5f11fefe09fc438fd3f1ffd1a73b52f9517b8c1b63be31ebd9802a21d63bc10e18192176e126c6df97f7
7
- data.tar.gz: 0770ac7a807ff2439c54ef1d780712ad503722d7ac3e556e9de46f2096644ea8db6270bec8d17844628edce5a5c59d4613433187835e9659cdcdee3f3cb04de4
6
+ metadata.gz: 9bbdf6fcec9cb2e4a5686f7f80972aa43889bda5e74e7711d4e80364d580279e9f947859aa76342b3018dcf5fcc471ab6b998c5a54e9b836654dab1e94e9bdeb
7
+ data.tar.gz: 991804f34a2f90601794418789fde42aff8d7031a8edd6b115fb79c4e0fd59e3b14277b8931a509e19c01200d4cd830776484e6d4622059c4bca3b321d2ecfc7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change log
2
2
 
3
+ ## master
4
+
5
+ ## 0.5.3 (2017-08-22)
6
+
7
+ - Add `--update` flag to model migration. ([@palkan][])
8
+
3
9
  ## 0.5.2 (2017-06-19)
4
10
 
5
11
  - Use versioned migrations in Rails 5+. ([@palkan][])
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/logidze.svg)](https://rubygems.org/gems/logidze) [![Build Status](https://travis-ci.org/palkan/logidze.svg?branch=master)](https://travis-ci.org/palkan/logidze) [![Circle CI](https://circleci.com/gh/palkan/logidze/tree/master.svg?style=svg)](https://circleci.com/gh/palkan/logidze/tree/master)
2
+ [![Dependency Status](https://dependencyci.com/github/palkan/logidze/badge)](https://dependencyci.com/github/palkan/logidze)
2
3
 
3
4
  # Logidze
4
5
 
@@ -86,6 +87,12 @@ rails generate logidze:model Post --timestamp_column time
86
87
  rails generate logidze:model Post --timestamp_column nil # "null" and "false" will also work
87
88
  ```
88
89
 
90
+ If you want to update Logidze settings for the model, run migration with `--update` flag:
91
+
92
+ ```ruby
93
+ rails generate logidze:model Post --update --whitelist=title body rating
94
+ ```
95
+
89
96
  Logidze also supports associations versioning. It is experimental feature, and disabled by default. You can learn more
90
97
  in the [wiki](https://github.com/palkan/logidze/wiki/Associations-versioning).
91
98
 
@@ -6,3 +6,8 @@ Examples:
6
6
 
7
7
  This will generate the migration to add log column and trigger.
8
8
  This will also add `has_logidze` to model.
9
+
10
+ rails generate logidze:model User --update --whitelist=name,age
11
+
12
+ This will generate the migration to update existing trigger (drop and create).
13
+
@@ -24,6 +24,9 @@ module Logidze
24
24
  class_option :timestamp_column, type: :string, optional: true,
25
25
  desc: "Specify timestamp column"
26
26
 
27
+ class_option :update, type: :boolean, optional: true,
28
+ desc: "Define whether this is an update migration"
29
+
27
30
  def generate_migration
28
31
  if options[:blacklist] && options[:whitelist]
29
32
  $stderr.puts "Use only one: --whitelist or --blacklist"
@@ -33,6 +36,7 @@ module Logidze
33
36
  end
34
37
 
35
38
  def inject_logidze_to_model
39
+ return if update?
36
40
  indents = " " * (class_name.scan("::").count + 1)
37
41
 
38
42
  inject_into_class(model_file_path, class_name.demodulize, "#{indents}has_logidze\n")
@@ -40,7 +44,11 @@ module Logidze
40
44
 
41
45
  no_tasks do
42
46
  def migration_name
43
- "add_logidze_to_#{plural_table_name}"
47
+ if update?
48
+ "update_logidze_for_#{plural_table_name}"
49
+ else
50
+ "add_logidze_to_#{plural_table_name}"
51
+ end
44
52
  end
45
53
 
46
54
  def migration_file_name
@@ -59,6 +67,10 @@ module Logidze
59
67
  options[:only_trigger]
60
68
  end
61
69
 
70
+ def update?
71
+ options[:update]
72
+ end
73
+
62
74
  def columns_blacklist
63
75
  array = if !options[:whitelist]
64
76
  options[:blacklist]
@@ -3,7 +3,9 @@ class <%= @migration_class_name %> < ActiveRecord::Migration<%= ActiveRecord::VE
3
3
  include Logidze::Migration
4
4
 
5
5
  def up
6
- <% unless only_trigger? %>
6
+ <% if update? %>
7
+ execute "DROP TRIGGER logidze_on_<%= table_name %> on <%= table_name %>;"
8
+ <% elsif !only_trigger? %>
7
9
  add_column :<%= table_name %>, :log_data, :jsonb
8
10
  <% end %>
9
11
 
@@ -23,10 +25,19 @@ class <%= @migration_class_name %> < ActiveRecord::Migration<%= ActiveRecord::VE
23
25
  end
24
26
 
25
27
  def down
28
+ <% if update? %>
29
+ # NOTE: We have no idea on how to revert the migration
30
+ # ('cause we don't know the previous trigger params),
31
+ # but you can do that on your own.
32
+ #
33
+ # Uncomment this line if you want to raise an error.
34
+ # raise ActiveRecord::IrreversibleMigration
35
+ <% else %>
26
36
  execute "DROP TRIGGER IF EXISTS logidze_on_<%= table_name %> on <%= table_name %>;"
27
37
 
28
- <% unless only_trigger? %>
38
+ <% if !only_trigger? %>
29
39
  remove_column :<%= table_name %>, :log_data
30
40
  <% end %>
41
+ <% end %>
31
42
  end
32
43
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Logidze
3
- VERSION = "0.5.2"
3
+ VERSION = "0.5.3"
4
4
  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.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - palkan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-19 00:00:00.000000000 Z
11
+ date: 2017-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -226,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
226
226
  version: '0'
227
227
  requirements: []
228
228
  rubyforge_project:
229
- rubygems_version: 2.6.4
229
+ rubygems_version: 2.6.11
230
230
  signing_key:
231
231
  specification_version: 4
232
232
  summary: PostgreSQL JSON-based auditing