izolenta 0.0.3 → 0.0.4

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: '09bc2895fc70a6c50727f81242f0f06e90c4492d3c1193ba4e1a1bffb83599ec'
4
- data.tar.gz: 14d8e61fbd7bb788b05054274418d14b55e18117fc5793d5f0b4a67af1e85a41
3
+ metadata.gz: 377c2667d8659d69896c5e397347c69653641261159f04c404b0ec6e4007cefa
4
+ data.tar.gz: 3d552cc871bb52efd2e9c4e546145446818ac667f92033b21d2f7cdb7eaeafc9
5
5
  SHA512:
6
- metadata.gz: 1d3fdb8446cd4698487c397bb7c8de99cdf1a44b911d84ce218c76d46f4aa98adc922813abfbbb231ad612bb0430137a538555d4620f77e813e2ac19e39c2d56
7
- data.tar.gz: c9dc6ef925404436a15358c07a1c7a640f593a02f12fae1448b8b6429063c07629768e0f8f45dc78e44367ab482ade23bd53a5e5be926cf1f23d53910f13d62d
6
+ metadata.gz: '094c5f7d6157445976aa017ee2ab757466ec21930a5f229da0a51d17928ffddd33e76862acacf340453885aac08ee0b3c5c67d3d6de5f8ea6a4bf96564bb3851'
7
+ data.tar.gz: 2d98b109bbb4809831aaa08c6504f7b6648f9ce9d4b53eb9211241417e60501ba3b5dea8ff3a5159d0542bd023b40f143364fb84a46f641570912cb9d56d521b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
+ #0.0.4
2
+ - removed 'OR REPLACE' in trigger definition, lowering Postgres version constraint
3
+ - trigger_condition added ( could replace partial uniq index )
4
+
1
5
  #0.0.3
2
6
  - wrapper_function options added, you can define function to convert to uniquely sortable types, for instance array to string
7
+ - moved all helper functions to internal module, just to keep things clear on the migrations
3
8
 
4
9
  #0.0.2
5
10
  - delegate_uniqueness helper is available as a migration method
data/README.md CHANGED
@@ -46,6 +46,15 @@ class WithWrapperFunctionMigration < ActiveRecord::Migration[5.0]
46
46
  delegate_uniqueness( :your_table_name, :column_name, wrapper_function: 'type_conversion_function' )
47
47
  end
48
48
  end
49
+
50
+
51
+ class WithWrapperFunctionMigration < ActiveRecord::Migration[5.0]
52
+ # apply trigger condition for partial uniqueness
53
+ def change
54
+ delegate_uniqueness( :your_table_name, :column_name, trigger_condition: 'NEW.type IS NOT NULL' )
55
+ end
56
+ end
57
+
49
58
  ```
50
59
 
51
60
  ## Development
@@ -29,6 +29,9 @@ module Izolenta::ActiveRecordMigration
29
29
  trg_name = "#{table}_#{column_name}_trg"
30
30
  insert_value = options[:wrapper_function] ? "#{options[:wrapper_function]}(NEW.#{column_name})"
31
31
  : "NEW.#{column_name}"
32
+
33
+ trigger_condition = "WHEN( #{options[:trigger_condition]} )" if options[:trigger_condition]
34
+
32
35
  ActiveRecord::Base.connection.execute <<~SYNC_TRIGGER
33
36
  CREATE OR REPLACE FUNCTION #{trg_name}() RETURNS trigger AS $$
34
37
  BEGIN
@@ -36,7 +39,9 @@ module Izolenta::ActiveRecordMigration
36
39
  RETURN NEW;
37
40
  END $$ LANGUAGE plpgSQL;
38
41
 
39
- CREATE OR REPLACE TRIGGER #{trg_name} BEFORE INSERT ON #{table} FOR EACH ROW
42
+ CREATE TRIGGER #{trg_name} BEFORE INSERT ON #{table}
43
+ FOR EACH ROW
44
+ #{trigger_condition}
40
45
  EXECUTE FUNCTION #{trg_name}();
41
46
  SYNC_TRIGGER
42
47
  end
@@ -49,7 +54,7 @@ module Izolenta::ActiveRecordMigration
49
54
  SYNC_TRIGGER
50
55
  end
51
56
 
52
- def get_new_column_type(origin_table, column, wrapper_function: nil)
57
+ def get_new_column_type(origin_table, column, wrapper_function: nil, **)
53
58
  wrapper_function ? get_function_type(wrapper_function) : get_column_type(origin_table, column)
54
59
  end
55
60
 
@@ -1,3 +1,3 @@
1
1
  module Izolenta
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: izolenta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - alekseyl
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-24 00:00:00.000000000 Z
11
+ date: 2021-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg